Signal filtering is an integral part of signal processing. In this tutorial we will design a finite impulse response low pass filter that will filter an input signal of our choosing.
Finite Impulse Response (FIR) and Infinite Impulse Response (IIR) filters are the two main digital filters used in digital signal processing (DSP). FIR filters differ from IIR filters because they have an impulse response of a finite duration. They are primarily used for tapping of high-orders since IIR filters may become unstable.
A low-pass filter is a filter that passes signals with a frequency lower than the selected cutoff frequency. It will attenuate signals with frequencies higher than the cutoff frequency. A low-pass filter is the complement of a high pass filter which lets signals with high frequencies pass.
\begin{array} {|l|l|} \hline Advantages & Disadvantages \\ \hline \text{Always stable} & \text{Require complex computation} \\ \hline \text{Simple to design} & \text{Hard to implement} \\ \hline \text{Easy to optimize} & \text{Can be expensive} \\ \hline \text{Have a linear phase response} & \text{Time consuming to design} \\ \hline \end{array}
We will begin our filter design in Collimator's model editor. First we define the model as shown below:
The model blocks parameters are described in the table below.
\begin{array} {|l|l|} \hline \text{Block Name} & \text{Block Type} & \text{Block Units} & \text{Block Description} \\ \hline \text{PureSignal} & \text{Sine wave block} & \text{Frequency: }10& \text{The target signal} \\ \hline \text{Noise} & \text{Sine wave block}& \text{Frequency: }200& \text{Noise} \\ \hline \text{Noise2} & \text{Sine wave block}& \text{Frequency: }100& \text{Noise} \\ \hline \text{Noise3} & \text{Sine wave block}& \text{Frequency: }250& \text{Noise} \\ \hline \text{Noise4} & \text{Sine wave block}& \text{Frequency: }300& \text{More Noise} \\ \hline \text{NoisySignal} & \text{Adder block}& \text{n/a} & \text{Combines sgnals} \\ \hline \text{Signal} & \text{Quantizer block} & \text{interval: }0.1& \text{Quantizes the signal } \\ \hline \text{FilteredSignal} & \text{Filter discrete block}& \text{Filter type: FIR}& \text{Incorrect B coefficients} \\ \hline \end{array}
In order to ensure our model works we must specify our end time which will correspond to the duration of our signals and our global discrete clock tick whose inverse will correspond to our signal's sample rate.
In order to solve for the correct filter coefficients to apply to our filter block we will need to use a Collimator notebook. Using Scipy, Numpy and Matplotlib, we will run calculations to solve for the coefficients.
We begin by importing the libraries we will use:
Next we call our model and run it in order to obtain the noisy input signal and assign it to a numpy array
Now we create a visualization of the frequency response of our noisy input signal
Now we begin designing our filter. The cutoff frequency of our filter will be 10Hz. As a result the output signal should be the same as our original source signal.
Now we plot the filter's frequency response in order to ensure it is a low pass filter
Lastly we call our filters coefficients that we assigned to the taps variable.
We copy and paste our taps onto the B coefficients of our Filtered Signal block and after running our simulation we see that the filter works. Below is a full video tutorial.