필터 지우기
필터 지우기

Trying to plot frequency spectrum from set of samples.

조회 수: 7 (최근 30일)
Jorge Cantu
Jorge Cantu 2015년 5월 5일
댓글: Amirmahdi Matin 2020년 3월 18일
Hi everyone. I have a set of samples (x(n)'s) in a table corresponding to a mysterious signal x(t). What I am trying to do is display the frequency spectrum of this set of samples with a certain resolution.
I am confused on how to actually plot this frequency spectrum when I am just given a table of values, an fs, and using a certain N value.
So for example, say I was given a set of samples like this:
0 1 2 3 4 5 6 7 8 9 0 1.25 0.57 -0.29 -0.78 -0.70 0.37 0.87 0.49 -0.18
How would I plot the frequency spectrum with say a resolution of 50 hz?
I went about it like this, (keep in mind this code pertains to a set of samples that is 1251 long, I created the above example for ease of use), however my graph doesn't look right as the magnitudes shouldn't go above 1 since the amplitudes never go above 1?
signal = xt;
N = length(signal);
fs = 25000; % 25000 samples per second
fnyquist = fs/2; %Nyquist frequency
plot(abs(fft(signal)))
xlabel('Frequency Spectrum)')
ylabel('Magnitude');
title('Double-sided Magnitude spectrum');
axis tight
  댓글 수: 1
Amirmahdi Matin
Amirmahdi Matin 2020년 3월 18일
how to realize main component frequencies and their amplitudes of this signal ??

댓글을 달려면 로그인하십시오.

채택된 답변

Star Strider
Star Strider 2015년 5월 5일
‘So for example, say I was given a set of samples like this:’
‘0 1 2 3 4 5 6 7 8 9 0 1.25 0.57 -0.29 -0.78 -0.70 0.37 0.87 0.49 -0.18’
‘How would I plot the frequency spectrum with say a resolution of 50 hz?’
You would do it with the absolutely clear code between the first two figures in the documentation for the fft function.
This is essentially an exact copy of that code, other than its using your vector and sampling frequency:
x = [0 1 2 3 4 5 6 7 8 9 0 1.25 0.57 -0.29 -0.78 -0.70 0.37 0.87 0.49 -0.18];
Fs = 50;
Fn = Fs/2;
Fx = fft(x)/length(x);
Fv = linspace(0, 1, length(x)/2+1)*Fn;
Iv = 1:length(Fv);
figure(1)
plot(Fv, abs(Fx(Iv)))
grid
xlabel('Frequency (Hz)')
ylabel('Amplitude')

추가 답변 (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