One pole LP and HP

References : Posted by Bram
Code :
LP:
recursion: tmp = (1-p)*in + p*tmp with output = tmp
coefficient: p = (2-cos(x)) - sqrt((2-cos(x))^2 - 1) with x = 2*pi*cutoff/samplerate
coeficient approximation: p = (1 - 2*cutoff/samplerate)^2

HP:
recursion: tmp = (p-1)*in - p*tmp with output = tmp
coefficient: p = (2+cos(x)) - sqrt((2+cos(x))^2 - 1) with x = 2*pi*cutoff/samplerate
coeficient approximation: p = (2*cutoff/samplerate)^2

Comments
from : skyphos_atw[AT]hotmail[DOT]com
comment : coefficient: p = (2-cos(x)) - sqrt((2-cos(x))^2 - 1) with x = 2*pi*cutoff/samplerate p is always -1 using the formula above. The square eliminates the squareroot and (2-cos(x)) - (2-cos(x)) is 0.

from : q[AT]q
comment : Look again. The -1 is inside the sqrt.

from : batlord[[DOT]A[DOT]T[DOT]]o2[[DOT]D[DOT]O[DOT]T[DOT]]pl
comment : skyphos: sqrt((2-cos(x))^2 - 1) doesn't equal sqrt((2-cos(x))^2) + sqrt(- 1) so -1 can be inside the sqrt, because (2-cos(x))^2 will be always >= one.

from : No
comment : HP is wrong! Or at least it does not work here. It acts like a lofi low-shelf. However this works: HP: recursion: tmp = (1-p)*in + p*tmp with output = in-tmp coefficient: p = (2-cos(x)) - sqrt((2-cos(x))^2 - 1) with x = 2*pi*cutoff/samplerate coeficient approximation: p = (1 - 2*cutoff/samplerate)^2