input freqRange in bandpower doc example returning an error when it is a Mx2 matrix

Hello,
While reading the doc of the function bandpower, I tried the example Percentage of Power in Frequency Bands (Periodogram) (in MATLAB online).
The line
powBands = bandpower(Pxx,F,[50 150;200 300],"psd");
returned the following error:
Error using bandpower
Expected input number 3, FREQRANGE, to be a vector.
Error in bandpower>psdbandpower (line 152)
validateattributes(freqrange,{'numeric'},{'vector','finite','real',...
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error in bandpower>timedomainbandpower (line 110)
pwr = psdbandpower(Pxx,F,freqrange);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error in bandpower (line 65)
pwr = timedomainbandpower(inputArgs{:});
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
which is quite incomprehensible, as the input description stipulate:
Frequency range for the band-power computation, specified as a two-element real-valued vector or as an M-by-2 real-valued matrix. M is the number of intervals along which to compute the band power.
Moreover, there is no mention about that in the Version History section
Did I miss something ?
Best regards,

Answers (1)

The specification of "freqRange" as Mx2 matrix was introduced in R2026a. Do you use this MATLAB version already ?
Alternatively, you can use
rng("default")
Fs = 1000;
t = 0:1/Fs:1-0.001;
x = cos(2*pi*100*t) + t.*chirp(t,220,t(end),270) + 0.2*randn(size(t));
[Pxx,F] = periodogram(x,hamming(length(x)),length(x),Fs);
periodogram(x,hamming(length(x)),length(x),Fs)
freqRange = [50 150;200 300];
powBands = [bandpower(Pxx,F,freqRange(1,:),"psd");bandpower(Pxx,F,freqRange(2,:),"psd")];
powTotal = bandpower(Pxx,F,[0 500],"psd");
powPercent = 100*powBands/powTotal
powPercent = 2×1
76.0390 20.6880
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>

Asked:

about 9 hours ago

Edited:

about 8 hours ago

Community Treasure Hunt

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

Start Hunting!