comm.BasebandFileWriter

Write baseband signals to file

Description

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 SampleRate and CenterFrequency properties are saved when the file is created.

To save a baseband signal to a file:

  1. Create a comm.BasebandFileWriter object and set the properties of the object.

  2. Call step to save a baseband signal to a file.

  3. Call release to save the baseband signal to a file and to close the file.

Note

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 example, y = step(obj,x) and y = obj(x) perform equivalent operations.

Construction

bbw = comm.BasebandFileWriter returns a baseband writer object, bbw, using the default properties.

bbw = comm.BasebandFileWriter(fname) returns bbw and sets fname as the Filename property.

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

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

bbw = comm.BasebandFileWriter(fname,fs,fc,md) also sets structure md as the MetaData property.

bbw = comm.BasebandFileWriter(___,Name,Value) specifies additional properties using Name,Value pairs. Unspecified properties have default values.

Example:

bbw = comm.BasebandFileWriter('qpsk_data.bb',10e6,2e9);

Properties

expand all

Name of saved file, specified as a character vector. The filename can include a relative or an absolute path.

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

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.

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.

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

  • To write all the baseband signal samples to a file, set NumSamplesToWrite to Inf.

  • To write only the last NumSamplesToWrite samples to a file, set NumSamplesToWrite to a finite number.

Data Types: double

Methods

infoCharacteristic information about baseband file writer
resetReset states of baseband file writer object
stepWrite baseband signal to file
Common to All System Objects
release

Allow System object property value changes

Examples

collapse all

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 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 bbw. Release the object.

info(bbw)
ans = struct with fields:
             Filename: '/tmp/BR2020bd_1459859_138098/mlx_to_docbook18/tp2c8e57a0/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. Read the metadata from the file.

bbr = comm.BasebandFileReader('baseband_data.bb','SamplesPerFrame',100);
bbr.Metadata
ans = struct with fields:
    Date: '19-Aug-2020'

Read the data from the file.

z = [];

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

Display information about bbr. Release bbr.

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

release(bbr)

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

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

Introduced in R2016b