Most Efficient Way to Smooth Wavelet Spectral Matrix over Time and Frequency
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Anas Khan
am 23 Okt. 2022
Beantwortet: William Rose
am 24 Okt. 2022
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 Kommentare
Akzeptierte Antwort
William Rose
am 24 Okt. 2022
@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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Signal Analysis finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!