How to vectorise the filter function with multiple window-sizes?

2 次查看(过去 30 天)
The task is to calculate the maximum of a moving rms-value of a signal, which is available with a constant timestep dt. So the signal has the length of T*dt and the RMS-value shall be calculated for a period tau=1*dt, tau=2*dt, tau=3*dt, ... tau=T*dt. At the end of this calulation the max of the moving rms value shall be selected. Actually I use the filter-function in a for-loop, but maybe it is possible to vectorise the calculation?
The code is below:
function [tau, werte_eff_H ] = twa_stat_2(signal)
% any signal-vector;
signal_eff = signal.^2; % To calculate the RMS-Values
no_value = size(signal,1);
tau = (1:1:no_value)';
werte_eff_H = NaN(size(signal,1)+1, no_value); % Preallocation
for i=1:size(tau,1)
zb_werte_eff = sqrt(filter(ones(1,tau(i,1))./tau(i,1),1,[signal_eff(1:no_value); signal_eff(1:tau(i,1)-1,1); 0 ] ));
werte_eff_H(:,i) = zb_werte_eff(0+tau(i,1):no_value+tau(i,1),1);
end
werte_eff_H = werte_eff_H(1:end-1,:);
end

采纳的回答

Jan
Jan 2017-6-20
编辑:Jan 2017-6-20
You can save 25% runtime by calculating the srqt() only of the used values and create the padded signal once only - and some slightly changes:
function [tau, werte_eff_H ] = twa_stat_2(signal)
% any signal-vector;
signal_eff = signal.^2; % To calculate the RMS-Values
no_value = size(signal,1);
tau = (1:1:no_value)';
werte_eff_H = zeros(size(signal,1), no_value); % Preallocation
signal2 = [signal_eff; signal_eff];
for i=1:no_value
zb_werte_eff = filter(ones(1,i) ./ i, 1, signal2(1:no_value + i,1));
werte_eff_H(:,i) = zb_werte_eff(i:no_value+i-1,1);
end
werte_eff_H = sqrt(werte_eff_H);
end
A vectorization of the different filter calls is not possible, as far as I can see. Using parfor might be useful, but filter is multithreaded already and if all cores are used, a parallelization will not have a positive effect.
Perhaps the movmean filter is faster than filter. Do you have a C-compiler? Then a hand made C-Mex functions for the moving average will be faster.

更多回答(1 个)

dalya anewr
dalya anewr 2017-6-28
hi text2speech Error using feval Input PROGID does not represent an Activex control. If this PROGID used to work before, please check vendor's documentation for equivalent activex control progid.
Error in actxcontrol
Error in actxcontrol
Error in text2speech (line 55) vlc1 = actxcontrol('VideoLAN.VLCPlugin.2', [1 1 0 0], fig); please i need help
  1 个评论
Jan
Jan 2017-6-28
编辑:Jan 2017-6-28
Please do not highjack another thread. This is not an answer to the original question. Open a new thread and delete this message. Thanks.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Speech Recognition 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by