Trying to understand the different IQ sample ranges

Having issues with the site, hardware, source code, or any other issues?
Post Reply
mbadders
Posts: 6
Joined: Fri Mar 20, 2015 9:29 am

Trying to understand the different IQ sample ranges

Post by mbadders »

Hi, I've been playing around with the BladeRF using bladeRF_cli, matlab and simulink, however I'm a bit confused about the samples I'm receiving.

*bladeRF-cli: This appears to be IQ samples normalised over 0 - 2048
*matlab (bladerf_dev(handle, 'RX', ...)): The return data from this appears to be complex IQ samples in between 1 to -1 on re and img planes.
*Simulink bladerf_source: This is the weird one that is confusing me, the complex values seem to be normalised around 0 and +31 on the re and img...

Does anyone know the reason for these differences? In particular for the Simulink source?

Cheers,

MB
jynik
Posts: 455
Joined: Thu Jun 06, 2013 8:15 pm

Re: Trying to understand the different IQ sample ranges

Post by jynik »

I think I can clarify on 2/3. I'm not sure about Simulink... I would have thought that'd be [-1.0, 1.0).

The "binary" input/output in the bladeRF-cli uses 12-bit ADC/DAC format, packed into 16-bit words. You can find a bit more info about this here in the libbladeRF docs. It's important to note here that the range is [-2048, 2047] (i.e., [-2048, 2048)) as the 12-bit value is two's complement.

The complex samples sent/received are interleaved: I, Q, I, Q, ... , I, Q

As you noted, the MATLAB interface normalizes to [-1.0, 1.0). Coverting back and forth is a matter of scaling by 2048.0. Here's a script I use to load the CLI samples into MATLAB:

Code: Select all

% Usage: [sig_complex, sig_i, sig_q ] = load_binary_sc16q11('myfile.bin');
% The loaded data will be in the ADC/DAC range of [-2048, 2047],
% so to convert to a float...
%                       sig_complex = load_binary_sc16q11('myfile.bin');
%                       sig_complex = sig_complex ./ 2048.0;
function [ signal, signal_i, signal_q ] = load_binary_sc16q11(filename)
    [f, err_msg] = fopen(filename, 'r', 'ieee-le');
    if f ~= -1
        data = fread(f, Inf, 'int16');
        signal_i = data(1:2:end, :);
        signal_q = data(2:2:end, :);
        signal = signal_i + 1i .* signal_q;
        fclose(f);
    else
        error(err_msg);
    end
end
I'll have to ask around on the Simulink block...
mbadders
Posts: 6
Joined: Fri Mar 20, 2015 9:29 am

Re: Trying to understand the different IQ sample ranges

Post by mbadders »

Thanks for the script! I was doing something similar in matlab to import the .csv files from bladeRF-cli, and normalised by 2048 like you said. I'm struggling with another issue now, but that is a topic for another thread...
Post Reply