Main Content

convertToFrames

Remove buffering from frames of frame-based signal

    Description

    example

    convertToFrames(sigObj) removes the buffering from each frame of the frame-based signal that corresponds to the Simulink.sdi.Signal object sigObj. For example, suppose sigObj is a frame-based signal with 64-by-2 sample values. The convertToFrames function interprets each 64-by-2 sample as 64 evenly spaced 1-by-2 samples.

    To convert the representation of a signal using the convertToFrames function, the signal must have a discrete sample rate, and the sample values must be nonscalar with fixed dimensions. The convertToFrames function does not support variable-size signals. The Simulation Data Inspector does not support converting frames for imported data.

    Examples

    collapse all

    Some applications buffer several samples of a signal into a frame to process with a single computation. When you log a frame-based signal to the Simulation Data Inspector, you can view and analyze the data for each frame using an array plot, or you can convert the representation of the signal data to undo the buffering.

    This example converts the representation of two frame-based signals from the model sfcndemo_frame, which:

    1. Samples a signal contaminated with noise using an analog to digital converter.

    2. Performs a discrete Fourier transform (DFT) on a frame of the sampled signal.

    3. Removes the noise from the signal in the frequency domain.

    4. Performs an inverse DFT on the filtered signal to return to the time domain.

    Simulating the model for this example requires a license for DSP System Toolbox™. Converting frame-based data in the Simulation Data Inspector does not require a license for DSP System Toolbox.

    Open and Simulate the Model

    Open the model sfcndemo_frame, then mark the time-domain signals for logging and give the signal lines a name.

    open_system('sfcndemo_frame');
    ADPort = get_param(find_system(gcs,  'FindAll', 'on', 'name', 'A/D Converter' ), 'PortHandles');
    set_param(ADPort.Outport,'DataLogging','on');
    
    ADLine = get_param(ADPort.Outport,'Line');
    set_param(ADLine,'Name','Noisy Signal');
    
    DAPort = get_param(find_system(gcs,  'FindAll', 'on', 'name', 'Remove trailing zeros' ), 'PortHandles');
    set_param(DAPort.Outport,'DataLogging','on');
    
    DALine = get_param(DAPort.Outport,'Line');
    set_param(DALine,'Name','Noise Removed Signal');

    Simulate the model.

    out = sim('sfcndemo_frame','StopTime','99.84');
    

    Access the Data in the Simulation Data Inspector

    Use the Simulink.sdi.getCurrentSimulationRun function to access the simulation data.

    runObj = Simulink.sdi.getCurrentSimulationRun('sfcndemo_frame');

    Use the getSignalsByName function to access the Simulink.sdi.Signal object for each of the time-domain signals, Noisy Signal and Noise Removed Signal.

    NoisySig = getSignalsByName(runObj,'Noisy Signal');
    NoNoiseSig = getSignalsByName(runObj,'Noise Removed Signal');

    Check the dimensions for a sample of each signal. The signal has two channels with a frame size of 64, resulting in sample values with dimensions 64-by-2. Because each sample is two-dimensional, the third dimension aligns with the time vector for the signal.

    size(NoisySig.Values.Data(:,:,1))
    ans = 1×2
    
        64     2
    
    
    size(NoNoiseSig.Values.Data(:,:,1))
    ans = 1×2
    
        64     2
    
    

    Convert the Signals to Remove the Frame Buffering

    To analyze the the data for each signal over the duration of the simulation, use the convertToFrames function to interpret the signal as frame-based.

    convertToFrames(NoisySig);
    convertToFrames(NoNoiseSig);

    Check the dimensions for a sample of each signal. After interpreting the signal as frame-based, each sample is a vector, so time aligns with the first dimension.

    size(NoisySig.Values.Data(1,:))
    ans = 1×2
    
         1     2
    
    
    size(NoNoiseSig.Values.Data(1,:))
    ans = 1×2
    
         1     2
    
    

    Because the resulting signal has fewer than four elements, the Simulation Data Inspector also automatically converts the signal to channels. The Run object now contains four signals.

    runObj.SignalCount
    ans = int32
        4
    

    You can access the Signal objects for each channel using the Children property for each of the original Signal objects.

    NoisyChannel1 = NoisySig.Children(1);
    NoisyChannel1.Name
    ans = 
    'Noisy Signal(1)'
    
    NoisyChannel2 = NoisySig.Children(2);
    NoisyChannel1.Name
    ans = 
    'Noisy Signal(1)'
    

    Each channel has scalar sample values.

    size(NoisyChannel1.Values.Data(1,:))
    ans = 1×2
    
         1     1
    
    

    Input Arguments

    collapse all

    Signal with data to convert, specified as a Simulink.sdi.Signal object. The convertToFrames function does not support variable-size signals.

    Introduced in R2021b