Main Content

comm.BasebandFileReader

Read baseband signal from file

Description

The comm.BasebandFileReader System object™ reads a baseband signal from a specific type of binary file written by the comm.BasebandFileWriter System object. 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 read a baseband file from a file:

  1. Create the comm.BasebandFileReader 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

bbr = comm.BasebandFileReader creates a baseband file reader System object to read a baseband signal from a specific type of binary file written by the comm.BasebandFileWriter System object.

example

bbr = comm.BasebandFileReader(fname) sets the Filename property to fname.

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

bbr = comm.BasebandFileReader(___,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 reader 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 read, specified as a string scalar or character vector. The object saved and displays the absolute path.

Tips

If the file is not on the MATLAB® path, specify the absolute path.

Data Types: string | char

This property is read-only.

Sample rate of the saved baseband signal in Hz, returned as a positive scalar.

Data Types: double

This property is read-only.

Center frequency of the saved baseband signal in Hz, returned 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.

Data Types: double

This property is read-only.

Number of channels in the saved baseband signal, returned as a positive integer.

Data Types: double

This property is read-only.

Data describing the baseband signal, returned as a structure of fields defined when creating the baseband file writer. If the file has no descriptive data, this property is an empty structure.

Data Types: struct

Number of samples per output frame, specified as a positive integer or Inf. When this property is Inf, the output frame contains all of the samples in the baseband file.

Data Types: double

Option to repeatedly read the baseband file, specified as a logical 0 (false) or 1 (true).

  • When this property is false, the object appends zeros to the last frame if it is partially filled. Then, the object returns all-zero frames.

  • When this property is true, the object repeatedly reads the file, starting from the first sample.

Data Types: logical

Usage

Description

example

samples = bbr() reads the baseband signal file from the file specified by the Filename property.

Output Arguments

expand all

Baseband samples read from the file, returned as an SamplesPerFrame-by-NumChannels matrix of complex values read from the baseband signal file specified by Filename. When the SamplesPerFrame property is Inf, the output matrix contains all of the samples in the baseband signal file.

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 reader
isDoneEnd-of-data status
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

Read a baseband signal from file using a single call to the comm.BasebandFileReader System object. To read all samples from the file in one call to the object, you can set the samples per frame equal to inf or to the number of samples in the data file.

Create a baseband file reader object setting the samples per frame to inf. Use the info method to gain additional information about bbr. The file contains 10,000 samples of type 'double'. No samples have been read.

bbr1 = comm.BasebandFileReader('baseband_samples_1ghz.bb',SamplesPerFrame=inf)
bbr1 = 
  comm.BasebandFileReader with properties:

            Filename: '/tmp/Bdoc22b_2054784_3730881/tpa45d7b20/comm-ex94749964/baseband_samples_1ghz.bb'
          SampleRate: 1
     CenterFrequency: 100000000
         NumChannels: 1
            Metadata: [1x1 struct]
     SamplesPerFrame: Inf
    CyclicRepetition: false

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

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

samples1 = bbr1();
info(bbr1)
ans = struct with fields:
    NumSamplesInData: 10000
            DataType: 'double'
      NumSamplesRead: 10000

Release the baseband file reader resources.

release(bbr1)

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. To do this you must updates the samples per frame setting (bbr.SamplesPerFrame) to the value of NumSamplesInData returned by the info object function.

Create a baseband file reader object and display the structure retuned by the info object function.

bbr2 = comm.BasebandFileReader('baseband_samples_1ghz.bb')
bbr2 = 
  comm.BasebandFileReader with properties:

            Filename: '/tmp/Bdoc22b_2054784_3730881/tpa45d7b20/comm-ex94749964/baseband_samples_1ghz.bb'
          SampleRate: 1
     CenterFrequency: 100000000
         NumChannels: 1
            Metadata: [1x1 struct]
     SamplesPerFrame: 100
    CyclicRepetition: false

bbrinfo = info(bbr2)
bbrinfo = struct with fields:
    NumSamplesInData: 10000
            DataType: 'double'
      NumSamplesRead: 0

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

            Filename: '/tmp/Bdoc22b_2054784_3730881/tpa45d7b20/comm-ex94749964/baseband_samples_1ghz.bb'
          SampleRate: 1
     CenterFrequency: 100000000
         NumChannels: 1
            Metadata: [1x1 struct]
     SamplesPerFrame: 10000
    CyclicRepetition: false

Now read the entire contents of the baseband_samples_1ghz.bb file with a single call to the bbr object. Confirm that all the samples have been read and compare the samples read by bbr1 and bbr2.

samples2 = bbr2();
info(bbr2)
ans = struct with fields:
    NumSamplesInData: 10000
            DataType: 'double'
      NumSamplesRead: 10000

isequal(samples1,samples2)
ans = logical
   1

Release the baseband file reader resources.

release(bbr2)

Read a baseband signal from a file by using multiple calls to the baseband file reader System object™.

Create a baseband file reader object.

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

            Filename: '/tmp/Bdoc22b_2054784_3730881/tpa45d7b20/comm-ex87872352/baseband_samples_1ghz.bb'
          SampleRate: 1
     CenterFrequency: 100000000
         NumChannels: 1
            Metadata: [1x1 struct]
     SamplesPerFrame: 100
    CyclicRepetition: false

Use the info object function to gain additional information about the baseband file reader. The file contains 10,000 samples of data type double. No samples have been read.

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

The baseband file (baseband_samples_1ghz.bb) contains 10,000 samples. Because the number of samples per frame is set to 100 in the baseband file reader object, reading the entire contents of the baseband file requires multiple calls to the object. To read all of the samples from the file, use the isDone object function to terminate a while loop.

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

Use the info obejct function to confirm that all of the samples have been read from the file. The total number of samples and the number of samples read are the same.

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

Plot the absolute magnitude of the baseband data.

plot(abs(y))
title('Baseband Signal Read From File')
xlabel('Samples')
ylabel('Amplitude')

Figure contains an axes object. The axes object with title Baseband Signal Read From File contains an object of type line.

Release the baseband file reader resources.

release(bbr)

Extended Capabilities

Version History

Introduced in R2016b