Help with Amplitude Spectrum of Fourier Tranform

5 次查看(过去 30 天)
%%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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Spectral Measurements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by