pkg load signal graphics_toolkit gnuplot %======================================================= function out=gauss(M2,sigma) % window function out = exp(-.5*(((0:M2)-M2/2)/(sigma*M2/2)).^2); endfunction %======================================================= % Dimensions of figure x1 = .07; % left margin x2 = .02; % right margin y1 = .07; % bottom margin for annotation y2 = .07; % top margin for title width = 1-x1-x2; height= 1-y1-y2; x_origin = x1; y_origin = 1; % start at top of graph area %======================================================= set(0, "DefaultAxesFontsize",12) set(0, "DefaultTextFontsize",14) figure("position",[50 100 800 600]); y_origin = y_origin -y2 -height; % position of top row subplot("position",[x_origin y_origin width height]) N = 8*9*10; M = 4; % finite Fourier transform domain is [-M,M] M2 = 2*M; M21 = M2+1; % sequence length symmetric = gauss(M2,1); symmetric = symmetric/sum(symmetric); periodic = symmetric(1:M2); periodic = periodic/sum(periodic); % A similar window is: % window = kaiser(M21+2, pi*.75)'; % window = window(2:end-1); % Remove zero-valued end points x = 0:M2; y = cos(2*pi*x/4); y_sym = y.*symmetric; y_even = y(1:end-1).*periodic; DTFT = fft(y_sym,N); DFT = fft([y_sym(1)+y_sym(end) y_sym(2:end-1)]); % periodic summation DFTeven = fft(y_even); % truncation (aka "DFT-even") x = 0:N/2; plot(x, real(DTFT(1+x)), "color","blue") hold on plot(x, imag(DTFT(1+x)), "color","blue", "linestyle","--") set(gca, "xaxislocation","origin") xlim([0 N/2]) ylim([-0.4 0.6]) x = (0:M); DFT = DFT(1+x); DFTeven = DFTeven(1+x); x = x*N/M2; plot(x, real(DFT), "color","blue", "o", "markersize",8, "linewidth",2) plot(x, real(DFTeven), "color","red", "*", "markersize",4, "linewidth",2) plot(x, imag(DFT), "color","blue", "o", "markersize",8, "linewidth",2) plot(x, imag(DFTeven), "color","red", "*", "markersize",4, "linewidth",2) h = legend("DTFT real",... "DTFT imaginary",... "periodic summation",... "DFT-even (truncation)", "location","northeast"); set(h, "fontsize",10) %legend boxoff set(gca, "xtick", x, "xgrid","on", "xticklabel",[0 1 2 3 4]) xlabel("DFT bins", "fontsize",14) ylabel("amplitude") title("Sampling the Discrete-time Fourier transform", "fontsize",14);