% % SDSMT Signals Class EE312 % Dr. Charles R. Tolle % % The use of the FFT and an example of aliasing. % Ts = .1; % sampling time Fs = 1 / Ts; % sampling frequency S = 256; % number of samples t = 0:Ts:(S-1)*Ts; % time signal x = cos(2*pi*t); % x(t) signal of interest f = linspace(0,Fs,S); % define the fft frequencies aX = abs(fft(x)); % calculate the magnitude protion % of the FFT(x(t)) pX = angle(fft(x)); % calculate the angle protion % of the FFT(x(t)) % plot x(t) figure(1),subplot(3,1,1),plot(t,x) figure(1),subplot(3,1,1),title('x(t)= cos(2 \pi t)') % plot the resultant mag and angle of the fft from 0-Fs figure(1),subplot(3,2,3),plot(f,aX) figure(1),subplot(3,2,3),title('|fft(x(t))|') figure(1),subplot(3,2,5),plot(f,pX) figure(1),subplot(3,2,5),title('phase(fft(x(t)))') % plot the spectrum from -Fs/2 to Fs/2 figure(1),subplot(3,2,4),plot(f(1:S/2),aX(1:S/2),(f(1:S/2)-(Fs/2)),aX(((S/2)+1):S)) figure(1),subplot(3,2,4),title('|fft(x(t))| plotted from -Fs to Fs') figure(1),subplot(3,2,6),plot(f(1:S/2),pX(1:S/2),(f(1:S/2)-(Fs/2)),pX(((S/2)+1):S)) figure(1),subplot(3,2,6),title('phase(fft(x(t))) plotted from -Fs to Fs') for j= 1:Fs, if (j > Fs / 2) alias = 'Aliased '; else alias = ''; end dt = 0:Ts/2:(S-1)*Ts; % double sample time signal dx = cos(2*pi*dt) + cos(2*pi*j*dt); % x(t) signal double sample time x = cos(2*pi*t) + cos(2*pi*j*t); % x(t) signal sampled aX = abs(fft(x)); % calculate the magnitude protion % of the FFT(x(t)) pX = angle(fft(x)); % calculate the angle protion % plot x(t) figure(2),subplot(4,1,1),plot(t,x) figure(2),subplot(4,1,1),title([alias 'x(t)= cos(2 \pi t) + cos(2 \pi' ,num2str(j) ' t) sampled at: ' num2str(Ts)]) % plot dx(t) figure(2),subplot(4,1,2),plot(dt,dx) figure(2),subplot(4,1,2),title(['x(t)= cos(2 \pi t) + cos(2 \pi' ,num2str(j) ' t) sampled at: ' num2str(Ts/2)]) % plot the resultant mag and angle of the fft from 0-Fs figure(2),subplot(4,2,5),plot(f,aX) figure(2),subplot(4,2,5),title([alias '|fft(x(t))|']) figure(2),subplot(4,2,7),plot(f,pX) figure(2),subplot(4,2,7),title([alias 'phase(fft(x(t)))']) % plot the spectrum from -Fs/2 to Fs/2 figure(2),subplot(4,2,6),plot(f(1:S/2),aX(1:S/2),(f(1:S/2)-(Fs/2)),aX(((S/2)+1):S)) figure(2),subplot(4,2,6),title([ alias '|fft(x(t))| plotted from -Fs to Fs']) figure(2),subplot(4,2,8),plot(f(1:S/2),pX(1:S/2),(f(1:S/2)-(Fs/2)),pX(((S/2)+1):S)) figure(2),subplot(4,2,8),title([alias 'phase(fft(x(t))) plotted from -Fs to Fs']) pause(1) end