If I were to implement low pass filters on an array of digital samples by the following code, where original
is the original array of data, and new
is the array of filtered data, and c
is a certain constant:
new[0] = original[0];
for(int i=1; i<original.length; i++){
new[i] = new[i-1] + c * (original[i] - new[i-1]);
}
Or a high pass filter with the third line replaced with:
new[i] = c * (new[i-1] + original[i] - original[i-1]);
What would be the relationship between c
and the cutoff frequency of each?
Both of the filters are single-pole Infinite Impulse Response (IIR) filters.
IIR filters have analogues in the continuous time domain (e.g. simple LC and RC circuits). Analysis usually starts with the desired transfer function
H(ω)
- using the z-tranform to covert to discrete-time. With a little re-arrangement will yield an equation which you can solve for your filter coefficients. [H(ω)
is -3dB at the cut-off frequency].This material is typically taught in the first and second undergraduate years of Electronic engineering degrees, so there will be loads of online, and free, courseware to be had. You'll need the accompanying pure mathematics courses.
Lots of practical filter designs turn out to be analytically insoluble (or at least difficult); a common way to proceed is solving numerically. MATLAB is the tool of choice for many. NI LabView also has a filter designer. Neither are cheap.
Single-pole filters are easy to solve. this may help. There are also various on-line filter solvers if you want to design more complex - or higher order - filters.