Info

This question is closed. Reopen it to edit or answer.

Can this loop be sped up significantly?

1 view (last 30 days)
Greg
Greg on 5 Aug 2015
Closed: MATLAB Answer Bot on 20 Aug 2021
I'm at a loss as to how I can speed up this loop since each time-step is dependent on the result of the previous time-step. Can this be vectorized with some nifty approach?
for t = startingT:T
data = [d(t-lagsT)' E(t - lagsTE)'];
E(t) = data * coefficients;
end
Thank you,
Greg
  3 Comments
Greg
Greg on 5 Aug 2015
Edited: Greg on 5 Aug 2015
Hi Sean, here is some sample data. E is preallocated to zeros just to size the vector. Thanks!:
startingT = 13;
d = [1.55149071327081;1.56248982174286;1.58571921956013;1.58099983724182;1.56773856348363;1.59031111151726;1.60888021170078;1.60888021170078;1.59181450560137;1.56425716004716;1.53566023323503;1.56248982174286;1.55707712813730;1.57614622446784;1.59913701799709;1.59031111151726;1.57449728399522;1.61022686232037;1.63623532049494;1.63623532049494;1.62187920421241;1.58726369730255;1.55523479881416;1.59769775015494;1.60477380084050;1.61156271226651;1.64514931173688;1.62801433742922;1.63851008693496;1.64514931173688;1.66644278137904;1.66644278137904;1.65152676960581;1.62680548626165;1.60615385014149;1.63158832825324;1.63737667622902;1.64730325573662;1.66064233876493;1.64836955136057;1.65048122380753;1.68352353885613;1.69342593031195;1.70273474429601;1.67566268329654;1.65866101678505;1.63851008693496;1.66162385851159;1.66356896183731;1.66356896183731;1.69815033940554;1.69737287371485;1.69262435098263;1.70348574005080;1.71846254557336;1.72380214464442;1.69892391754576;1.67744381527656;1.64730325573662;1.66833019377893;1.67111985628275;1.65564225297093;1.69737287371485;1.69100868601660;1.69659148379588;1.71846254557336;1.74229380500042;1.73698162118278;1.71502745296964;1.69262435098263;1.67019541559399;1.69262435098263];
E = [0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0];
coefficients = [-1;-0.00146675057476386];
lagsT = [0 12];
lagsTE = [0 1]; % use this as the lags for vector E
Greg
Greg on 5 Aug 2015
Sorry Sean, just made a quick edit to coefficients. It should work now.

Answers (1)

Muthu Annamalai
Muthu Annamalai on 5 Aug 2015
Edited: Muthu Annamalai on 5 Aug 2015
It seems like you are trying to calculate a 2-tap FIR filter (if your lagsTE = 1) or lagsTE+1 tap FIR filter with lagsTE-2 coefficients set to 0.
Maybe you could do this in the frequency domain without carrying out the convolution in the time domain.
Try using the MATLAB command filter http://www.mathworks.com/help/matlab/ref/filter.html

This question is closed.

Community Treasure Hunt

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

Start Hunting!