简体   繁体   中英

Slicing Power Spectral Density over frequency bands

I am using pwelch to get the Power Spectral Density of multiple signal vectors and then finding the average signal to noise ratios over 5 frequency bands.

I converted the power spectral densities to dB and am currently obtaining each band one by one:

P_signal1(band1)
P_signal1(band2)
P_signal1(band3)

...

P_signal2(band1)
P_signal2(band2)

and so on.

Is there any way to obtain this easily, maybe using arrays of the signals and the bands

signals = [P_signal1, P_signal2, P_signal3, P_signal4, P_signal5]
bands = [band1, band2, band3, band4, band5]

and obtain a matrix of each combination?

A = 1:100;
bands = [1:20;21:40;41:60;61:80;81:100];
A(bands)

Full documentation can be seen here .

The idea is indexing in Matlab is a lot different than in other languages, since Matlab uses matrices. When you index an array like A(1) , it will pick one element out, just like any other language. When you index it as A([2,1;3,1]) , magic happens. Matlab will take out elements of A 4 times, each corresponding to one element in [2,1;3,1] . And then it arranges the 4 results in the same form of [2,1;3,1] . The output will be also a matrix.


EDIT: Using cell array

A = 1:100;
bands = {1:20;21:40;41:60;61:80;81:100};
cell2mat( cellfun(@(x) A(x), bands, 'UniformOutput', false) )

This works differently than above, but shares similar idea. Now bands is a cell array, each element containing an index range.

cellfun takes each of this range as x , and evaluate expression A(x) (which means access that part of A ), and put the result into a new cell array, of which the size is same with bands , and the element position accords to the definition in bands .

cell2mat converts this output cell array into a plain numeric array.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM