%% dftdemo2 %% show a signal and dft pair %% the dft is shifted to put low frequencies in the center % define signal, sample rate, sample domain N = 128; t = (0:1:(N-1))/N; % sig = 2*cos(5*2*pi*t)+0.5*sin(24*2*pi*t); k = 20; sig = [ones(1,k),zeros(1,N-k)]*(N/k); SD = 0:(N-1); % get shifted dft and frequency domain fsig = fft(sig); sfsig = fftshift(fsig); FD = fftshift(SD); N1 = FD(1); FD(1:(N-N1))= (N1-N):(-1); % display results subplot(2,1,1) plot(SD,real(sig),'r',SD,imag(sig),'g') title('sampled signal'); axis tight subplot(2,1,2) plot(FD, real(sfsig),'r',FD,imag(sfsig),'g') title('shifted DFT of signal') axis tight figure(2) plot(FD, abs(sfsig),'r-')