Sample Rate Change: Difference between revisions

From GNU Radio
Jump to navigation Jump to search
No edit summary
(linking against new tutorial)
 
(7 intermediate revisions by 5 users not shown)
Line 4: Line 4:
This tutorial describes how to implement sample rate change within GNU Radio.
This tutorial describes how to implement sample rate change within GNU Radio.


The previous tutorial, [[Designing_Filter_Taps|Designing Filter Taps]], demonstrates how to design filter taps and use them in signal processing blocks. Please complete the [[Designing_Filter_Taps|Designing Filter Taps]] tutorial before completing this one.
The previous tutorial, [[Designing_Filter_Taps|Designing Filter Taps]], demonstrates how to design filter taps and use them in signal processing blocks. Please complete the [[Designing_Filter_Taps|Designing Filter Taps]] tutorial before completing this one. The next tutorial, [[Frequency_Shifting|Frequency Shifting]], describes how to apply a frequency shift to a signal both mathematically and with DSP blocks.


== Interpolation ==
== Interpolation ==
Interpolation is the process of increasing the sampling rate and thus the available bandwidth. This example will demonstrate how to increase the sampling rate using the ''Interpolating FIR Filter'' block.
Interpolation is the process of increasing the sampling rate and thus the available bandwidth. This example demonstrates how to increase the sampling rate using the ''Interpolating FIR Filter'' block.


Start by adding the following blocks to the flowgraph and connect them:
Start by adding the following blocks to the flowgraph and connect them:
Line 17: Line 17:
# ''Interpolating FIR Filter''
# ''Interpolating FIR Filter''
# ''Throttle''
# ''Throttle''
# ''QT Frequency GUI Sink''
# ''QT GUI Frequency Sink''


[[File:InterpolationFlowgraphStart.png|700px]]
[[File:InterpolationFlowgraphStart.png|700px]]
Line 28: Line 28:
Edit the second of the two new variable blocks:
Edit the second of the two new variable blocks:
* Id: ''samp_rate_interpolated''
* Id: ''samp_rate_interpolated''
* Value: ''samp_rate*interpolation_rate"
* Value: ''samp_rate*interpolation_rate''


Edit the properties of the ''Low-Pass Filter Taps'' block:
Edit the properties of the ''Low-Pass Filter Taps'' block:
Line 55: Line 55:




The ''Interpolating FIR Filter'' will increase the sampling rate from 32 kHz to 128 kHz, a factor of 4 due to the ''interpolation_rate'' variable. Make a note of this by editing the ''Comment'' field under the ''Advanced'' tab:
The ''Interpolating FIR Filter'' increases the sampling rate from 32 kHz to 128 kHz, a factor of 4 due to the ''interpolation_rate'' variable. Make a note of this by editing the ''Comment'' field under the ''Advanced'' tab:


[[File:AddCommentToBlock.png|500px]]
[[File:AddCommentToBlock.png|500px]]
Line 71: Line 71:
* Bandwidth (Hz): ''samp_rate_interpolated''
* Bandwidth (Hz): ''samp_rate_interpolated''


The flowgraph should now look like the following:
The flowgraph looks like the following:


[[File:InterpolationFinalFlowgraph.png|700px]]
[[File:InterpolationFinalFlowgraph.png|700px]]




Running the flowgraph will show the following ''QT GUI Frequency Sink'':
Running the flowgraph shows the following ''QT GUI Frequency Sink'':


[[File:RunInterpolationFlowgraph.png|500px]]
[[File:RunInterpolationFlowgraph.png|500px]]
Line 90: Line 90:
[[File:InterpolationMaxHoldOutline.png|500px]]
[[File:InterpolationMaxHoldOutline.png|500px]]


== Decimation ==
== Decimation (Source hardware example) ==


Where interpolation increases the sample rate, decimation decreases the sample rate and available bandwidth. Starting with the flowgraph from the previous ''Interpolation'' example, rename the ''interpolation_rate'' variable to ''decimation_rate''. The flowgraph will now have some errors:
Where interpolation increases the sample rate, decimation decreases the sample rate and available bandwidth.


