Plot a FFT from bladerf-cli sample capture (GNU OCTIVE)

Discussions related to modulation techniques, filtering, error correction and detection, wireless link layer implementations, etc

Moderator: robert.ghilduta

Post Reply
kb3gtn
Posts: 10
Joined: Sat Aug 03, 2013 10:46 pm

Plot a FFT from bladerf-cli sample capture (GNU OCTIVE)

Post by kb3gtn » Wed Oct 02, 2013 8:36 pm

Use this gnu octive script to plot a FFT of the samples captured using bladerf-cli.
I do 8192 samples at a time when I run it..

Code: Select all

% read bladeRF-cli output.csv file and plot a FFT of the samples
% assumes input file is ./output.csv from bladeRF

% load file (edit filename as needed)
% loads into a variable call output.
load( "-ascii", "output.csv" );

%get number of samples
n = size( output )(1,1)

% combine columns I and Q into  I + jQ complex number
for i = 1:n
  samples(i) = output(i,1) + output(i,2)*1i;
endfor

% build high pass filter to move DC component.
[b, a] = cheby2( 4, 80, 0.001, 'high' );

filtered_samples = filter(b,a,samples);

% ok we now have samples.. compute FFT
Complex_FFT = fft( filtered_samples );

% plot
plot( 1:n , Complex_FFT );


drmpeg
Posts: 62
Joined: Fri Mar 01, 2013 3:58 am
Location: Silicon Valley
Contact:

Re: Plot a FFT from bladerf-cli sample capture (GNU OCTIVE)

Post by drmpeg » Thu Oct 17, 2013 11:15 pm

Good stuff. Some thorny details for others.

1) Get the package.

sudo apt-get install octave

2) Get the development package. Required to install octave packages.

sudo apt-get install liboctave-dev

3) To use the function cheby2(), the octave "signal" package has to be installed. When installing octave packages, octave has to be run as root. The signal package requires the "specfun", "control" and "general" packages.

sudo octave

octave:1> pkg install -forge specfun
octave:2> pkg install -forge control
octave:3> pkg install -forge general
octave:4> pkg install -forge signal

4) The "signal" package doesn't autoload when you restart octave.

octave:1> pkg load signal

Here's a plot of an ATSC signal with 61440 samples. Looks like a bad sample may have snuck in?

Image

Ron

bpadalino
Posts: 303
Joined: Mon Mar 04, 2013 4:53 pm

Re: Plot a FFT from bladerf-cli sample capture (GNU OCTIVE)

Post by bpadalino » Fri Oct 18, 2013 5:26 am

Thanks for the tips, and yeah - that looks like a bad sample.

Where were you writing to? What is the sample rate? You may want to think about writing to /dev/shm (basically RAM) if the samplerate is very high as to avoid incurring spinning disk access times. Then again, you might be writing to an SSD - I am not sure.

Can you find out what the value of that sample is? Put the number in hex and if the upper nibble is not just 0 or F, then it's a marker that wasn't stripped. You can probably just sign extend the lower 12 bits and things should look more continuous.

This is great stuff, by the way. Are you planning on modeling a whole ATSC transmitter/receiver in octave?

drmpeg
Posts: 62
Joined: Fri Mar 01, 2013 3:58 am
Location: Silicon Valley
Contact:

Re: Plot a FFT from bladerf-cli sample capture (GNU OCTIVE)

Post by drmpeg » Fri Oct 18, 2013 12:13 pm

Thanx for the tips. I'm trying to get the GnuRadio ATSC stuff (atsc_rx.py) to work. Sample rate is 6.144 MS/s. Of course, atsc_rx.py doesn't do anything, so I'm trying to verify that I'm feeding it good samples. I couldn't get osmocom_fft to accept a file last night (see #bladerf IRC), so in the meantime I thought I would try this stuff. However, it seems very slow (at least when reading the samples in).

Also not sure if my indoor antenna (one of the WA5VJB log-periodics) is providing enough SNR. I may have to put something more studly on the tower.

Here's what KQEH-DT looks like with the indoor antenna.

Image

Ron

drmpeg
Posts: 62
Joined: Fri Mar 01, 2013 3:58 am
Location: Silicon Valley
Contact:

