Help with Amplitude Spectrum of Fourier Tranform
2 ビュー (過去 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!
0 件のコメント
採用された回答
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 件のコメント
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!