speeding up the proccess
Información
La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.
Mostrar comentarios más antiguos
hello,
I have a wavfile that I read with 'wavread' and I want to apply some weighting function on each channel. everything is working ok, but it takes almost 2 minutes to through the for loop. Any ideas as to how to speed things up? the sampling frequency fs=32kHz and duration is 10secs.
[y,fs] = wavread('C:\Desktop\testwavfile')
y = y';
t =0:1/fs:length(y)/fs-1/fs;
t = t';
gain1 = 0:4/fs:40-4/fs; %this is level
gain2 = 20:4/fs:60-4/fs;
gain3 = 40:-4/fs:0+4/fs;
t1 = 8*fs;
slope = (gain2(1)-gain2(t1))/t1;
con = slope+gain2(1);
slopeout = (gain1(5*fs)-gain1(t1))/t1;
conout = slopeout+gain1(5*fs);
%creates a weighting function
for iTime = 1:t1
temp(iTime) = -slope*iTime+con; %#ok<*SAGROW>
out(iTime) = -slopeout*iTime+conout;
end
temp(t1+1:length(y)) = 6.5*gain3(t1+1:length(y));
out(t1+1:length(y)) = 4*gain3(t1+1:length(y));
3 comentarios
Matt Kindig
el 25 de Abr. de 2013
First thing I would do is pre-allocate temp and out before entering the for loop. Add this:
npts = length(1:t1);
temp = NaN(1,npts);
out = NaN(1,npts);
for iTime = 1:t1
.....
Does this help?
Matt Kindig
el 25 de Abr. de 2013
In fact, the for loop doesn't even appear to be necessary. You can define both of them as:
temp(1:t1) = -slope*iTime+con;
out(1:t1) = -slopeout*iTime+conout;
and eliminate the for loop entirely.
tony karamp
el 25 de Abr. de 2013
Respuestas (0)
La pregunta está cerrada.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!