Help with Amplitude Spectrum of Fourier Tranform

5 views (last 30 days)
Jim Tom
Jim Tom on 16 Sep 2017
Commented: Star Strider on 16 Sep 2017
%%Import the data
[~, ~, raw] = xlsread('/Users/Michael/Downloads/waveform_data (3).xlsx','Sheet1');
raw = raw(2:end,:);
%%Create output variable
data = reshape([raw{:}],size(raw));
%%Allocate imported array to column variable names
t = data(:,1);
y = data(:,2);
This program applies the Fourier transform to a waveform y(t) defined by the vectors t and y in the workspace. Note that these variables must be present in the MATLAB workspace in order for FFT_Code to run.
fs=1/(t(2)-t(1));
nfft=length(t); % Determine the number of data points
tstart=t(1); tfinal=t(end); % The start and stop times of the signal y
F=2/fs*fft(y,nfft)*(1/(tfinal-tstart)); % Apply Fourier transform to y(t) (next two lines)
F=F(1:floor(nfft/2));
M_F=abs(F); % Calculate the amplitude of the sine waves
f=(0:(nfft/2)-1)*(fs/nfft); % Converstion of time to frequency
plot(f,M_F)
axis([0 30 0 30])
So I attached my code, however, you do not have the data I used. I also attached the graph I am currently getting, however, I would like it to look like vertical lines, how it normally looks in an Amplitude Spectra. If anyone has any advice on how to make that happen I would greatly appreciate it. Thanks in advance!

Accepted Answer

Star Strider
Star Strider on 16 Sep 2017
If you simply want to plot vertical lines, the best option is to use the stem (link) plot. See the documentation for ways to customise the plot to create the depiction you want.
  3 Comments

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by