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

2 ビュー (過去 30 日間)
Anas Khan
Anas Khan 2022 年 10 月 23 日
回答済み: William Rose 2022 年 10 月 24 日
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 Center および File ExchangeSignal Analysis についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by