Accessing previous input samples

Mar 18, 2011 at 9:02pm

Accessing previous input samples

Hi,
I’m trying to implement the following difference equation (an antiresonator) as a max external

y(n) = (1/A)*x(n) – (B/A)*x(n-2) – (C/A)*x(n-3)

My question is how do I access the previous samples required for this. I have done this many times in non real-time situations (in Matlab) but I’m a little unsure of how to deal with the input vector.
Is it a matter of simply subtracting 1 from the *in pointer for each previous sample or is it necessary to store the values somewhere?
Thanks!

#55640
Mar 19, 2011 at 7:23am

Hello jrdalton,

IMHO : as you get “vectorsize length slices of sample” you should store previous slice in your external to compute case when n is {0, 1, 2}.

#200132
Mar 19, 2011 at 8:49am

Hello,

have you read “Advanced signal object topics” in the “MAX 5 API Reference” ?

use an array t_float f_sample[4]; instead of a single value …

HTH

#200133
Mar 19, 2011 at 10:57am

Thanks for the reply.
I’ll try that out!

#200134
Mar 21, 2011 at 7:03pm

That worked out fine.
I made an array of 4 elements to store the values of x(n)…..x(n-3) and shifted them to the right at the beginning of each iteration of the dsp loop. Quite simple in the end. I’m just not so used to processing streams like that.
Thanks for the help.
John

#200135
Mar 22, 2011 at 7:11am

Hello,

IMHO : just take care about vector size < 4, and don't forgot to set your array to zero at DSP on if you don't want artifacts.

#200136
Mar 22, 2011 at 11:23am

You should probably look up “ring buffer” in a text book on data structures. It is more efficient than shifting data around at every sample. However, if your buffer is only four elements it won’t make a big difference.

Still, for future reference. If you try to scale your approach to delay lines of several milliseconds (ie hundreds or thousands of samples) it will be imperative to use a more efficient approach.

#200137

You must be logged in to reply to this topic.