Page 1 of 1

Trying to understand the different IQ sample ranges

Posted: Mon Mar 23, 2015 10:38 am
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

Re: Trying to understand the different IQ sample ranges

Posted: Tue Mar 24, 2015 6:39 am
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...

Re: Trying to understand the different IQ sample ranges

Posted: Tue Mar 24, 2015 9:05 am
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...