Skip to content

Simulink blockset and MATLAB functions to interface with HackRF devices in real-time

License

Notifications You must be signed in to change notification settings

wbin020/simulink-hackrf

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simulink-HackRF

The Simulink-HackRF project is an Open Source Software Package allows interfacing MATLAB Simulink models with a HackRF device in real-time. Simulink-HackRF uses libhackrf to transmit or receive IQ samples. It is thus possible to build a wide variety of signal processing and wireless communication applications directly in Simulink while being able to test them on real hardware at the same time.

Spectrum scope demo

The Simulink-HackRF project was initiated at the Communication Engineering Lab (CEL) at the Karlsruhe Institute of Technology (KIT), Germany, http://www.cel.kit.edu.

Requirements

Build instructions for Linux

  1. Make sure MATLAB's mex compile script is configured. Open a MATLAB console:

     >> mex -setup C
     MEX configured to use 'gcc' for C language compilation.
     ...
    

    You can also enter $ mex -setup C a terminal (MATLAB executables must be in your PATH).

  2. Get, (build) and install the hackrf library and tools: You can use the link above or install hackrf* from your OS package repositories, if available. Make sure to include the development packages. Additional information can be found in the HackRF Wiki.

  3. To test your hackrf installation plug-in your device and run the included application

     $ hackrf_info
     Found HackRF board.
     ...
    

    If your device is not found, you can consult the HackRF FAQ for more information.

  4. Get the Simulink-HackRF source from GitHub.

     $ git clone git://github.com/kit-cel/simulink-hackrf.git
    

    If you aren't using git you can get the latest release. Extract the archive to any folder you want.

  5. There are two options for compiling the Simulink-HackRF blocks:

    • Run MATLAB, switch to your Simulink-HackRF directory and start the build process via

        >> make
      

      You might need to adapt the include and lib path for the hackrf library at the top of make.m to reflect your setup. Finally, add the build directory to the MATLAB Path.

    • As an alternative you can use CMake:

        $ cd simulink-hackrf
        $ mkdir build && cd build
        $ cmake ..
        ...
        $ make
        $ make install
      

      $ make install puts all required files in ~/Documents/MATLAB which is in the MATLAB Path by default. You can also skip this step and add the build directory to the MATLAB Path instead.

  6. After a refresh, you will find a new Toolbox named "HackRF" in the Simulink Library Browser. A simple spectrum scope model and a single-tone transmitter model is located in the directory demos. Also, there is MATLAB command >> hackrf_find_devices which you can use to test your setup.

Build instructions for Microsoft Windows

  1. Install a compiler and setup MATLAB's mex compile script: Here, we will use MinGW64 which is support since MATLAB 2015b. To set it up follow the instructions on the Mathworks page. Next, add the MinGW64 bin directory to your PATH (default is C:\TDM-GCC-64\bin) To double-check, open a MATLAB console:

     >> mex -setup C
     MEX configured to use 'MinGW64 Compiler (C)' for C language compilation.
     ...
    
  2. Get the Simulink-HackRF source from GitHub. If you aren't using git you can get the latest release. Extract the archive and create a subdirectory deps in there.

  3. Build the hackrf library (based on libhackrf README):

    • First, get the hackrf source code by cloning the repo or download it as an archive and extract. Next, you need to install CMake as well as windows binaries for libusb.

    • Start the CMake-GUI and set the source directory to your libhackrf sources, that is subdirectory 'host/libhackrf' in the repo. Create a directory 'build' in there and set it as the binaries directory in the CMake-GUI. Next, hit Configure and select 'MinGW Makefiles' as generator. Set the CMAKE_INSTALL_PREFIX to the 'deps' directory you created above. You will probably have to set the the include and lib settings for libusb manually: LIBUSB_INCLUDE_DIR must be set to the libusb directory, subfolder 'include/libusb-1.0'. LIBUSB_LIBRARIES can point to the static library shipped with the libusb binaries, 'MinGW64/static/libusb-1.0.a'. Finally, press Generate.

    • Open the MinGW Command Prompt, navigate to the 'libhackrf/build' directory and run mingw32-make to build the hackrf library. Next, run mingw32-make install.

  4. Get Zadig, plug-in your device and run Zadig and install the driver.

  5. Run MATLAB, switch to your Simulink-HackRF directory and start the build process via

     	>> make
    

    If you get errors, create an empty file libhackrf.lib in 'deps/bin/' and rerun. Copy libhackrf.dll from 'deps/bin' into the 'build' folder. Finally, add the build directory to the MATLAB Path.

  6. After a refresh, you will find a new Toolbox named "HackRF" in the Simulink Library Browser. A simple spectrum scope model and a single-tone transmitter model is located in the directory demos. Also, there is MATLAB command >> hackrf_find_devices which you can use to test your setup.

video install HackRFOne in matlab on Win8 Install simulink-hackrf in win8

Known issues / Future plans

  • Feature: Add support for multiple HackRF devices introduced in libhackrf version 2015.07.1

Copyright

The Simulink-HackRF interface consists of software from several authors. The following table lists all included software packages:

Contact and Support

If you have further questions concerning the Simulink-HackRF interface (e.g. the build process) or you've found a bug, please feel free to contact us:

Change-log

(see https://github.com/kit-cel/simulink-hackrf/releases)

About

Simulink blockset and MATLAB functions to interface with HackRF devices in real-time

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C 75.7%
  • CMake 17.2%
  • MATLAB 7.1%