Designing Filter Taps
This tutorial will demonstrate how to create a list of filter taps and apply them within a low pass filtering block. This tutorial makes use of the flowgraph developed in the previous tutorial, Low Pass Filter Example.
Designing the Filter Taps
Begin with the flowgraph from Low Pass Filter Example, but replace the Low Pass Filter with the Frequency Xlating Filter and drag in the Low-Pass Filter Taps block:
The Low-Pass Filter Taps block will design a set of filter taps that can be applied to filtering blocks. Filter taps may also be referred to as weights or coefficients. The response and performance of the filter is dependent on the parameters entered by the user. Double-click the Low-Pass Filter Taps block to open the properties. Edit the properties:
- Id: lowPassFilterTaps
- Cutoff Freq (Hz): samp_rate/4
- Transition Width (Hz): samp_rate/8
The Low-Pass Filter Taps block saves the filter taps as a tuple as variable lowPassFilterTaps. A tuple is a data type in Python that is like a list or array but is more flexible in that it can contain data of all different types. Tuples are represented by python by parenthesis, (item1, item2, item3). You can get more information on Python tuples here.
Double-click the Frequency Xlating FIR Filter block to edit the properties. Enter lowPassFilterTaps for Taps and leave all of the other parameters the same. Hovering over the lowPassFilterTaps variable will display information about the filter taps:
The first couple of filter taps are displayed in a tuple. Blocks in GNU Radio can accept data objects as parameters such as tuples, arrays and lists. In some instances, blocks require their parameters to be of a specific data type. Save the properties and run the flowgraph:
Mouse-click and select Max Hold, then slowly drag the frequency slider across all of the values. The magnitude of the frequency response can then be seen through the outline:
Entering Filter Taps Manually
Alternative methods can be used to design filter taps and then enter them manually as a Python variable. For example, the Frequency Xlating FIR Filter block will accept filter taps as a NumPy array. An import statement for NumPy is needed to be able to access it's functions and data types. Add the Import block to the GRC workspace:
Double-click the block and add the import statement:
import numpy as np
A simple moving-average filter, or boxcar, can be designed by setting all of filter taps to be the same. This can be done by using the NumPy ones() function which returns a NumPy array of all ones with a specified length. Create a variable named boxcarFilter with the Value being:
np.ones(8)/8
Right-click on Low-Pass Filter Taps and then Disable:
Then edit the properties of Frequency Xlating FIR Filter and replace lowPassTaps with boxcarFilter. The flowgraph will now look like the following:
Run the flowgraph, select Max Hold and then sweep the frequency slider. A different frequency response magnitude can be seen now that different filter taps are used:
Real to Complex Filter
Many of the filtering blocks have options to select combinations of real or complex data types for the input and output, as well as real or complex filter weights. This example will demonstrate one method of how to use complex filter weights to transform a real signal into a complex signal. Re-create the following flowgraph by deleting the boxcarFilter variable:
Double-click the Frequency Xlating FIR Filter block to edit the properties. Click the drop-down menu for Type and select Real->Complex(Complex Taps):
Enter bandPassTaps for Taps.