% dft_ex1.m -- Some signals to compute DFT and interpret. % Modified from dft_ex.m to produce plots for all signals. % Rich Kozick, Spring 1997 % Instructions: Plot each time signal and compare the signal shape with % the DFT basis vectors. % Then look at the corresponding DFT coefficients and interpret them. % Can you explain? N = 8; n = 0:N-1; % Signals to consider x1 = ones(1,N); x2 = cos(2*pi*n/N); x3 = 5*cos(2*pi*2*n/N); x4 = 0.2*sin(2*pi*n/N); x5 = cos(2*pi*2*n/N + pi/3); x6 = cos(2*pi*1.5*n/N); x = [x1; x2; x3; x4; x5; x6]'; X = fft(x); for k=1:6 figure(k) subplot(311) plot(n,x(:,k),'-',n,x(:,k),'o'); title(['Signal ' num2str(k)]); subplot(312) plot(n,real(X(:,k)),'*') % axis([0 7 -5 8]) title('Real FFT Coeff.') subplot(313) plot(n,imag(X(:,k)),'*') % axis([0 7 -5 8]) title('Imag FFT Coeff.') end % Effect of zero-padding signal 6 X6_16 = fft(x6, 16); n16 = 0:.5:7.5; figure(7) subplot(411) plot(n,x(:,k),'-',n,x(:,k),'o'); title('Signal 6 with zero padding to N = 16') subplot(412) plot(n,real(X(:,6)),'x') hold on plot(n16,real(X6_16),'o') hold off ylabel('Real FFT') subplot(413) plot(n,imag(X(:,6)),'x') hold on plot(n16,imag(X6_16),'o') hold off ylabel('Imag FFT') subplot(414) plot(n,abs(X(:,6)),'x') hold on plot(n16,abs(X6_16),'o') hold off ylabel('Abs FFT')