function [f,W] = dft(f1,f2,N,T) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %ECOMMS Spring 00 Class Demo %S. Mandayam, ECE Dept., Rowan University % %Function Usage: [f,W] = dft(f1,f2,N,T) % %Purpose: %Demonstrate Discrete Fourier Transform using the fft function %How to generate the frequency axis % %Example waveform: Sum of 2 sine waves: %w(t)=sin(2*pi*f1*t)+sin(2*pi*f2*t) % %Function Inputs: %f1, f2: frequencies of the two sine waves %N: no. of samples (must be 2^m) %T: duration of the entire waveform % %Function Outputs %f: frequency axis %W: FFT of w(t) %W is a complex quantity %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% close all; %sampling interval dt=T/N; %samples index n=0:N-1; %corresponding time index t=n*dt; %original time domain sampled signal w=sin(2*pi*f1*t)+sin(2*pi*f2*t); subplot(2,1,1);plot(t,w); title(['Time Domain: w(t) = sin(2\pi' int2str(f1) 't) + sin(2\pi' int2str(f2) 't)']); xlabel('t in s'); ylabel('w(t)'); %sampling frequency fs=1/dt; %calculate the FFT W = dt*fft(w); %calculate the frequency axis f=n/T; subplot(2,1,2);plot(f, abs(W)); title('Amplitude Spectrum'); xlabel(['f in Hz: Sampling Frequency f_s = ' int2str(fs) 'Hz']); ylabel('|W(f)|');