Designing Filter Taps

From GNU Radio
Revision as of 12:37, 20 January 2023 by Delta512 (talk | contribs) (added more specific instructions to keep the tutorial style consistent)
Jump to navigation Jump to search
Beginner Tutorials

Introducing GNU Radio

  1. What is GNU Radio?
  2. Installing GNU Radio
  3. Your First Flowgraph

Flowgraph Fundamentals

  1. Python Variables in GRC
  2. Variables in Flowgraphs
  3. Runtime Updating Variables
  4. Signal Data Types
  5. Converting Data Types
  6. Packing Bits
  7. Streams and Vectors
  8. Hier Blocks and Parameters

Creating and Modifying Python Blocks

  1. Creating Your First Block
  2. Python Block With Vectors
  3. Python Block Message Passing
  4. Python Block Tags

DSP Blocks

  1. Low Pass Filter Example
  2. Designing Filter Taps
  3. Sample Rate Change
  4. Frequency Shifting
  5. Reading and Writing Binary Files

SDR Hardware

  1. RTL-SDR FM Receiver
  2. B200-B205mini FM Receiver

This tutorial demonstrates how to create a list or array 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, so please complete it before continuing. The next tutorial, Sample Rate Change, describes how to perform sample rate change in GNU Radio.

Designing the Filter Taps

Begin with the flowgraph from Low Pass Filter Example but replace the Low Pass Filter with a Frequency Xlating FIR Filter and drag in the Low-Pass Filter Taps block:


FlowgraphFrequencyXlatingFilterStart.png


The Low-Pass Filter Taps block designs 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

LowPassFilterTapsProperties.png

The Low-Pass Filter Taps block saves the filter taps in a list within the lowPassFilterTaps variable.

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 displays information about the filter taps:

LowPassFilterTapsTuple.png


The first couple of filter taps are displayed in a list. Block parameters in GNU Radio accept data objects 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:

LowPassFilterTapsFreqSink.png


Scroll-wheel-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:

LowPassFilterTapsMaxHold.png

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 accepts filter taps as a NumPy array. To be able to access NumPy's functions and data types, it needs to be imported first. Add the Import block to the GRC workspace:

AddImportBlock.png


Double-click the block and add the import statement:

import numpy as np

ImportProperties.png


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

BoxcarFilterTaps.png


Right-click on Low-Pass Filter Taps and then Disable:

DisableLowPassFilterTaps.png


Then edit the properties of Frequency Xlating FIR Filter and replace lowPassTaps with boxcarFilter. The flowgraph looks like the following:

UpdateXlatingFilterTaps.png


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:

BoxcarFilterMaxHold.png


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 demonstrates 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 and enabling again the lowPassTaps one:

DeleteBoxcarFilterVariable.png

The lowPassTaps are used as the basis for a complex band-pass filter. Create a variable n with the Value

np.arange(0,len(lowPassTaps))

which produces an array of integers: 0, 1, 2, 3, ... up to the length of lowPassTaps:

NVariable.png

Create the frequencyShift variable with Value:

np.exp(2j*np.pi*0.25*n)

FrequencyShiftVariable.png

which is a complex sinusoid with a frequency of 1/4th the sampling rate. The frequencyShift variable changes the center frequency of lowPassTaps from 0 to 1/4th the sampling rate. Create a variable bandPassTaps with value:

lowPassTaps*frequencyShift

BandPassTapsVariable.png


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):

SelectRealInputComplexOutput.png


Replace lowPassTaps with bandPassTaps in the Frequency Xlating Filter.

Edit the properties of the Signal Source and convert it to a real signal.

RealSignalSource.png

The flowgraph looks like:

RealToComplexFlowgraph.png

Run the flowgraph, turn on Max Hold, and sweep the frequency variable:


RealToComplexMaxHold.png

The magnitude of the frequency response shows the center frequency of the low-pass filter has been moved up to 1/4th the sampling rate, which is now a band-pass filter. The frequency response is now different between the positive and negative frequencies, which can be a property of complex filters (but not real filters).

The next tutorial, Sample Rate Change, describes how to perform sample rate change in GNU Radio.