Hello World with matlab and the server

From Tools4SDR

Jump to: navigation, search
Tutorial: Using the USRP with Matlab
1. Description of SDR4All toolbox
2. Setup the toolbox
3. About the signals
4. Hello world tutorial

When you have installed the SDR4All toolbox for USRP, you can perform so experimentations.

In the following, some basics examples are performed.

Please, provide us some feedbacks at pierre@tools4sdr.com.

Contents

General configuration

These exemples suppose that you have the following equipments:

  • A PC running Windows and Matlab.
  • 2 USRPs connected to this computer with RFX2400 daughterboards.

The purpose of this demonstration is to transmit a signal from an USRP to the second USRP.

Two USRPs connected by wire

The card working in transmission uses the port TX/RX of the daughterboard. If you are using the toolbox with a version < 1.0.2, the card working in reception uses the port RX2. With version >= 1.0.2, it works with the port TX/RX.

These tests use the scripts TX bursts and RX to file which code will be available for download and explained.

Test the reception of a signal with Matlab

To perform this test, we process as follows:

  • The USRP card working in TX is controlled by the soft TX bursts that stands in the SDR4All folder in your start menu.
  • The USRP card working in RX is controlled by matlab.

You have first to launch both applications TX bursts and SDR4All server.

Configuration of TX

When you launch the application, select a card (for example card #1) and the daughterboard you want to use. You should then be able to select the transmission parameters. Choose them as illustrated on the following image:

TX bursts interface

When you will be ready to receive the signal, you just click on the button Start transmission.

Configuration of RX

At the matlab prompt, type the following commands:

sock=SDR4All_Connect(0,'SlotA','RX'); % 0 stands for USRP #0

The communication with the USRP should be confirmed with a message like:

 Number of connected USRP: 2
 Communication set with USRP 1 and daugtherboard on slot A

The next commands are:

[gain_min,gain_max,gain_step] = SDR4All_GetGain(sock);
[freq_min,freq_max] = SDR4All_GetFreq(sock);
SDR4All_SetGain(sock,(gain_max+gain_min)/2);
SDR4All_SetDecimRate(sock,128); % set signal sampling period (and bandwidth)
SDR4All_SetFreq(sock,2422e6);

You can now start the transmission with the TX bursts soft. Use the following command with matlab to record 5 seconds of signal (at 500kHz):

[Data] = SDR4All_GetData(sock,5*1000*500);

and plot the data with:

Te = (1:length(Data))/(500e3);
plot(Te,real(Data));

You should observe the following signal:

Received signal of the hello world example

If you have finished to use the toolbox, close the connection to server with the command:

SDR4All_Close(sock);

Test the transmission of a signal from matlab to a file

To perform this test, we now process as follows:

  • The USRP card working in RX is controlled by the soft RX to file that stands in the SDR4All folder in your start menu.
  • The USRP card working in TX is controlled by matlab.

You have first to launch both applications RX to file and SDR4All server.

Configuration of RX

The configuration is the same as for the TX bursts software described previously. You have to select an USRP card (#1 in this example) and a daughterboard. Use then the following parameters:

RX to file interface

Select a file and start the reception when you just have sent the signal.

Configuration of TX

With matlab, use the following command to connect to the USRP in TX:

sock=SDR4All_Connect(0,'SlotA','TX'); % 0 stands for USRP #0

Set the communication parameters:

SDR4All_SetGain(sock,20); % Maximal TX gain
SDR4All_SetFreq(sock,2422e6);
SDR4All_SetInterpRate(sock,256); % set signal sampling period (and bandwidth)

Generate the signal to be transmitted:

Basic  = kron(ones(5e5/10/2/4,1),[ones(10,1);-ones(10,1)]);
Vide = zeros(125000,1);
Base = [Basic;Vide];
Sig = kron(ones(20,1),Base);
Te = (1:length(Sig))/(500e3);
plot(Te,Sig);

And perform the transmission:

SDR4All_SendData(sock,Sig);

Note that matlab gives you the prompt just after the command. Nevertheless, the transmissions begins when the server has received all data to transmit (can take one or two seconds depending on the signal length) and ends of course when all data are transmitted.

You have to use the RX script at this time to record the signal.

Read the signal

You can read the file written by the RX to file script within matlab with the following commands:

fid = fopen('test.dat');
a = fread(fid,'float');
fclose(fid);
b = a(1:2:end)+i*a(2:2:end);

Test the transmission of a signal from matlab to matlab

The previous tests can finally be done from matlab to matlab. You hence needs to launch twice matlab.

You can use the same command as above but replace for either the RX or the TX the connection line from:

sock=SDR4All_Connect(0,'SlotA','TX'); % 0 stands for USRP #0

to

sock=SDR4All_Connect(1,'SlotA','TX'); % 1 stands for USRP #1

You just have to connect to one USRP in TX and to the other one in RX. You can't connect to a card in RX and TX at the same time.

Personal tools
Software defined radio