Hello; Can someone please help me matlab doesn't plot my excel data it show the axis only I am trying to make spectral analysis.i have attested the excel file and code as well.

filename = 'datacollect2.xlsx';
N = length(filename);
fs = 400;
fnyquest = fs/2;
num = xlsread(filename);
y = num(: ,2);
mags = abs(fft(y));
bin_vals = [0 : N-1];
fax_Hz = bin_vals*fs/N;
N_2 = ceil(N/2);
plot(mags(1:N_2),fax_hz(1:N_2))
xlabel('Frequency (Hz)')
ylabel('Power (dB)');
title('Single-sided Power spectrum (Hertz)');
axis tight

5 件のコメント

Jan
Jan 2017 年 5 月 14 日
What happens instead of the expected plotting? Do you get an error message? Does the axes appear but is empty? Please explain any details.
dpb
dpb 2017 年 5 月 15 日
編集済み: Image Analyst 2017 年 5 月 15 日
For one thing you've reversed the role of X and Y in
plot(mags(1:N_2), fax_hz(1:N_2));
The file isn't attached
You might also use semilogy() instead of plot(),
semilogy(mags(1:N_2), fax_hz(1:N_2))
or take the log of the data before plotting, like
mags = log(abs(fft(y)));
yes the axis is appeared its empty but when I removed this line (fax_hz(1:N_2)) from the plot command its shows the complete spectral. No there is no any error.
here is the data file attached

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

 採用された回答

dpb
dpb 2017 年 5 月 15 日
編集済み: dpb 2017 年 5 月 15 日
filename = 'datacollect2.xlsx';
N = length(filename);
fs = 400;
fnyquest = fs/2;
num = xlsread(filename);
y = num(: ,2);
mags = abs(fft(y));
bin_vals = [0 : N-1];
Probably biggest problem is you've used the length of the filename as the length of the data. The file name is just that; the string containing the name of the file on the disk, it has nothing whatsoever to do with the data contained in the file.
Here,
>> filename = 'datacollect2.xlsx';
N = length(filename)
N =
17
>>
so all you've plotted are the first 9 points out of the arrays; not much at all... :)
N = length(y);
after you've defined y will undoubtedly help a lot, particularly when you get the roles of X,Y corrected in the plot statement.
You may want to also plot 2*abs(fft(y))/N to normalize the spectrum amplitude to input. See
doc fft % example there shows some other details as well

3 件のコメント

Thankyou very much it works
arif hussain
arif hussain 2017 年 5 月 16 日
編集済み: dpb 2017 年 5 月 16 日
i dont think so this is accurate spectrum may be something wrong here.data file and code attested below.
filename = 'datacollect2.xlsx';
num = xlsread(filename);
fs = 400;
x = num(:,1);
N = length(x);
y = num(: ,2);
mags = abs(fft(y));
bin_vals = [0 : N-1];
fax_Hz = bin_vals*fs/N;
N_2 = ceil(N/2);
plot(mags(1:N_2),fax_Hz(1:N_2))
dpb
dpb 2017 年 5 月 16 日
編集済み: dpb 2017 年 5 月 17 日
You're still using the spectrum magnitude as the independent variable in the PLOT() call. WHY???
Also, you've taken the amplitude normalization out. WHY?
I would again refer you back to the example at
doc fft

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

その他の回答 (0 件)

質問済み:

2017 年 5 月 14 日

編集済み:

dpb
2017 年 5 月 17 日

Community Treasure Hunt

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

Start Hunting!

Translated by