File: load_grcomplex.m

package info (click to toggle)
bladerf 0.2024.05-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 245,984 kB
  • sloc: ansic: 361,923; vhdl: 28,167; tcl: 14,424; python: 3,668; sh: 1,811; makefile: 1,255; xml: 1,020; cpp: 473; asm: 158; csh: 18
file content (31 lines) | stat: -rw-r--r-- 913 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
function [ signal, signal_i, signal_q ] = load_grcomplex(filename)
% LOAD_GRCOMPLEX Read a complex signal from a binary file containing
%                complex float samples saved using GNU Radio.
%
%                The data in the file is assumed to be little-endian.
%
%
%   [SIGNAL, SIGNAL_I, SIGNAL_Q] = load_grcomplex(FILENAME)
%
%   FILENAME is the source filename.
%
%   SIGNAL is a complex signal with the real and imaginary components
%   within the range [-1.0, 1.0].
%
%   SIGNAL_I and SIGNAL_Q are optional return values which contain the
%   real and imaginary components of SIGNAL as separate vectors.
%
    [f, err_msg] = fopen(filename, 'r', 'ieee-le');
    if f ~= -1
        data = fread(f, Inf, 'float');

        signal_i = data(1:2:end-1, :);
        signal_q = data(2:2:end,   :);

        signal = signal_i + 1j .* signal_q;

        fclose(f);
    else
        error(err_msg)
    end
end