Help with Amplitude Spectrum of Fourier Tranform

2 ビュー (過去 30 日間)
Jim Tom
Jim Tom 2017 年 9 月 16 日
コメント済み: Star Strider 2017 年 9 月 16 日
%%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!

採用された回答

Star Strider
Star Strider 2017 年 9 月 16 日
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 件のコメント
Jim Tom
Jim Tom 2017 年 9 月 16 日
Edit: Never mind I found a function to do this for me thanks for the advice, I accepted your answer.
Star Strider
Star Strider 2017 年 9 月 16 日
My pleasure.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDiscrete Fourier and Cosine Transforms についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by