GitHub pages HackRF Wiki
The software used to control the HackRF is called GNU Radio Companion. This tutorial run this on Windows. If you decide to use Pentoo, do NOT use a virtual machine.
Plug in the HackRF to your host computer, you should see the LEDs on the side of the device illuminate. This indicates that the HackRF is getting power.
When opening the GNU Radio Companion for the first time, you should get something that looks like this:
The way that you can interact with blocks is by double-clicking them. Double-click on the Generate Options block in the top left corner and change the property from QT GUI to WX GUI.
We first want to create a source block which tells the HackRF to receive signals. This can be done by creating a block called osmocom Source. This block can be found at (no module specified)->Sources->osmocom Source.
We can create a GUI that allows us to see the FFT of the signals that are coming in from the RF. Create a WX GUI FFT Sink block that can be found at Core->Instrumentation->WX->WX GUI FFT Sink.
Connect the output of the osmocom Source to the input of the WX GUI FFT Sink.
We now want to modify some of the properties of the osmocom Source. We can change the global sampling rate to 10 MHz by changing the property samp_rate to 10e6. We can change the hardware frequency that it will tune to by changing the property Ch0: Frequency (Hz) to whichever radio station you want to tune to (102.7e6). Change the RF Gain (dB) to 0. Your properties should look as follows:
Modify the property Average to On in the WX GUI FFT Sink block. This will smooth the graph out. The properties should look like:
Generate the flow to check for errors using F5 and then execute the flow using F6. A window showing the FFT should pop up. Notice that the graph is centered around 0 MHz, we can change this to reflect the frequency it is tuned to.
Kill the foreground window using F7.
We can create a variable by creating a variable block which is found at Core->Variables->Variable. Name the variable center_freq and give it the value that you tuned to (102.7e6). We can now change the property Ch0: Frequency (Hz) in osmocom Source to center_freq. We can also change the property Baseband Freq in WX GUI FFT Sink to center_freq. The flow should reflect these changes.
Understand that we’ve only simply tuned the radio by tuning the hardware in the HackRF. However, often times the strength of a software radio is being able to “tune” the radio using software. Recall from signals that we can use sinusoidal signals to manipulate the signal that we are receiving from the HackRF to get tune to a particular frequency, completely in software.
We can generate a cosine value by creating a Signal Source block found at Core->Waveform Generators ->Signal Source. We know that if we multiply the signal receive from the HackRF by our generated cosine sinusoid, we will shift the HackRF signal by the frequency of the generated source.
Create a new variable (by creating a variable block) called channel_freq. Set this value to a frequency you want to tune into (104.3e6). Now set the property Frequency in the Signal Source block to center_freq - channel_freq. It is important to not that we can use Python as property values.
Create a multipication block found at Core->Math Operators->Multiply. Connect the output of osmocom Source to the first input of Multiply. Connect the output of Signal Source to the second input of Multiply.
To verify that this has worked, create a copy of WX GUI FFT Sink by copying and pasting and have the output of the Multiply block connect to the input of this new block that was just created. Change the property Baseband Freq to channel_freq as this new FFT should be tuned accordingly. Run to confirm:
In order to hear the signal that we’ve been tuning into, we need to demodulate this. We first can pass this through a Low Pass Filter which can be found at Core->Filters->Low Pass Filter. Connect the output of the Multiply block to the input of the Low Pass Filter.
Create another variable (by creating a block) and name it channel_width. Set this value to 200e3.
Set the properties of the Low Pass Filter as follows:
Cutoff Freq: 75e3, Transition Width: 25e3, Decimation: int(samp_rate/channel_width)
Notice that we can use a Python statement again to force the float into an int, the reason being is that this particular block can only decimate by an integer. Decimation reduces the sample rate, so we will get 200e3 samples per second out of the LPF.
We can circumvent the issue of an integer only decimation by using a Rational Resampler which can be found at Core->Resamplers->Rational Resampler. Set the Interpolation to 12 and the Decimation to 5. This allows us to decimate by 12/5. Connect the output of the Low Pass Filter to the input of the Rational Resampler.
We now need a WBFM Receiver (Wide Band Frequency Modulation) found at Core->Modulators->WBFM Receive. Set the Quadrature Rate (input frequency) to 480e3 and Audio Decimation to 10. This should give us a final sample rate of 48e3 which most sound cards support.
Create an Audio Sink found at Core->Audio->Audio Sink. Set the sample_rate to 48kHz. Connect the output of WBFM Receive to the input of Audio Sink.
Your flow should look something similar to this:
Run this flow and make sure your volume is up, you should be hearing audio.
You can play with the channel_freq variable in order to use software to “tune” into different frequencies without changing the frequency that the hardware is tuned to. A combination that I found that works well is center_freq: 91e6, channel_freq: 94.7e6, sample_rate: 20e6).
We currently have no way to adjust the volume of the incoming HackRF signal (besides changing the volume slider on your computer). This can be accomplished by multipling the amplitude of the signal by a constant value. This is done using a Multiply Const block found at Core->Math Operators->Multiply Const.
Delete the connection between WBFM Receive and Audio Sink and place the Multiply Const block between them. Connect the output from WBFM Receive to the input of Multiply Const and the output of Multiply Const to Audio Sink. Change the property IO Type to Float in the Multiply Const block.
We can the augment the GUI of the window that pops up by inserting a slider. This is done by Core-> GUI Widgets->WX->WX GUI Slider. This will give us a simple way to change the Constant property of Multiply Const. Change the ID to audio_gain, default_value to 1, minimum to 0, and maximum to 10. Finally, change the property Constant in Multiply Const to audio_gain. Now you can use the slider on the GUI to change the volume:
You can use this flow in order to explore the idea of using a software radio in order to tune into different frequencies. Because we used software, it is possible to tune into two radion stations at once. This should be done as an exercise.