# Difference between revisions of "Octave"

m (special character confusion due to use of tilde in octaverc filespec) |
(minor change) |
||

Line 51: | Line 51: | ||

== Using Python as an alternative to Octave and Matlab == | == Using Python as an alternative to Octave and Matlab == | ||

− | Most likely you have several scientific Python libraries installed, such as SciPy and NumPy components (in particular, [http://matplotlib.sourceforge.net/ | + | Most likely you have several scientific Python libraries installed, such as SciPy and NumPy components (in particular, [http://matplotlib.sourceforge.net/ Matplotlib]). With these tools, you can use Python to plot and analyse data. |

## Latest revision as of 21:44, 25 July 2020

## Contents

# Octave and Matlab[edit]

Octave is the most popular analysis tool with GNU Radio, as the GNU Radio package includes its own set of scripts for reading and parsing output.

Matlab is a closed source tool, and very expensive--but if you already have it installed, you might prefer it to Octave.

## Installing[edit]

Installing Octave can be done from source, or in Ubuntu using:

sudo apt-get install octave

To use the GNU Radio octave scripts, you must add the path to your Octave path variable. This is easily done using your local ~/.octaverc configuration file. If you check out the GNU Radio trunk to /home/username/gnuradio/, you can add the following to ~/.octaverc:

addpath("/home/username/gnuradio/gr-utils/octave")

## Parsing Data[edit]

To parse data output from GNU Radio, the easiest thing to do is use the provided scripts. Ensure that you have added the GNU Radio script path to your octave path, as described in the installing guide. These help you read data that you may have dumped to disk using gr.file_sink(*size*, *filename*).

You want to use one of the following methods, based on the *size* parameter used in gr.file_sink(). Each method takes a filename as the first parameter, and an optional second parameter which is the number of items to read from the file:

'** _'read_complex_binary()_**: gr.sizeof_gr_complex

'** _'read_float_binary()_**: gr.sizeof_float

'** _'read_int_binary()_**: gr.sizeof_int

'** _'read_short_binary()_**: gr.sizeof_short

'** _'read_char_binary()_**: gr.sizeof_char

For example, after capturing 64-bit complex using *gr.file_sink(gr.sizeof_gr_complex, "capture.dat")* in a Python script:

c=read_complex_binary('capture.dat');

Data captured directly from the USRP is stored as 32-bit complex, rather than 64-bit complex (gr.sizeof_gr_complex). To read this data, first use *read_short_binary()* and then split it into a two dimensional vector:

d=read_short_binary(data); c=split_vect(d,2);

This works for both Octave and Matlab.

## Plotting[edit]

To plot data using octave, it is easiest to do with gnuplot. You can install GNU plot from source or using the Ubuntu repository:

sudo apt-get install gnuplot

To plot I and Q separately over time, graph each component separately:

plot([real(c), imag(c)])

Generating an I/Q plot (x-axis I, y-axis Q) can be done using:

plot(c)

## Using Python as an alternative to Octave and Matlab[edit]

Most likely you have several scientific Python libraries installed, such as SciPy and NumPy components (in particular, Matplotlib). With these tools, you can use Python to plot and analyse data.