Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: Computation efficiency: convolution or direct calculation
Replies: 1   Last Post: Dec 5, 2012 6:52 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Luca

Posts: 77
Registered: 6/6/12
Computation efficiency: convolution or direct calculation
Posted: Dec 5, 2012 8:08 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

Hello everybody.
I wrote a code of a couple of lines in 2 minutes that computes the response of a dynamic system to a stimulus.
This is described by differential equations.
In the first draft, where I wasn't looking at all for efficiency, correct code etc.... I did

for i=2:numel(F)
c1(i) = c1(i-1) + k1*S(i)-(k2+k3)*c1(i-1)
c2(i) = c2(i-1)+k3*c1(i)
end
CC = c1+c2;
(where CC is my total system response, c1 and c2 the response of two subsystems and S the external stymulus)
With F having an huge number of elements (~100k) to achieve very fine "temporal" resolution so that using this Euler method to solve the ODE achieves the correct solution. I know this isn't the best method and I know that for loops are bad in matlab, for what speed is concerned
I also happen to know that this system has an analytical solution which is
CC = conv (R,S) with R being the impulse response and S the stimulus.
So I tried to use this to improve computation speed and "code beauty".
R = zeros (size(S));
R = (function(i));

CC = conv (R,S);
(R and S have the same size of 100k).
It turns out using tic and toc that the ugly method using the for loops takes 5 ms while the convolution using conv take 220 ms.
How's that???
(ok... maybe with the convolution I could go to much wider "time" frames to reduce the dimension of about 10-100 and become as fast or faster...)

And... which method shall I be using?
Can I improve the "for" cycle in some way?



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.