% Demo of DFTs of cosines % Upgraded to included DTFT analysis % Last revised 10/7/97 - rms %Create a cosine with period 16 clear N0 = 16; n = 1:64; np = n-1; xn = cos(2*pi*np/N0); subplot(1,1,1),stem(0:63,xn(1:64)) title('Cosine with period of 16 samples') pause % Show the 64-point DFT Xk = fft(xn(1:64),64); stem(0:63,abs(Xk)) title('64-point DFT') pause % Show the 60-point DFT Xk = fft(xn(1:60),60); stem(0:59,abs(Xk)) title('60-point DFT') pause % Compare the two time functions np2 = 0:79; xnp1 = [xn xn(1:16)]; subplot(2,1,1), stem(np2,xnp1) hold on subplot(2,1,1), stem(64:79,xn(1:16),'r') hold off xlabel('n') title('16-point cosine repeated with period 64') xnp2 = [xn(1:59) xn(1:21)]; subplot(2,1,2), stem(np2,xnp2) hold on subplot(2,1,2), stem(59:79,xn(1:21),'r') hold off xlabel('n') title('16-point cosine repeated with period 60') pause % Show DTFT and DFT of 64-point cosine ovsamp = 8; % How many times we oversample for display w = -pi:pi/(64*ovsamp/2):pi; w2 = w(1:(ovsamp*64)); % temp = .5*sincN(64,w2); temp = .5*64*diric(w2,64); X = cirshftt(temp,4*ovsamp,64*ovsamp) + cirshftt(temp,-4*ovsamp,64*ovsamp); subplot(1,1,1),plot(w/pi,[X X(1)]) hold on title('DTFT') xlabel('w/pi') pause index = 1+ ovsamp*(0:63); stem([w(index)/pi 1],[X(index) X(1)],'r') title('DTFT and 64-point DFT') pause hold off % Repeat, but for N = 60 ovsamp = 8; % How many times we oversample for display w = -pi:pi/(64*ovsamp/2):pi; w2 = w(1:(ovsamp*64)); % temp = .5*sincN(64,w2); temp = .5*64*diric(w2,64); X = cirshftt(temp,4*ovsamp,64*ovsamp) + cirshftt(temp,-4*ovsamp,64*ovsamp); subplot(1,1,1),plot(w/pi,[X X(1)]) hold on title('DTFT') xlabel('w/pi') pause Y = resample(X,15,16); % Resampling to new DFT points index = 1+ ovsamp*(0:59); w3 = -pi:(16/15)*pi/(64*ovsamp/2):pi; stem([w3(index)/pi 1],[Y(index) Y(1)],'r') title('DTFT and 60-point DFT') pause