Main Content

comm.BasebandFileWriter

Write baseband signal to file

Description

The comm.BasebandFileWriter System object™ writes a specific type of binary file to store baseband signal data. Baseband signals are typically down-converted from a nonzero center frequency to 0 Hz. The SampleRate and CenterFrequency properties are saved when the file is created.

To write a baseband signal to a file:

  1. Create the comm.BasebandFileWriter object and set its properties.

  2. Call the object with arguments, as if it were a function.

To learn more about how System objects work, see What Are System Objects?

Creation

Description

bbw = comm.BasebandFileWriter creates a baseband file writer System object to write a baseband signal to a specific type of binary file.

bbw = comm.BasebandFileWriter(fname) sets the Filename property to fname.

bbw = comm.BasebandFileWriter(fname,fs) also sets the SampleRate property to fs.

bbw = comm.BasebandFileWriter(fname,fs,fc) also sets the CenterFrequency property to fc.

bbw = comm.BasebandFileWriter(fname,fs,fc,md) also sets the Metadata property to md.

example

bbw = comm.BasebandFileWriter(___,Name=Value) sets properties using one or more name-value arguments in addition to an input argument combination from any of the previous syntaxes. For example, SampleRate=2 sets the sample rate of the baseband file writer to 2.

Properties

expand all

Unless otherwise indicated, properties are nontunable, which means you cannot change their values after calling the object. Objects lock when you call them, and the release function unlocks them.

If a property is tunable, you can change its value at any time.

For more information on changing property values, see System Design in MATLAB Using System Objects.

Name of the baseband file to write, specified as a string scalar or character vector. The filename can include a relative or absolute path.

Data Types: string | char

Sample rate of the output baseband signal in Hz, specified as a positive scalar.

Data Types: double

Center frequency of the baseband signal in Hz, specified as a positive scalar or row vector. When this property is a row vector, each element is the center frequency of a channel in a multichannel signal. The vector length equal the number of columns in the input signal samples.

Data Types: double

Data describing the baseband signal, specified as a scalar structure or object.

Data Types: struct | object

Number of samples to save, specified as a positive integer or Inf.

  • To write all of the baseband signal samples to a file, set this property to Inf.

  • To write only the last NumSamplesToWrite samples to a file, set this property to a positive integer.

Data Types: double

Usage

Description

bbw(samples) writes one frame of baseband samples to the file specified by the Filename property. The number of samples written to the file is determined by the NumSamplesToWrite property.

Input Arguments

expand all

Baseband signal to write to the file, specified as an Nsample-by-Nchannel matrix of numeric values. Nsample is the number of baseband samples and Nchannel is the number of channels in the input signal. If NumSamplesToWrite is Inf, the object writes all of the samples in the input signal to the file.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64
Complex Number Support: Yes

Object Functions

To use an object function, specify the System object as the first input argument. For example, to release system resources of a System object named obj, use this syntax:

release(obj)

expand all

infoCharacteristic information about baseband file writer
stepRun System object algorithm
releaseRelease resources and allow changes to System object property values and input characteristics
resetReset internal states of System object

Examples

collapse all

Create a baseband file writer object specifying a sample rate of 1 kHz and a 0 Hz center frequency.

bbw = comm.BasebandFileWriter('baseband_data.bb',1000,0);

Save the date for today in the Metadata structure.

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 baseband_data.bb.

bbw(x)

Display information about the baseband file writer. Then, release the object.

info(bbw)
ans = struct with fields:
             Filename: '/tmp/Bdoc24b_2679053_1670783/tp29d70b66/comm-ex66490302/baseband_data.bb'
      SamplesPerFrame: 1000
          NumChannels: 2
             DataType: 'double'
    NumSamplesWritten: 1000

release(bbw)

Create a baseband file reader object to read the saved data. Display the metadata from the file.

bbr = comm.BasebandFileReader('baseband_data.bb', ...
    'SamplesPerFrame',100);
bbr.Metadata
ans = struct with fields:
    Date: '20-Jul-2024'

Read the data from the file.

z = [];

while ~isDone(bbr)
    y = bbr();
    z = cat(1,z,y);
end

Display information about the baseband file reader. Then, release object.

info(bbr)
ans = struct with fields:
    NumSamplesInData: 1000
            DataType: 'double'
      NumSamplesRead: 1000

release(bbr)

Confirm that the original modulated data x, matches the data z, read from file baseband_data.bb.

isequal(x,z)
ans = logical
   1

Tips

  • comm.BasebandFileWriter writes baseband signals to uncompressed binary files. To share these files, you can compress them to a zip file using the zip function. For more information, see Create and Extract from Zip Archives.

Extended Capabilities

Version History

Introduced in R2016b

expand all