Simple Allpass filter

DSP, Plugin and Host development discussion.
Post Reply New Topic
RELATED
PRODUCTS

Post

Can someone explain how can I achieve a 1-pole all pass filter in C++?
I can't find examples with code and I'm not sure how to implement it. If I understood correctly I should make a 1 sample delay and mix it with the original buffer, right?
Thanks.

Post


Post

Thanks for the link. I think I got the theory now but still dunno exactly how to make it in C++.
I should make a circular buffer delay of 1 sample, is that right?
Do you have any code examples?

Post

You don't need a circular buffer. Two variables are enough.

Code: Select all

float oldy = 0;
float oldx = 0;

for(int i = 0; i < nFrames; ++i)
{
  output|i] = - c * input[i] + oldx + c * oldy;
  oldx = input[i];
  oldy = output[i];
}

Post

Thanks. I tried that but I'm getting really harsh/crackling output.

Also, another question, how can I change the frequency of this filter formula?

Post

The frequency is a function of c (or the opposite). I don't remember the exact formula though. You can write a quick Matlab/Python script to help you.
Of course, |c| < 1. It might be tan(pi * fc/fs)

Post

Save the delay variables between function calls!

Post

Ok I tried with c = 0.5 and almost destroyed my headphones :D
I put c = 0.1 and seems to work as it should.

Still I don't understand how to control both frequency and feedback/resonance of this filter.

I used the RBJ in DSPFilters and worked ok, but I wanted to build mine and try some modulation on cutoff/feedback.

Post

There is no resonance in an all-pass filter. All frequencies have the same gain. What changes is their phase.

It seems that I was wrong (I searched online, and the article I used had it wrong). The proper line is :

Code: Select all

output|i] = c * input[i] + oldx - c * oldy;
Check here for the phase shift: https://ccrma.stanford.edu/realsimple/D ... lters.html

Post

Ok great thanks.

Post

You don't actually need two state variables though, one is enough if you rewrite as DF2/TDF2 (the latter is typically preferable). While not a big deal with single-sample delays, it'll save you half the delay memory (and cache pressure) for longer ones. In fact, TDF2 is exactly what you get with the "all-pass filter reverb element" block diagram from the article linked above:

Code: Select all

float state = 0;
for(unsigned i = 0; i < nSamples; ++i)
{
   output[i] = state + c * input[i];
   state = input[i] - c * output[i];
}
Also, changing the sign of the coefficient should not make things blow up if everything else is correct: the transfer function is (c + z^1)/(1 + c*z^-1) and this is stable for c in ]-1,1[.

Post

mystran wrote: Wed Jul 16, 2014 12:19 pm

Code: Select all

float state = 0;
for(unsigned i = 0; i < nSamples; ++i)
{
   output[i] = state + c * input[i];
   state = input[i] - c * output[i];
}
I knew it's been a few days since there was any activity on this topic, however if somebody has time I would sure appreciate a code example showing the above algorithm as a two pole (stage) allpass filter, thanks!
"Scuba divers work best under pressure!"

https://www.youtube.com/user/DKDiveDude (Original music and hardware videos)

Post Reply

Return to “DSP and Plugin Development”