LP/HP filter theory for beginners?

DSP, Plugin and Host development discussion.
RELATED
PRODUCTS

Post

Hello!
I've just started writing my own vst-plugins and I found two (one pole?) filter algoritms somewhere on the web. It's a highpass and a lowpass filter and they seem to work fine.

My question is; why? I want to know how this really works! Can anyone explain some basic filtering theory or do you know any good websites in the subject? There are a lot of dsp-websites out there but I can't find one that can explain this in a good way for dummies, with concrete examples.

Highpass:

Code: Select all

	w = 2 * SamplingRate;
	Cutoff *= 2 * PI;
	Norm = 1 / (Cutoff + w);
	a0 = (w * Norm);
	a1 = -a0;
	b1 = (w - Cutoff) * Norm;
Lowpass:

Code: Select all

	w = 2 * SamplingRate;
	Cutoff *= 2 * PI;
	Norm = 1 / (Cutoff + w);
	b1 = (w - Cutoff) * Norm;
	a0 = a1 = Cutoff * Norm;
...where both of them are applied like

Code: Select all

out[n] = in[n]*a0 + in[n-1]*a1 + out[n-1]*b1
Thanks in advance!
/Henke :wink:

Post

http://ccrma.stanford.edu/~jos/filters/
This is quite maths heavy, but an excellent resource

http://www.dspguide.com/
A whole book on dsp!

http://members.tripod.com/~theover/filter.html
a bit of background

http://www.netrino.com/Publications/Glo ... lters.html
Some more info about filters

You can also find loads of resources by googling for
Digital filter theory
Digital filter analysis
Digital filters
etc etc

Hope some of that helps
Paul
__________________________
Paul Chana
Senior Software Engineer
FXpansion Audio UK Ltd

Post

My filter knowledge isn't amazing, but on the simplest level, filters are basically constructive / destructive interferance.

Say, for example, you have a waveform that is exactly half the sampling rate. If you apply a 1-sample, 1-shot delay, then you will completely cancel out the waveform:

Code: Select all

1010101010... (original)+
0101010101... (original, delayed by 1 sample)
=
1111111111... (output) 
You'll notice that you get a bit of a DC offset going on there (twice the DC offset that was in the original), and also that the high frequency has been completely cancelled out.

If you actually plot the frequency response of this filter, you'll notice that it is a pretty crap one, but the frequency response does follow a smooth curve.

You can design better filters by adding more single-shot delays, and / or by adding feedback delays, with different multipliers on them.
Typically filters that only consist of these 'one shot' delays are FIR filters (Finite Impulse Response). If you have per-sample delays with feedback, then they are IIR (Infinite Impulse Response). The latter is coined 'infinite', because potentially if you inject some noise into it and the feedback is very high then it can end up emitting sound (or DC) forever.

Post

texture wrote:
[snip]

Typically filters that only consist of these 'one shot' delays are FIR filters (Finite Impulse Response). If you have per-sample delays with feedback, then they are IIR (Infinite Impulse Response). The latter is coined 'infinite', because potentially if you inject some noise into it and the feedback is very high then it can end up emitting sound (or DC) forever.
It does not matter if the feedback is high, if there is any feedback at all, the filter will have a non-zero output forever. Regard the simplest "computer implementation" of a first order lowpas FIR filter:
out = input * cutoff + lastOut * (1 - cutoff)
Where cutoff is between 0 and 1. If cutoff is not zero, and you once put in a non-zero value as input, the output will never reach zero (if the resolution is infinite that is, which it never is. but still...).

Basicly you can construct a very simple lowpass filter like that, and you can also construct a highpass filter by subtracting the lowpassed signal from the original signal. But this is nothing I'd call a fancy filter, but it might be a good starting point. To understand the filter, try calculating some stuff on a paper. For instance:
let out = 0.0
let in = 1.0
and then iterate this a few times
lastOut = out
out = in * 0.5 + lastOut * 0.5 (cutoff = 0.5 in this example)
write down the value of out and go back to "lastOut = out"

You'll get:
out = 0.5
out = 0.75
out = 0.875
out = 0.9375

And so on. It will go towards 1.0, but it will never reach 1.0.
Stefan H Singer
Musician, coder and co-founder of We made you look Web agency

Post

It was my impression that lp and hp filters are simply a load comb filters use to induce phase cancelation. I may be way off the mark hear, just having vague recollections of my dsp for audio lectures :D ! If i remember correctly, isnt the only difference between the lp and hp algorithms whether or not the delay buffer is added or subtracted to the original signal?

My head hurts :oops:

Post

To really understand what filters do, and how they work, you really have to know the concepts of the Fourier Transform and the z-transform. The frequency responses arise from the presence of poles and zeros in the z-plane. A pole is a place where the response jumps to infinity, a zero, naturally, where the response dips to zero. So now envision a plane, that we will call the z-plane. Our major concern within the z-plane is the region corresponding to the Fourier transfrom. i.e. the unit circle (circle of radius 1 in the z-plane). This unit circle is the "train tracks" we follow through frequency to determine the frequency response. As we approach the vicinity of poles, we go up hill. Near zeros we go down hill. If a pole lies on the traintracks, we will blow up to infinity there. This is a no no, and an unstable filter.

take for example a filter whose difference equation is:

