File: save_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 (38 lines) | stat: -rw-r--r-- 988 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
32
33
34
35
36
37
38
function [ret] = save_grcomplex(filename, signal)
% SAVE_GRCOMPLEX Write a normalized complex signal to a binary file in the
%                GNU Radio complex float format.
%
%   [RET] = save_grcomplex(FILENAME, SIGNAL)
%
%   RET is 1 on success, and 0 on failure.
%
%   FILENAME is the target filename. The file will be overwritten if it
%   already exists. The file data is written in little-endian format.
%
%   SIGNAL is a complex signal with the real and imaginary components
%   within the range [-1.0, 1.0].

    [f, err_msg] = fopen(filename, 'w', 'ieee-le');
    if f ~= -1

        sig_i = real(signal);
        sig_q = imag(signal);

        sig_len = 2 * length(sig_i);

        sig_out(1:2:sig_len-1) = sig_i;
        sig_out(2:2:sig_len)   = sig_q;

        count = fwrite(f, sig_out, 'float');
        fclose(f);

        if count == sig_len;
            ret = 1;
        else
            ret = 0;
        end
    else
        error(err_msg);
        ret = 0;
    end
end