% ftfft script approximates Fourier transform % of x(t) based on samples x(t1),...,x(t2), % where samples are uniformly spaced by 1/fs. % EXAMPLE: x(t) = cos(2*pi*10*t) subplot(2,1,1) % Plot waveform x(t) t = linspace(0,1,200); plot(t,cos(2*pi*10*t)) title('\itx\rm(\itt\rm)=cos(2*pi*10*\itt\rm)') grid on fs = 24; % Select sampling rate. Since the cutoff freq. is 10, % the Nyquist rate is 20. t1 = 0; % Sample x(t) for t1<=t<=t2 ... t2 = 4; n1 = ceil(fs*t1); % ... using time values of the form n/fs n2 = floor(fs*t2); nvec = [n1:n2]; t = nvec/fs; % Note that we are redefining t x = cos(2*pi*10*t); % Compute function values [y,f] = dtftfft(x,n1,0); % Compute DTFT on [-1/2,1/2] f = f*fs; % Convert freq. to [-fs/2,fs/2] y = y/fs; % Scale DTFT subplot(2,1,2) plot(f,abs(y)) title('Approximate Fourier transform') grid on