Most Efficient Way to Smooth Wavelet Spectral Matrix over Time and Frequency
1 次查看(过去 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.
0 个评论
采纳的回答
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Signal Analysis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!