fft_plot.m
%
% function file to perform a Fast Fourier Transform
% of a data vector and plot both the time and frequency domain trace
%
function fftplot = fft_plot(y,dt)
%
% input: y - data vector
% dt - spacing of signal in time domain
%
% output: plot of signal in time and frequency domain
% Fourier transform calculation
ffty = fft(y)/length(y)*2; % perform FFT and scale
ffty(1) = ffty(1)/2; % correct DC value
% time domain plot
subplot(2,1,1);
t = 0:dt:(length(y)-1)*dt; % create time vector for plotting
plot(t,y);
xlabel('time (sec)');
ylabel('amplitude');
title('Time and Frequency Domain Representation of a Signal');
% for the FFT plot, only plot length(ffty)/2 + 1 points
% and scale x-axis as frequency...
subplot(2,1,2);
numfft = length(ffty)/2 + 1;
f = linspace(0,1/dt/2,numfft); % o
stem(f,abs(ffty(1:numfft))); % 'stem' plot |
xlabel('frequency (Hz)');
ylabel('amplitude');