Write baseband signals to file
A baseband file is a specific type of binary file written by the comm.BasebandFileWriter
System object™. Baseband signals are typically down-converted from a nonzero center
frequency to 0 Hz. The
CenterFrequency properties are saved when the file is created.
To save a baseband signal to a file:
comm.BasebandFileWriter object and
set the properties of the object.
step to save a baseband signal to a
release to save the baseband signal to
a file and to close the file.
Alternatively, instead of using the
step method to perform the
operation defined by the System object, you can call the object with arguments, as if it were a function. For
y = step(obj,x) and
y = obj(x)
perform equivalent operations.
bbw = comm.BasebandFileWriter returns a baseband writer object,
bbw, using the default properties.
bbw = comm.BasebandFileWriter(fname) returns
bbw and sets
fname as the
bbw = comm.BasebandFileWriter(fname,fs) also sets
fs as the
bbw = comm.BasebandFileWriter(fname,fs,fc) also sets
fc as the
bbw = comm.BasebandFileWriter(fname,fs,fc,md) also sets structure
md as the
bbw = comm.BasebandFileWriter(___,Name,Value)
specifies additional properties using
Name,Value pairs. Unspecified
properties have default values.
bbw = comm.BasebandFileWriter('qpsk_data.bb',10e6,2e9);
Filename— Name of saved file
'untitled.bb'(default) | character vector
Name of saved file, specified as a character vector. The filename can include a relative or an absolute path.
SampleRate— Sample rate of output signal
1(default) | positive scalar
Sample rate of the output signal, specified in Hz as a positive scalar.
CenterFrequency— Center frequency of the baseband signal
100000000(default) | positive integer scalar | row vector
Center frequency of the baseband signal, specified in Hz as a positive
integer scalar or row vector. If
CenterFrequency is a
row vector, each element corresponds to a channel.
Metadata— Data describing the baseband signal
Data describing the baseband signal, specified as a structure. The structure can have any number of fields and any field name. The field values can be of any numeric, logical, or character data type and have any number of dimensions.
NumSamplesToWrite— Number of samples to save
Inf(default) | positive integer
Number of samples to save, specified as a positive integer.
To write all the baseband signal samples to a file, set
To write only the last
samples to a file, set
NumSamplesToWrite to a
|info||Characteristic information about baseband file writer|
|step||Write baseband signal to file|
Create a baseband file writer object having a sample rate of 1 kHz and a 0 Hz center frequency.
bbw = comm.BasebandFileWriter('baseband_data.bb',1000,0);
Save today's date in the
bbw.Metadata = struct('Date',date);
Generate two channels of QPSK-modulated data.
d = randi([0 3],1000,2); x = pskmod(d,4,pi/4,'gray');
Write the baseband data to file
Display information about
bbw. Release the object.
ans = struct with fields: Filename: '/tmp/Bdoc21b_1757077_50723/tp81a94b56/comm-ex66490302/baseband_data.bb' SamplesPerFrame: 1000 NumChannels: 2 DataType: 'double' NumSamplesWritten: 1000
Create a baseband file reader object to read the saved data. Read the metadata from the file.
bbr = comm.BasebandFileReader('baseband_data.bb','SamplesPerFrame',100); bbr.Metadata
ans = struct with fields: Date: '01-Sep-2021'
Read the data from the file.
z = ; while ~isDone(bbr) y = bbr(); z = cat(1,z,y); end
Display information about
ans = struct with fields: NumSamplesInData: 1000 DataType: 'double' NumSamplesRead: 1000
Confirm the original modulated data,
x, matches the data read from file
ans = logical 1
Usage notes and limitations:
See System Objects in MATLAB Code Generation (MATLAB Coder).