periodogram for 200 Hz sample rate returns 129 array length

3 次查看(过去 30 天)
why periodogram for 200 Hz sample rate, for 1 second, returns an array lenght of 129, if called without parameters. why it's not 100
signal = linspace(0,3000,200)'; %this is 1 second of my signal (200 because that's the sample rate)
[x,y] = periodogram(signal,[],[],200);
x
x = 129×1
1.0e+06 * 2.2500 1.1035 0.2091 0.0750 0.0438 0.0316 0.0222 0.0152 0.0112 0.0093

采纳的回答

Paul
Paul 2023-1-24
Hi sam,
signal = linspace(0,3000,200)'; %this is 1 second of my signal (200 because that's the sample rate)
[x,y] = periodogram(signal,[],[],200);
numel(signal)
ans = 200
Because signal is only 200 elements and nfft is set for default, nfft will be (according to periodogram)
nfft = max(256,2^nextpow2(length(signal)))
nfft = 256
The default for "freqrange" is 'onesided', in which case with nfft = 256, x will have length nfft/2 + 1 = 129 (also on periodogram)
  3 个评论
Paul
Paul 2023-1-24
编辑:Paul 2023-1-24
I don't know what you mean by "100 Hz and not 129 bins," as in I don't know how you're relating Hz and bins. In the original code, the periodogram was computed as
signal = linspace(0,3000,200)'; %this is 1 second of my signal (200 because that's the sample rate)
[x,y] = periodogram(signal,[],[],200);
The resulting frequency vector y has
numel(y)
ans = 129
129 bins and the final frequency in y is
y(end)
ans = 100
100 Hz, which is what happens when nfft is even and freqrange is onesided. With nfft even, numel(y) will always be odd when freqrange is onesided.
In the new code
[x,y] = periodogram(signal,[],199,200);
the frequency vector has 100 bins
numel(y)
ans = 100
but the final frequency point is just short of 100 Hz
y(end)
ans = 99.4975
which is what happens when nfft is odd and freqrange is onesided.
sam
sam 2023-1-25
I beleive I need to do more reading on nfft, I wanted to end up with a frquency vector of 100 bins only not 129, that's why I thought using 199.
the part that confuses me is if changing the nfft might affect my periodogram results. I guess this is beyond the scope of this post and MATLAB itself.
thank you.
Sam

请先登录,再进行评论。

更多回答(0 个)

类别

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

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by