% 1D example % TSVD deblur % Build object clear all, close all t=[0:0.02:1]'; x=1*(t>0.25&t<0.75); % Build blurring matrix and compute image m=length(t); c = zeros(m,1); c(1:5) = [5:-1:1]'/25; A = toeplitz(c); b = A*x+0.01*randn(m,1); % Plot object, image and naive solution. [U,S,V]=svd(A); alpha = input(' Truncation level = '); Strunc = (S>alpha).*S; xtsvd=V*pinv(Strunc)*U'*b; figure(1) subplot(221) semilogy(diag(S)) hold on, semilogy(alpha*ones(size(b)),'r'), hold off title('Singular Values of A') subplot(222) plot(U(:,1)) title('Singular Vector 1') subplot(223) plot(U(:,5)) title('Singular Vector 5') subplot(224) plot(U(:,25)) title('Singular Vector 25') figure(2) plot(t,x,'g-',t,b,'r--',t,xtsvd) axis([0 1 -0.5 1.5]) legend('true','blurred','naive solution')