1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2024-12-15 04:30:33 +00:00

added a script that reads a signal stored using the ibyte format, quantizes the signal using the specified number of bits, and writes the signal to an output file.

This commit is contained in:
Marc Majoral 2020-04-01 20:22:46 +02:00 committed by Carles Fernandez
parent 21cdbc613f
commit c0796eb983

View File

@ -0,0 +1,84 @@
%
% \file quantize_signal.m
% \brief This file opens a binary file using the ibyte format, reads and
% quantizes the signal using the most significant nbits, and stores the
% quantized signal into an output file. The output file also uses the
% ibyte format.
% \author Marc Majoral, 2020. mmajoral(at)cttc.es
%
% Usage: quantize_signal (infile, outfile, nbits)
%
% Inputs:
% infile - Input file name
% outfile - Output file name
% nbits - number of quantization bits
%
% -------------------------------------------------------------------------
%
% Copyright (C) 2010-2020 (see AUTHORS file for a list of contributors)
%
% GNSS-SDR is a software defined Global Navigation
% Satellite Systems receiver
%
% This file is part of GNSS-SDR.
%
% SPDX-License-Identifier: GPL-3.0-or-later
%
% -------------------------------------------------------------------------
%
function quantize_signal (infile, outfile, nbits)
%% usage: quantize_signal (infile, outfile, nbits)
%%
%% open input signal file infile, quantize the signal using the most
%% significant nbits and write the quantized signal to outfile
%%
fileID = fopen(infile, 'rb');
fileID2 = fopen(outfile, 'wb');
% initialize loop
BlockSize = 20000000; % processing block size
NumBitsPerSample = 8; % num. bits per sample ibyte format.
NumBitsSHift = NumBitsPerSample - nbits;
DivVal = 2^NumBitsSHift;
Lim2sCompl = 2^(NumBitsPerSample - 1) - 1;
Base2sCompl = 2^NumBitsPerSample;
do = true;
data_bytes = fread(fileID, BlockSize);
while do
% 2's complement
for k=1:length(data_bytes)
if (data_bytes(k) > Lim2sCompl)
data_bytes(k) = -Base2sCompl + data_bytes(k);
end
end
% take the nbits most significant bits
data_bytes = floor(data_bytes/DivVal);
% quantization correction
data_bytes = data_bytes*2 + 1;
% 2's complement
for k=1:length(data_bytes)
if (data_bytes(k) < 0)
data_bytes(k) = Base2sCompl + data_bytes(k);
end
end
% write result
fwrite(fileID2, data_bytes);
if (size(data_bytes) < BlockSize)
do = false;
else
data_bytes = fread(fileID,BlockSize);
end
end
% close files
fclose(fileID);
fclose(fileID2);