[[File:ChangeDecimationRateVariable.png|700px]]
The following discussion is based on the flowgraph of a RadioTeleTYpe (RTTY) receiver. It can be found at [https://raw.githubusercontent.com/duggabe/gr-RTTY-basics/master/RTTY_rcv/RTTY_receive.grc RTTY_receive.grc]


[[File:RTTY_rcv.png|800px]]


Change the ''samp_rate_interpolated'' variable:
Frequency shift keying (FSK) tones are input to the microphone jack of the computer which has a sample rate of 48 kHz. That data is fed to a [[Frequency Xlating FIR Filter]] which shifts the tones above and below the center frequency. It also decimates (divides) the sample rate by 50, producing an output sample rate of 960.
* Id: ''samp_rate_decimated''
* Value: ''samp_rate*decimation_rate''


Change the ''Low-Pass Filter Taps'' block properties:
The [[Quadrature Demod]] produces a signal which is positive or negative depending on whether the tone is above or below the center frequency.
* Sample Rate (Hz): ''samp_rate''
* Cutoff Frequency (Hz): ''samp_rate/(decimation_rate*2)''
* Transition Width (Hz): ''samp_rate/(decimation_rate*4)''


Replace the ''Interpolating FIR Filter'' block with the ''Decimating FIR Filter'' block. Update the properties:
The RTTY symbol time is, by definition, exactly 22 ms. yielding the familiar 45 baud (1/0.022 rounded). To get an integer number of samples per symbol, a sample rate of 500 was chosen, producing 11 samples per symbol time. (500 samples/sec * 0.022 seconds = 11 samples).
* Decimation: ''decimation_rate''
* Taps: ''lowPassTaps''
 
Update the properties for the ''Throttle'' block:
* Sample Rate: ''samp_rate_decimated''
 
Update the properties for the ''QT GUI Frequency Sink'' block:
* Bandwidth (Hz): ''samp_rate_decimated''
 
The flowgraph will now look like the following:
 
[[File:DecimationFlowgraph.png|700px]]
 
 
Run the flowgraph and enable ''Max Hold''. Sweeping the frequency slider across positive frequencies will show the spectral shape of the ''Decimating FIR Filter'':
 
[[File:DecimationMaxHold.png|700px]]
 
 
Note that the bandwidth has been reduced by a factor of 1/4 due to the ''Decimating FIR Filter'' block.
 
== Rational Rate Resampling ==
 
The ''Interpolating FIR Filter'' and ''Decimating FIR Filter'' both change the sample rate by integer values. Situations can arise in which the sample rate needs to be changed by a fractional number such as 2/3. One way to perform a fractional resample is to apply the interpolation by 2 followed by the decimation by 3. A better way is to use the ''Rational Resampler'' block.
 
Starting with the flowgraph from the ''Decimation'' example, replace the ''Decimating FIR Filter'' with the ''Rational Resampler''.
 
Add a ''variable'' block for the interpolation rate:
* Id: ''interpolation_rate''
* Value: ''2''
 
Change the value for the ''decimation_rate'' variable:
* Value: ''3''
 
Change the properties for the ''samp_rate_decimated'' variable:
* Id: ''samp_rate_resampled''
* Value: ''samp_rate*interpolation_rate/decimation_rate''
 
The cutoff-frequency needs to be the minimum between ''samp_rate/(interpolation_rate*2)'' and ''samp_rate/(decimation_rate*2)''. Since ''decimation_rate'' > ''interpolation_rate'', the ''Low-Pass Filter Taps'' block already has correct sample rate, cutoff-frequency and transition bandwidth and therefore does not need to be modified.
 
Change the ''Sample Rate'' property for ''Throttle'':
* Sample Rate: ''samp_rate_resampled''
 
Change the ''Bandwidth'' property for ''QT GUI Frequency Sink'':
* Bandwidth (Hz): ''samp_rate_resampled''
 
Update the properties for the ''Rational Resampler'' block:
* Interpolation: ''interpolation_rate''
* Decimation: ''decimation_rate''
* Taps: ''lowPassTaps''
 
The flowgraph will now look like the following:
 
[[File:RationalResamplerFlowgraph.png|700px]]


The output of the Quadrature Demod block has a sample rate of 960; the desired sample rate is 500. The [[Rational Resampler]] interpolates (multiplies) the sample rate by 500 and decimates (divides) it by 960 to produce an output sample rate of 500.


Run the flowgraph and select the ''Max Hold'' option. Sweeping the frequency slider over the positive frequencies shows the resampled spectrum:
The [[Binary Slicer]] produces an output of +1 for inputs greater than zero, and 0 for inputs less than zero.


[[File:RationalResamplerMaxHold.png|700px]]
The 'Terminal Display Sink' is an [[Embedded Python Block]] which reads the input stream of 1's and 0's, synchronizes on the start bit, creates a Baudot character from the five data bits, converts Baudot to UTF-8, and outputs the characters to a [[ZMQ PUSH Message Sink]].


The [https://github.com/duggabe/ gr-webserver] package can receive the messages from the message sink and display them on a browser screen.


Note that the bandwidth in this case has been reduced by a factor of 2/3 due to the ''Rational Resampler'' block.
The next tutorial, [[Frequency_Shifting|Frequency Shifting]], describes how to apply a frequency shift to a signal both mathematically and with DSP blocks.

Latest revision as of 22:16, 12 June 2024

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 describes how to implement sample rate change within GNU Radio.

The previous tutorial, Designing Filter Taps, demonstrates how to design filter taps and use them in signal processing blocks. Please complete the Designing Filter Taps tutorial before completing this one. The next tutorial, Frequency Shifting, describes how to apply a frequency shift to a signal both mathematically and with DSP blocks.

Interpolation

Interpolation is the process of increasing the sampling rate and thus the available bandwidth. This example demonstrates how to increase the sampling rate using the Interpolating FIR Filter block.

Start by adding the following blocks to the flowgraph and connect them:

  1. Two Variable blocks
  2. Low-Pass Filter Taps
  3. QT GUI Range
  4. Signal Source
  5. Interpolating FIR Filter
  6. Throttle
  7. QT GUI Frequency Sink

InterpolationFlowgraphStart.png


Edit the first of the two new variable blocks:

  • Id: interpolation_rate
  • Value: 4

Edit the second of the two new variable blocks:

  • Id: samp_rate_interpolated
  • Value: samp_rate*interpolation_rate

Edit the properties of the Low-Pass Filter Taps block:

  • Id: lowPassTaps
  • Sample Rate (Hz): samp_rate_interpolated
  • Cutoff Freq (Hz): samp_rate_interpolated/(interpolation_rate*2)
  • Transition Width (Hz): samp_rate_interpolated/(interpolation_rate*4)

EditLowPassTapsProperties.png


Edit the properties of the QT GUI Range block:

  • Id: frequency
  • Default Value: 0
  • Start: -samp_rate/2
  • Stop: samp_rate/2

Edit the property of the Signal Source:

  • Frequency: frequency

Edit the properties of the Interpolating FIR Filter block:

  • Interpolation: interpolation_rate
  • Taps: lowPassTaps

InterpolatingFIRFilterProperties.png


The Interpolating FIR Filter increases the sampling rate from 32 kHz to 128 kHz, a factor of 4 due to the interpolation_rate variable. Make a note of this by editing the Comment field under the Advanced tab:

AddCommentToBlock.png


The comment is then displayed as a visual reminder in GRC:

SampleRateBlockComment.png


Edit the Throttle property:

  • Sample Rate: samp_rate_interpolated

Edit the QT GUI Frequency Sink property:

  • Bandwidth (Hz): samp_rate_interpolated

The flowgraph looks like the following:

InterpolationFinalFlowgraph.png


Running the flowgraph shows the following QT GUI Frequency Sink:

RunInterpolationFlowgraph.png


The four peaks come from the interpolation operation. Scroll-wheel-click on the window and enable Max Hold:

InterpolationClickMaxHold.png


Drag the frequency slider to show how the four peaks change in frequency, creating an outline of the frequency response of the Interpolating FIR Filter block. The interpolation has increased the sampling rate by a factor of 4, with the low-pass filter taps attenuating the spectral images to minimize distortion.

InterpolationMaxHoldOutline.png

Decimation (Source hardware example)

Where interpolation increases the sample rate, decimation decreases the sample rate and available bandwidth.

The following discussion is based on the flowgraph of a RadioTeleTYpe (RTTY) receiver. It can be found at RTTY_receive.grc

RTTY rcv.png

Frequency shift keying (FSK) tones are input to the microphone jack of the computer which has a sample rate of 48 kHz. That data is fed to a Frequency Xlating FIR Filter which shifts the tones above and below the center frequency. It also decimates (divides) the sample rate by 50, producing an output sample rate of 960.

The Quadrature Demod produces a signal which is positive or negative depending on whether the tone is above or below the center frequency.

The RTTY symbol time is, by definition, exactly 22 ms. yielding the familiar 45 baud (1/0.022 rounded). To get an integer number of samples per symbol, a sample rate of 500 was chosen, producing 11 samples per symbol time. (500 samples/sec * 0.022 seconds = 11 samples).

The output of the Quadrature Demod block has a sample rate of 960; the desired sample rate is 500. The Rational Resampler interpolates (multiplies) the sample rate by 500 and decimates (divides) it by 960 to produce an output sample rate of 500.

The Binary Slicer produces an output of +1 for inputs greater than zero, and 0 for inputs less than zero.

The 'Terminal Display Sink' is an Embedded Python Block which reads the input stream of 1's and 0's, synchronizes on the start bit, creates a Baudot character from the five data bits, converts Baudot to UTF-8, and outputs the characters to a ZMQ PUSH Message Sink.

The gr-webserver package can receive the messages from the message sink and display them on a browser screen.

The next tutorial, Frequency Shifting, describes how to apply a frequency shift to a signal both mathematically and with DSP blocks.