%matlab notes for 5-15-2012 clear all %joint gaussian distribution, zero mean, standard deviation 1 p = 0 %p is correlation [X,Y] = meshgrid(-5:.01:5,-5:.01:5); size(X) size(Y) imagesc(exp(-(X.^2 - 2*p*X.*Y + Y.^2)/2/(1-p^2))/(2*pi)/(sqrt(1-p^2))); p = .5; imagesc(exp(-(X.^2 - 2*p*X.*Y + Y.^2)/2/(1-p^2))/(2*pi)/(sqrt(1-p^2))); axis xy; p = -.5; imagesc(exp(-(X.^2 - 2*p*X.*Y + Y.^2)/2/(1-p^2))/(2*pi)/(sqrt(1-p^2))); axis xy; p = .9 imagesc(exp(-(X.^2 - 2*p*X.*Y + Y.^2)/2/(1-p^2))/(2*pi)/(sqrt(1-p^2))); axis xy; mesh(exp(-(X.^2 - 2*p*X.*Y + Y.^2)/2/(1-p^2))/(2*pi)/(sqrt(1-p^2))); %how to use randn to generate zero mean Gaussian random numbers with %a given covariance matrix C C = [1 .5;.5 1/3] det(C) [V,D] = eigs(C) V*D*V' S = sqrt(D)*V' N1 = randn(1,1000); N2 = randn(1,1000); X = S'*[N1;N2]; cov(X(1,:),X(2,:)) C scatter(X(1,:),X(2,:)) %use SVD for image compression f_in = double(imread('elvis.bmp')); %load image f = f_in(:,:,1); imagesc(f) colormap gray [mr,mc] = size(f); m = mr*mc; g = zeros(mr,mc); mr mc help svd [U,S,V] = svd(f); imagesc(S) sv = diag(S); %singular values sv(1) sv(2) sv(3) svlen = length(find(sv>0)) mr r = .1 s = round(r*svlen); s Uc = U(:,1:s); svc = sv(1:s); Vc = V(:,1:s); size(Uc) g = Uc*(svc(:,ones(1,mc)).*Vc'); imagesc(g) %now throw away even more information s = .01 r = .01 s = round(r*svlen); %number of singular values to keep %compress Uc = U(:,1:s); svc = sv(1:s); Vc = V(:,1:s); g = Uc*(svc(:,ones(1,mc)).*Vc'); imagesc(g)