Most Efficient Way to Smooth Wavelet Spectral Matrix over Time and Frequency

조회 수: 2 (최근 30일)
I want to smooth a 4 dimensional matrix (channel i x channel j x frequency x time) containing wavelet coefficients across time and frequency for each channel ij pair.
Dimenions of S:
size(S)
ans =
3 3 67 4501
My solution:
% Smoothing over time
k = 50;
for chani = 1:size(S,1)
for chanj = 1:size(S,2)
for freqi = 1:size(S,3)
temporalsmoothedS(chani,chanj,freqi,:) = movmean(squeeze(S(chani,chanj,freqi,:)),k);
end
end
end
clear k chani chanj freqi
% Smoothing over frequency
k = 3;
for chani = 1:size(S,1)
for chanj = 1:size(S,2)
for timei = 1:size(S,4)
doublesmoothedS(chani,chanj,:,timei) = movmean(squeeze(S(chani,chanj,:,timei)),k);
end
end
end
clear k chani chanj timei temporalsmoothedS
Is there a way to do this better? Perhaps do time and frequency at the same time? would conv2 work? Do I absolutely need all the loops? Thanks.

채택된 답변

William Rose
William Rose 2022년 10월 24일
@Anas Khan, I think your approach is good. It has the virtues of being readable and easy to follow. You do not need
clear k chani chanj freqi
since k, chani, chanj will all be assigned new values in a line or two, and it is not necessary to remove freqi from memory.
You also don't need
clear k chani chanj timei temporalsmoothedS
for similar reasons. And in the case of temporalsmoothedS, you have computed it and then erased it without ever using it for anything - like plotting, saving to a file, etc.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Signal Analysis에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by