Re: Plot a FFT from bladerf-cli sample capture (GNU OCTIVE)

Post by drmpeg » Sat Oct 19, 2013 9:06 pm

Now that osmocom_fft can accept a file, it can be used to display bladeRF captures. However, osmocom_fft requires that the samples be in GnuRadio complex format. I've written a utility to convert bladeRF binary capture files to GnuRadio complex files.

http://www.w6rz.net/iqtocmplx.c

Code: Select all

/*
bladeRF binary sc16q12 to GnuRadio complex converter
*/

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char **argv)
{
    FILE    *fp;
    FILE    *fpout;
    static short    buffer[16384];
    static float    output[16384];
    int	i, length;

    if (argc != 3) {
        fprintf(stderr, "usage: iqtocmplx <infile> <outfile>\n");
        exit(-1);
    }

    /*--- open binary file (for parsing) ---*/
    fp = fopen(argv[1], "rb");
    if (fp == 0) {
        fprintf(stderr, "Cannot open input file <%s>\n", argv[1]);
        exit(-1);
    }

    /*--- open binary file (for parsing) ---*/
    fpout = fopen(argv[2], "wb");
    if (fpout == 0) {
        fprintf(stderr, "Cannot open output file <%s>\n", argv[2]);
        exit(-1);
    }

    while(!feof(fp))  {
        length = fread(&buffer[0], 1, 16384, fp);
        for(i = 0; i < length / 2; i++)  {
            output[i] = (float)buffer[i] * (1.0f/2048.0f);
        }
        fwrite(&output[0], 1, length * 2, fpout);
    }

    fclose(fp);
    fclose(fpout);
    return 0;
}
Ron

evaxc
Posts: 12
Joined: Thu Oct 17, 2013 6:16 pm

Re: Plot a FFT from bladerf-cli sample capture (GNU OCTIVE)

Post by evaxc » Thu Oct 24, 2013 4:59 am

drmpeg wrote:Thanx for the tips. I'm trying to get the GnuRadio ATSC stuff (atsc_rx.py) to work. Sample rate is 6.144 MS/s. Of course, atsc_rx.py doesn't do anything, so I'm trying to verify that I'm feeding it good samples. I couldn't get osmocom_fft to accept a file last night (see #bladerf IRC), so in the meantime I thought I would try this stuff. However, it seems very slow (at least when reading the samples in).

Also not sure if my indoor antenna (one of the WA5VJB log-periodics) is providing enough SNR. I may have to put something more studly on the tower.

Here's what KQEH-DT looks like with the indoor antenna.

Image

Ron
wow,I am a beginner of bladeRF.How can I get this GUI window like yours?
Please tell me something about this,thank you !!

drmpeg
Posts: 62
Joined: Fri Mar 01, 2013 3:58 am
Location: Silicon Valley
Contact:

Re: Plot a FFT from bladerf-cli sample capture (GNU OCTIVE)

Post by drmpeg » Thu Oct 24, 2013 2:45 pm

evaxc wrote: wow,I am a beginner of bladeRF.How can I get this GUI window like yours?
Please tell me something about this,thank you !!
http://gqrx.dk/

It's only available for Linux and Mac though.

Ron

evaxc
Posts: 12
Joined: Thu Oct 17, 2013 6:16 pm

Re: Plot a FFT from bladerf-cli sample capture (GNU OCTIVE)

Post by evaxc » Thu Oct 24, 2013 7:41 pm

drmpeg wrote:
evaxc wrote: wow,I am a beginner of bladeRF.How can I get this GUI window like yours?
Please tell me something about this,thank you !!
http://gqrx.dk/

It's only available for Linux and Mac though.

Ron
What a pity ... maybe I should install a vm. thank you.

Tim
Posts: 3
Joined: Fri Mar 01, 2013 8:20 am

Re: Plot a FFT from bladerf-cli sample capture (GNU OCTIVE)

Post by Tim » Wed Mar 12, 2014 6:51 pm

I highly recommend using a VM if you can't do a native Linux installation. You can get yourself up and running pretty quickly with VMWare, Ubuntu 12.04 LTS, and the script provided in the Getting Started: Linux guide.

I'm going to give gqrx a shot. Looks like a better starting place than the osmocom examples.

Post Reply