% DFT program homework on April 4, 2007 % version 2 % message is a sinusoid N=128; f0=0.1; f1=0.4; t=[0: 1: 127]; g0=sin(2*pi*f0*t); g1=cos(2*pi*f1*t); zz0=fft(g0); z0=fftshift(zz0); % fftshift makes the center to be 0Hz instead of half of the sampling % frequency zz1=fft(g1); z1=fftshift(zz1); Ts=t(2)-t(1); % the sampling period Fs=1/Ts; % the sampling frequency in Hz F = Fs*(-N/2:(N/2)-1)/N; % frequency axis plot(F, abs(z0+z1)); y0=ifft(z0); y1=ifft(z1); % DFT program % put the DFT result in an array u0 and u1 % plot(abs(u0+u1)) and compare it with the result by plot(abs(z0+z1)) % IDFT prgram % put the IDFT result in arrays w0 and w1 % compare these with g0 and g1