One zero, LP/HP

References : Posted by Bram
Notes :
LP is only 'valid' for cutoffs > samplerate/4
HP is only 'valid' for cutoffs < samplerate/4

Code :
theta = cutoff*2*pi / samplerate

LP:
H(z) = (1+p*z^(-1)) / (1+p)
out[i] = 1/(1+p) * in[i] + p/(1+p) * in[i-1];
p = (1-2*cos(theta)) - sqrt((1-2*cos(theta))^2 - 1)
Pi/2 < theta < Pi

HP:
H(z) = (1-p*z^(-1)) / (1+p)
out[i] = 1/(1+p) * in[i] - p/(1+p) * in[i-1];
p = (1+2*cos(theta)) - sqrt((1+2*cos(theta))^2 - 1)
0 < theta < Pi/2

Comments
from : newbie attack
comment : What is the implementation of z^(-1)?

from : spam[AT]hell[DOT]no
comment : z^(-1) = 1/z

from : cam
comment : z^(-1) is a single sample delay. The second line of code is the actual filter code. First line is a transfer function.

from : Gorgr
comment : wt's the meaning of 'p'?

from : chippo
comment : And what's the meaning of 'z'?