Help with Amplitude Spectrum of Fourier Tranform

5 Ansichten (letzte 30 Tage)
Jim Tom
Jim Tom am 16 Sep. 2017
Kommentiert: Star Strider am 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!

Akzeptierte Antwort

Star Strider
Star Strider am 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 Kommentare
Jim Tom
Jim Tom am 16 Sep. 2017
Edit: Never mind I found a function to do this for me thanks for the advice, I accepted your answer.
Star Strider
Star Strider am 16 Sep. 2017
My pleasure.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by