periodogram for 200 Hz sample rate returns 129 array length

3 Ansichten (letzte 30 Tage)
sam
sam am 24 Jan. 2023
Kommentiert: sam am 25 Jan. 2023
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

Akzeptierte Antwort

Paul
Paul am 24 Jan. 2023
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 Kommentare
Paul
Paul am 24 Jan. 2023
Bearbeitet: Paul am 24 Jan. 2023
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 am 25 Jan. 2023
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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by