Write baseband signals to file
A baseband file is a specific type of binary file written by
Baseband signals are typically downconverted from a nonzero center
frequency to 0 Hz. The
are saved when the file is created.
To save a baseband signal to a file:
and set the properties of the object.
step to save a baseband signal
to a file.
release to save the baseband
signal to a file and to close the file.
Alternatively, instead of using the
to perform the operation defined by the System
object™, you can
call the object with arguments, as if it were a function. For example,
= step(obj,x) and
y = obj(x) perform
bbw = comm.BasebandFileWriter returns a
baseband writer object,
bbw, using the default properties.
bbw = comm.BasebandFileWriter(fname) returns
fname as the
bbw = comm.BasebandFileWriter(fname,fs) also
fs as the
bbw = comm.BasebandFileWriter(fname,fs,fc) also
fc as the
bbw = comm.BasebandFileWriter(fname,fs,fc,md) also
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
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,
To write only the last
to a file, set
NumSamplesToWrite to a finite
|info||Characteristic information about baseband file writer|
|reset||Reset states of baseband file writer object|
|step||Write baseband signal to file|
|Common to All System Objects|
Allow System object property value changes
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/Bdoc19a_1099451_128710/tpd3e100d1/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: '13-Apr-2019'
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).