File Exchange

image thumbnail

hackRF toolbox with spectrum analyzer

version (6.09 KB) by Tillmann Stübler
MATLAB interface for the hackRF


Updated 21 Feb 2016

View License

This submission is an interface to use the hackRF (a radio receiver/transmitter) directly in MATLAB. It gives you buffered receive and transmit functionality and you can control parameters like frequency, gain, sample rate, receiver and transmitter gain. It is nothing more than a convenient gateway to the hackrflib. It avoids writing the samples to temporary files and then calling hackrf_transfer.
Also, there is a small graphical app "panorama" which is a simple but useful spectrum analyzer. You can interactively tune the hackRF by panning and zooming into the spectrum display. This tool requires the DSP toolbox.

First prerequisite is to compile the hackrf library which is available here:
(or just install it if there's a package for your linux).
Some useful instructions for compilation are found here:

Then, you need to compile the MEX gateway function by just calling the make script.
To get access to the hackrf device, create an instance of the hackrf class. This object will make calls to the MEX function and it will offer intuitive control over the hackrf radio. For receiving/transmitting signals, you need to provide appropriate callback functions to process the complex samples.

Be aware that while using the hackrf within MATLAB, unplugging it will kill MATLAB instantly (At least that's the case on my computer). To be safe, only unplug it AFTER closing MATLAB.

There was another MATLAB/Simulink interface for the hackrf somewhere in the internet. Unfortunately, I was unable to compile it, so i just made my own one.

Cite As

Tillmann Stübler (2021). hackRF toolbox with spectrum analyzer (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (8)

Francesco Adamo

In addition to comment from Jordi Lopez of Sept 20, 2020 I add that also hackrf.dll must be copied from the Photos lib folder into the same folder of hackrfdev.c, otherwise the panorama.m and hackrf.m function will report and error Invalid MEX-file '....\hackrfdev.mexw64': The specified module could not be found.
This worked for me on a Win10 64 Pro Edition w/ MATLAB v2020b and VS 2019 Pro.
This toolbox is a very good attempt to start with HackRF in MATLAB but it appears to be no more maintained by the author nor by others contributors.
I hope to be able to add some further development to it.

Jordi Lopez

this worked for me in win 10 64 Home Edition
added <string.h>in hackrfdev.c include section
to avoid warning message
warning: implicit declaration of function 'strcmp' [-Wimplicit-function-declaration] if(nrhs>1 && strcmp("data",cmd)) {
and declared local hackrf.h in quotation marks ""
in hackrfdev.c:
#include "mex.h"
#include <stdio.h>
#include <string.h>
#include "hackrf.h"
Used library hackrf.lib from pothos SDR lib folder, after installation of exe
and copied hackrf.h from the same installation in folder
issued mex make command:
mex hackrfdev.c hackrf.lib
MEX completed successfully.

Ariel Kantorovich

i have problem to run this code:
Error in hackrf/get.IsOpen (line 88)

Error in hackrf/open (line 198)
if ~obj.IsOpen

Error in hackrf (line 70)
can someone help me?


Tillmann Stübler

Nikolay, you are missing the hackrf library. Download the binaries and place them in the appropriate directory...

Nikolay Nikolay

I compile the MEX gateway function just calling the make script and i have a problem:

Building with 'MinGW64 Compiler (C)'.
Error using mex
C:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -llibhackrf
collect2.exe: error: ld returned 1 exit status

Error in make (line 2)
mex -lhackrf hackrfdev.c
Can you help me?

mntaser salem

please i have a problem in operating this interface with windows, can you help me

James Muchechetere

Thanks but the ubuntu link above doesn't help with Matlab, it's talking about gnuradio etc.

MATLAB Release Compatibility
Created with R2015b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Inspired: SDRplay RSP2 Matlab Toolbox

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!