Parameterize overlapping - cpsd()

Hello, everyone.
I need to create a script where overlapping is parameterized. I did it this way:
N = length(u); % = length(y)
percentage = 0.5; %range = [0.01 - 0.99]
window = hanning(round(N/4.5));
overlap = round(length(window)*percentage);
[SuyW,fw] = cpsd(u,y,window,overlap,[],fs);
Can anyone tell me if this is correct?

 Respuesta aceptada

William Rose
William Rose el 22 de Ag. de 2022
Editada: William Rose el 22 de Ag. de 2022
[edit: correcting my recommendation from overlap=floor(...) to overlap=ceil(...)]
Yes this is reasonable.
You can answer your quesiton by trying some different values for N and observing the resulting values for window length and overlap:
%N = length(u); % = length(y)
N=[500,1000,2000,4000];
percentage = 0.5; %range = [0.01 - 0.99]
for i=1:4
window = hanning(round(N(i)/4.5));
overlap = round(length(window)*percentage);
fprintf('N=%d, winLen=%d, overlap=%d\n',N(i),length(window),overlap);
end
N=500, winLen=111, overlap=56 N=1000, winLen=222, overlap=111 N=2000, winLen=444, overlap=222 N=4000, winLen=889, overlap=445
The results look reasonable.
You chose a window length that is 1/4.5 times the signal length, in all cases. This choice will usually allow for 8 half-overlapped windows in the signal. It is possible that, due to rounding, the 8th and final window will not fit. For example, N=98, N=502, N=512, N=1006, N=1024, and others. Therefore I would use
window = hanning(floor(N/4.5));
overlap = ceil(length(window)*percentage);
to assure that the window goes onto the signal 8 times.

2 comentarios

Amanda Santos
Amanda Santos el 22 de Ag. de 2022
Thank you!
William Rose
William Rose el 23 de Ag. de 2022
You're welcome, @Amanda Santos. If my answer suffices, please accept it. Good luck with your work.

Iniciar sesión para comentar.

Más respuestas (0)

Preguntada:

el 21 de Ag. de 2022

Comentada:

el 23 de Ag. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by