# How does Amplitude-rescaling work in filters?

Today I tried implementing my own simple low-pass filter using the pseudocode from Wikipedia as a starting point. Specifically, this code:

``````   for i from 1 to n
y[i] := y[i-1] + α * (x[i] - y[i-1])
``````

Which can also be written as:

``````for each sample:
filtered_sample = previous_filtered_sample + α * (input_sample - previous_filtered_sample)
``````

I've implemented a quick and dirty version here, using Floatbeat.

When decreasing α (the smoothing factor of the filter, in other words: we are decreasing the cutoff frequency of the filter), the resulting signal gets softer and softer. This is of course not strange since we are losing energy when removing frequencies.

However, when applying a filter and doing a filter sweep in my DAW, the amplitude keeps constant: It seems that the amplitude gets re-scaled to offset this problem.

So, my question: How do I know with what value to multiply my filtered signal to give it the same amplitude it had before the filter?

You could try a few values.

If a = 0 then the amplitude remains at unity i.e. the algorithm acts as a 1 sample delay.

If a = 1 then athe amplitude is also unity with the output = the input

Somewhere in between 0 and 1 I think is where you are operating and if you did a quick spreadsheet and kept the input constant at "1" i.e. a dc level then you'd see how it shapes up.

For instance try 0.5. First time thru o/p = 0.5 of the input because previous = 0

• Next time output = 0.5 + 0.5(1 - 0.5) = 0.75
• Next time output = 0.75 + 0.5(1 - 0.75) = 0.875
• Next time output = 0.875 + 0.5(1 - 0.875) = 0.9375

It looks to me like it doesn't need rescaling because it seems to be heading for a final value of 1. And it does look like a low pass filter.

If you want to try some other interesting filters in software THIS might give you a few extra pointers - see the appendix about trying stuff out in excel.

• I see... Then there might be something that I am doing wrong in the implementation I made. When using a value like a=0.01 or lower, the sound seems to be much softer than I'd expect. Anyway, this approach is a great way to test something like this! Thanks a lot!
– Qqwy
Oct 14, 2013 at 21:20