%% dftdemo %% show a noisy signal and shifted dft magnitude %% smooth dft and then smooth signal % define signal, sample rate, sample domain N = 256; t = (0:1:(N-1))/N; truesig = cos(5*2*pi*t)+0.5*cos(24*2*pi*t); noise = rand(size(truesig)) - 0.5*ones(size(truesig)); sig = truesig+noise; SD = 0:(N-1); % get dft and frequency domain csig = dct(sig); FD = (0:(N-1))/2; csig =dct(sig); % display signal and transform figure(1) subplot(2,1,1) plot(SD,real(sig),'r') title('sampled signal'); axis tight subplot(2,1,2) plot(FD, csig,'r-' ) title('frequency stength') axis tight % smooth transform and signal thresh =0.1; m = max(abs(csig)); ZI = find(abs(csig) < thresh*m); smcsig = csig; smcsig(ZI) = 0; smsig = idct(smcsig); disp('press a key'); pause % display smoothed functions figure(2) subplot(2,1,1) plot(FD, smcsig,'r-' ) title('thresholded DCT') axis tight subplot(2,1,2) plot(SD, smsig,'r-' ) title('smoothed signal') axis tight