y[n] = x[n] + x[n-1]

(the current output = current input + input one sample ago)

the Fourier Transform of the above is:
Y(w) = X(w) + exp(-jw)X(w)

Therefore the transfer function/response of the filter Y(w)/X(w) = H(w) is:

H(w) = 1+exp(-jw)

so at w=0, i.e. zero radian frequency (DC) the magnitude response |H(w)| = 2. At w=pi, which is your half sample rate |H(w)| = 0. Therefore, this is a low pass filter. More specifically, it is an order 1 lowpass filter with a zero on the z-plane at -1.

So when out train started it's journey, it was far away from this "valley"... As we started approaching the higher frequencies, we approached closer and closer until we completely hit the valley and went to zero.

The example I showed is what we call a Finite Impulse Response filter. It contains no poles. It is only a function of past (or future if the filter is noncausal) INPUT samples. Poles arise when we use recursion, i.e. past OUTPUT samples in the difference equation. This leads to infinite impulse response filters, and poles.

If you want me to go on.. I could, but this is a basic jist of what you'll have to deal with to get what's going on.

Peoples intuitions are right, it basically amounts to phase cancellations...

Post

Ecko wrote:To really understand what filters do, and how they work, you really have to know the concepts of the Fourier Transform and the z-transform. The frequency responses arise from the presence of poles and zeros in the z-plane. A pole is a place where the response jumps to infinity, a zero, naturally, where the response dips to zero. So now envision a plane, that we will call the z-plane. Our major concern within the z-plane is the region corresponding to the Fourier transfrom. i.e. the unit circle (circle of radius 1 in the z-plane). This unit circle is the "train tracks" we follow through frequency to determine the frequency response. As we approach the vicinity of poles, we go up hill. Near zeros we go down hill. If a pole lies on the traintracks, we will blow up to infinity there. This is a no no, and an unstable filter.

take for example a filter whose difference equation is:

y[n] = x[n] + x[n-1]

(the current output = current input + input one sample ago)

the Fourier Transform of the above is:
Y(w) = X(w) + exp(-jw)X(w)

Therefore the transfer function/response of the filter Y(w)/X(w) = H(w) is:

H(w) = 1+exp(-jw)

so at w=0, i.e. zero radian frequency (DC) the magnitude response |H(w)| = 2. At w=pi, which is your half sample rate |H(w)| = 0. Therefore, this is a low pass filter. More specifically, it is an order 1 lowpass filter with a zero on the z-plane at -1.

So when out train started it's journey, it was far away from this "valley"... As we started approaching the higher frequencies, we approached closer and closer until we completely hit the valley and went to zero.

The example I showed is what we call a Finite Impulse Response filter. It contains no poles. It is only a function of past (or future if the filter is noncausal) INPUT samples. Poles arise when we use recursion, i.e. past OUTPUT samples in the difference equation. This leads to infinite impulse response filters, and poles.

If you want me to go on.. I could, but this is a basic jist of what you'll have to deal with to get what's going on.

Peoples intuitions are right, it basically amounts to phase cancellations...
Holy crap on a stick! :-o

I'm sticking with synthedit i think :lol:

Post

i know you guys prolly enjoy writing this stuf as much as i enjoy reading it :p but just saying thanks - i think my teachers collectively decided that i *shouldn't* learn math so tech docs are usually lots of wading for me.. ~ glad i didn't learn it in an institutional setting after all..

can't really implement the single sample feedback in synthedit, but well enough to see the effect. super appreciate these little jogs..
you come and go, you come and go. amitabha neither a follower nor a leader be tagore "where roads are made i lose my way" where there is certainty, consideration is absent.

Post

Ecko, I must add my thanks. You have put into fairly simple terms a complicated process, but without dumbing down the math.

I have read a whole load of articles explaining the same thing, but none so succinctly as the way you have expressed it, I have a much better understanding now WHY those equations that I have taken for granted work.

You say you could go on: the floor is yours...

:)

DSP
Image

Post

duncanparsons wrote:Ecko, I must add my thanks. You have put into fairly simple terms a complicated process, but without dumbing down the math.

I have read a whole load of articles explaining the same thing, but none so succinctly as the way you have expressed it, I have a much better understanding now WHY those equations that I have taken for granted work.

You say you could go on: the floor is yours...

:)

DSP
ditto that :)

Post

Yep, big praise to Ecko also from here. Few people have the ability to explain scientific topics easily understandable and find good analogies. There are enough books about the maths, but I guess much more people COULD understand it if simple explanations were more available. Once you understand the concept, it also becomes much easier to understand the maths.

Post

I found this neat little vst plug-in

http://jaha.smartelectronix.com/

shows beatifully the z-plane and the pole-zero locations.. as well as a 3d plot that shows nicely the hill/valley interpretation... you can move the poles and zeros around and look what happens to the response.

Post

Thats pretty cool

Post

Ecko: Thanks a lot for that! It took some time for me to understand you completely but eventually i think i got it! Please continue if you want to/have time :)

Post

By the way... Theoretically, it must be possible to make many different filter-types out of a lowpass...
For example, to make a highpass, can i just subtract a lowpass-filtered copy of the signal from the original signal? Can I make a bandpass by highpass-filtering a lowpass-filtered signal?

And so on...

Post Reply

Return to “DSP and Plugin Development”