Nubeat7 wrote:i thought because because of this part at the end of the code:Code: Select all x2=x1; x1=in;
If you look more closely you see that
Code: Select all
y0=b0*x0+b1*x1+b2*x2-... //the output consists of all inputs ranging from the actual input and the previous ones
Filter is basically a code (or a circuit/rezonator) that adds inputs and outputs along with their previous versions in a way, that certain frequency elements get boosted/damped and delayed while others don't.
One very simple way to explain this is the way they were invented.
Led's say you have a digital signal (a sequence of values) that changes rapidly and you what it to have more stable values. So you say, let the output be 50% the input and 50% previous output. Logically that means you reduce the change between those to by 50%.
Code: Select all
b0=0.5;
a1=-0.5; //We use negative a1 that is later subtracted for a reason I can't really explain
y0=x0*b0-y1*a1;
y1=y0;
if you enter sequence
0 , 0.5 , 1 , 0.5 , 0*, -0.5 , -1 , -0.5 , 0
it will put out
0 , 0.25 , 0.625 , 0.4625 , 0.2312* , -0.01975...
As you can see the changes in signal are smaller, but also the signal is shifted in time ( in the first signal, the zero is crossed exactly at fifth sample - in output it is somewhere between 5fth and 6th closer to 6th )
In terms of frequency that means you leave DC (constant part of the signal) untouched and Nyquist frequency (instant rapid changes) reduced to 0.5. Slower Changes are reduced in smaller way, than fast ones - lower frequencies are passed, high frequencies are cut. You have just constructed a simple low-pass filter.
Much more smarter mathematicians then we are have taken this even further. They invented Fourier transform that let you analyze frequency response and phase shifts on signals and Z-transform to calculate A and B coefficients or filters for specific frequency and phase response desired.
I hope this little explanation helps...