comm.BasebandFileReader

Read baseband signals from file

Description

The comm.BasebandFileReader object reads a baseband signal from a specific type of binary file written by comm.BasebandFileWriter. Baseband signals are typically downconverted from a nonzero center frequency to 0 Hz. The SampleRate and CenterFrequency properties are saved when the file is created. The comm.BasebandFileReader object automatically reads the sample rate, center frequency, number of channels, and any descriptive data and saves them to its read-only properties.

To create an input signal from a saved baseband file:

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

  2. Call step to generate a baseband signal from saved data.

  3. Call release 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) and y = obj() perform equivalent operations.

Construction

bbr = comm.BasebandFileReader returns a baseband reader object, bbr, using the default properties.

bbr = comm.BasebandFileReader(fname) returns a baseband reader object and sets fname as the Filename property.

bbr = comm.BasebandFileReader(fname,spf) also sets spf as the SamplesPerFrame property.

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

Example:

bbr = comm.BasebandFileReader('recorded_data',100);

Properties

expand all

Name of the baseband file to read, specified as a character vector. Specify the absolute path only if the file is not on the MATLAB® path. Only the absolute path is saved and displayed.

This property is read-only.

Sample rate of the saved baseband signal in Hz.

This property is read-only.

Center frequency of the saved baseband signal in Hz. When this property is a row vector, each element represents the center frequency of a channel in a multichannel signal.

This property is read-only.

Number of channels of the saved baseband signal.

This property is read-only.

Data describing the baseband signal. If the file has no descriptive data, this property is an empty structure.

Number of samples per output frame, specified as a positive integer.

Data Types: double

Flag to repeatedly read baseband file, specified as a logical scalar. To repeatedly read the baseband file specified by Filename, set this property to true.

Methods

infoCharacteristic information about baseband file reader
Common to All System Objects
release

Allow System object property value changes

step

Generate baseband signal from file

reset

Reset states of baseband file reader object

isDone

Read status of baseband file samples

Examples

collapse all

Read a baseband signal from file using the comm.BasebandFileReader System object.

Create a baseband file reader object.

bbr = comm.BasebandFileReader('example.bb')
bbr = 
  comm.BasebandFileReader with properties:

            Filename: '/tmp/BR2020bd_1459859_138098/mlx_to_docbook15/tp6300b53d/comm-ex87872352/example.bb'
          SampleRate: 1
     CenterFrequency: 100000000
         NumChannels: 1
            Metadata: [1x1 struct]
     SamplesPerFrame: 100
    CyclicRepetition: false

Use the info method to gain additional information about bbr. The file contains 10000 samples of type 'double'. No samples have been read.

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

Reading Data with Multiple Calls to Baseband File Reader Object

Since the NumSamplesPerFrame is 100, and NumSamplesInData is 10000, reading the entire contents of the example.bb file will require multiple calls to the bbr object. This can be achieved by using the isDone method to terminate a while loop.

y = [];

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

Plot the absolute magnitude of the baseband data.

plot(abs(y))

Confirm that all the samples have been read.

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

The total number of samples and the number of samples read are the same.

Release the baseband file reader resources.

release(bbr)

Reading Data with Single Call to Baseband File Reader Object

Alternatively, to read all samples from the file in one call to the object, you can set the samples per frame equal to the number of samples in the data file.

bbrinfo = bbr.info
bbrinfo = struct with fields:
    NumSamplesInData: 10000
            DataType: 'double'
      NumSamplesRead: 10000

bbr.SamplesPerFrame = bbrinfo.NumSamplesInData
bbr = 
  comm.BasebandFileReader with properties:

            Filename: '/tmp/BR2020bd_1459859_138098/mlx_to_docbook15/tp6300b53d/comm-ex87872352/example.bb'
          SampleRate: 1
     CenterFrequency: 100000000
         NumChannels: 1
            Metadata: [1x1 struct]
     SamplesPerFrame: 10000
    CyclicRepetition: false

Now read the entire contents of the example.bb file with a single call to the bbr object. Confirm that all the samples have been read.

xx = bbr();
isequal(y,xx)
ans = logical
   1

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

Extended Capabilities

Introduced in R2016b