Casadi and convolution/filters

144 views
Skip to first unread message

Dave Goel

unread,
May 15, 2017, 3:33:02 PM5/15/17
to CasADi
Do you guys know of a  facility in casadi that provides or allows a way to get convolutions or filters? 
I'm currently using for-loops, and keep thinking I'm missing something. 

I would like to do this efficienty: 

sum_i  coeff(i) shift(vector,i)

where shift does a circular shift by amount i. 

Where both coeff and vector are casadi objects. 


Joel Andersson

unread,
May 16, 2017, 10:48:47 AM5/16/17
to CasADi
You could probably do something like that with a combination of "repmat", and "reshape":

n = vector.size1()
S
= mtimes(reshape(
repmat(
vector, 1, n+1), n+1, n), coeff)

For MX, that might be more efficient. "reshape" is free in MX and repmat is very cheap.

Joel

Dave Goel

unread,
May 16, 2017, 4:28:27 PM5/16/17
to Joel Andersson, CasADi

Joel,

That's really neat! Thanks for that trick.  That might be the way to go. 

My concern is that creates a n^2 matrix, and my n is 10k... 

BTW, I know that octave/matlab's functions conv, conv2 and filter are very efficient in that regard.  In fact, conv is a m-file that uses the c-file filter as a backend. 


For example, I can simply conv(vector, coefficients).
Or, if I want the shift behavior,  I can
conv2([vector; vector], coefficients, "valid") ## Using conv2 in the 1-d sense, not 2-d. Using conv2 instead of conv to use the "valid" feature. 

The only problem is that they don't work when vector and coefficients are  casadi objects.  

It seems to me that it all hinges on a salient facility "filter" that might be nice to have in casadi some day.
An example of filter is, say, a signal-smoothing 30-day moving average filter..

I don't mean to sound like an ungrateful brat. Thanks for the neat n+1 trick! I will go play around with that more. 


--
Sent from CasADi's user forum at http://forum.casadi.org.
---
You received this message because you are subscribed to a topic in the Google Groups "CasADi" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/casadi-users/V3yzkeYidkM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to casadi-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/casadi-users/8587883a-78e1-4b0e-b7f0-a8e6ef5e6a04%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Joel Andersson

unread,
May 17, 2017, 10:02:13 AM5/17/17
to CasADi, j.a.e.a...@gmail.com
Alright, I've created an issue for it: https://github.com/casadi/casadi/issues/2007
There are no immediate plans to implement it, though.

Dave Goel

unread,
May 17, 2017, 11:57:40 PM5/17/17
to Joel Andersson, CasADi
Joel, Many thanks.

On Wed, May 17, 2017 at 10:02 AM, Joel Andersson <j.a.e.a...@gmail.com> wrote:
Alright, I've created an issue for it: https://github.com/casadi/casadi/issues/2007
There are no immediate plans to implement it, though.

--
Sent from CasADi's user forum at http://forum.casadi.org.
---
You received this message because you are subscribed to a topic in the Google Groups "CasADi" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/casadi-users/V3yzkeYidkM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to casadi-users+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages