• ### y[n] = x[n]/samplerate + y[n-1]

How to patch y[n] = x[n]/samplerate + y[n-1] with x the input and y the output in Pure Data?

• Posts 26 | Views 3723
• @Nobody Maybe...... if I understand correctly "n"......

But there will be no value of course for n-1 for the first x.
David.

• Sorry - I want x and y to be audio-signals. And consequently x[0] and y[0] are the values of the samples taken of x and y at a chosen time 0, x[1] and y[1] are the values of x and y at 1 sample time after time 0. Etc.

• Something like this perhaps?:

• @Nobody Ah.
I started writing that you will need a [block~ 1] to get individual sample values......etc.......
David.

• @Nobody Take a look at the help patch for [rpole~]

• Perhaps rzero_rev~ (with a=0) is the easiest way to realize a one sample delay?

• Thanks for all the answers! I can indeed now get a very small (one sample?) delay, but the patch no longer works (at least on my computer) as soon as I use block~ 1 or apply a feedback loop for y to get y[n] = x[n]/samplerate + y[n-1]

• @Nobody Oh, you're right, rpole~ uses the previous input, but you wanted the previous output. My bad. Maybe you could prototype with [fexpr~] and then search for something more efficient (if it matters) once you know it's working?

Edit: crap, just saw @seb-harmonik.ar's post, my bad again. rpole~ doesn't use the previous input, it uses the previous output.

• @Nobody I thought it might be impossible to loop the output with [block~ 1] as it has moved to the next frame already when you need the output.
Maybe [block~ 2] with the y(n-1) delayed by one sample by a [send] + [receive] within the sub-patch?
Or maybe [vline~] can be used within [block~1] as it can schedule even between samples?
y(n) into [vline~] to jump its output to be used as y(n-1) in the next block?
But the [vline~] help file states that its timing is unreliable when a patch is reblocked, so it would need testing.
David.

• Found out just now that the feedback of y by using [send] + [receive] to get y[n] = x[n]/samplerate + y[n-1] results in a drift of y that ultimately drowns the signal.

• (x)
|
[*~ inverse of samplerate]
|
[rpole~ 1]

• Thank you! Yes that should work, but strangely I'm not getting the results that I think I should get...

• @Nobody what results do you think you should get? seems like you should get a kind of lowpassed triangle wave on the right side with that configuration.

• I'm trying to make a mathematical integrator module (not a slew limiter), and indeed feeding a square wave should result in a triangle wave at the output. But sadly for some reason it's not working...

• Now we are getting somewhere:

• Is such a feedback loop as below forbidden in Pure Data? Can't get it to work...

• Yes, it's forbidden. You can't loop signal objects like that. You have to use a [send~] / [receive~] pair to make the loop.

• Thanks! Yes the loop is working now.

• Is there a simple way to give a single pulse to startup the patch instead of the workaround in the red circle?

• @Nobody said:

Is there a simple way to give a single pulse to startup the patch instead of the workaround in the red circle?

The best way I know is to create a two element array -- first value 1, second value 0 -- then tabplay~ to get the impulse.

``````[array define dirac]

|
[t b b]
|     |
|     [; dirac resize 2; dirac 0 1 0(  <<-- message, not object
|
[tabplay~ dirac]
``````

(From memory, maybe I got the array messages wrong)

hjh

Posts 26 | Views 3723
Internal error.

Oops! Looks like something went wrong!