Main Content

SpectralMaskConfiguration

Display upper and lower spectral mask lines in the Spectrum Analyzer

    Description

    Use the SpectralMaskConfiguration object to overlay a spectral mask on a spectrum in the Spectrum Analyzer. If the mask is green, the signal is within the mask limits. If the mask is red, the signal fails the mask limits.

    You can check the status of the spectral mask from the scope toolbar, the command line, or event listeners.

    • To modify a spectral mask and see its status, in the scope toolbar, click the spectral mask button . You can modify the masks in the Spectral Mask tab on the Spectrum Analyzer toolstrip. Use the getSpectralMaskStatus function to obtain mask details, such as number of times a mask succeeded, number of times a mask failed, channels causing mask failure, and so on.

    • Use the MaskTestFailed event to perform an action every time the mask fails. To trigger a function when the mask fails, create a listener to the MaskTestFailed event and define a callback function to trigger. For more details about using events, see Events.

    Snapshot showing spectral mask.

    Creation

    Description

    example

    mask = SpectralMaskConfiguration() creates a spectral mask object.

    Properties

    expand all

    All properties are tunable.

    Spectral mask to enable, specified as "none", "lower", "upper", or "upper-and-lower".

    Scope Window Use

    Click the Spectral Mask tab on the Spectrum Analyzer toolstrip. In the Views section, select Upper Mask, Lower Mask, or both.

    The Spectral Mask tab appears when you:

    • Select Spectrum in the Analyzer tab.

    • In the drop-down list under Spectrum, choose either Power or Power Density.

    Data Types: char | string

    Limit for the upper spectral mask, specified as a scalar or two-column matrix.

    If UpperMask is a scalar, the upper limit mask uses the same power value for all frequencies specified in the Spectrum Analyzer.

    If UpperMask is a matrix, the first column contains the frequency values (Hz), which correspond to the x-axis values. The second column contains the power values, which correspond to the associated y-axis values.

    To apply offsets to the power and frequency values, use the ReferenceLevel and MaskFrequencyOffset properties.

    Scope Window Use

    Click the Spectral Mask tab on the Spectrum Analyzer toolstrip. In the Configuration section, specify Upper Limits.

    The Spectral Mask tab appears when you:

    • Select Spectrum in the Analyzer tab.

    • In the drop-down under Spectrum, choose either Power or Power Density.

    Data Types: double

    Limit for the lower spectral mask, specified as a scalar or two-column matrix.

    If LowerMask is a scalar, the lower limit mask uses the same power value for all frequencies specified in the Spectrum Analyzer.

    If LowerMask is a matrix, the first column contains the frequency values (Hz), which correspond to the x-axis values. The second column contains the power values, which correspond to the associated y-axis values.

    To apply offsets to the power and frequency values, use the ReferenceLevel and MaskFrequencyOffset property values.

    Scope Window Use

    Click the Spectral Mask tab on the Spectrum Analyzer toolstrip. In the Configuration section, specify Lower Limits.

    The Spectral Mask tab appears when you:

    • Select Spectrum in the Analyzer tab.

    • In the drop-down under Spectrum, choose either Power or Power Density.

    Data Types: double

    Reference level for mask power values, specified as either "custom" or "spectrum-peak".

    When you specify ReferenceLevel as "custom", the object uses the value you specify in the CustomReferenceLevel property as the reference to the power values (in dBr) in the UpperMask and LowerMask properties.

    When you specify ReferenceLevel as "spectrum-peak", the object uses the peak value of the current spectrum of the SelectedChannel as the reference power value.

    Scope Window Use

    Click the Spectral Mask tab on the Spectrum Analyzer toolstrip. In the Configuration section, set Reference Level (dBr) to either Spectrum peak or enter a real scalar.

    The Spectral Mask tab appears when you:

    • Select Spectrum in the Analyzer tab.

    • In the drop-down under Spectrum, choose either Power or Power Density.

    Data Types: char | string

    Custom reference level to the power values, specified as a real numeric scalar. The reference level should have the same units as the SpectrumUnits property of the Spectrum Analyzer. The reference level is the value to which the object references the power values in the UpperMask and LowerMask properties.

    Dependency

    To enable this property, set ReferenceLevel to "custom". This property uses the same units as the SpectrumUnits property of the Spectrum Analyzer.

    Scope Window Use

    Click the Spectral Mask tab on the Spectrum Analyzer toolstrip. In the Configuration section, set Reference Level (dBr) to either Spectrum peak or enter a real scalar.

    The Spectral Mask tab appears when you:

    • Select Spectrum in the Analyzer tab.

    • In the drop-down under Spectrum, choose either Power or Power Density.

    Data Types: double

    Input channel with peak spectrum to use as the mask reference level, specified as an integer.

    Dependency

    To enable this property, set ReferenceLevel to "spectrum-peak".

    Scope Window Use

    Click the Spectral Mask tab on the Spectrum Analyzer toolstrip. In the Configuration section, specify Channel as an integer.

    To enable Channel, set Reference Level (dBr) in the Configuration section to Spectrum peak and display some data on the scope.

    The Spectral Mask tab appears when you:

    • Select Spectrum in the Analyzer tab.

    • In the drop-down under Spectrum, choose either Power or Power Density.

    Frequency offset, specified as a finite numeric scalar. The object offsets the frequency values in the UpperMask and LowerMask properties by this value.

    Scope Window Use

    Click the Spectral Mask tab on the Spectrum Analyzer toolstrip. In the Configuration section, set Frequency Offset (Hz) to a real scalar.

    The Spectral Mask tab appears when you:

    • Select Spectrum in the Analyzer tab.

    • In the drop-down under Spectrum, choose either Power or Power Density.

    Data Types: double

    Object Functions

    getSpectralMaskStatusGet test results of current spectral mask

    Examples

    collapse all

    Create an upper spectral mask, set the reference level matrix, and add it to a Spectrum Analyzer object.

    mask = SpectralMaskConfiguration();
    mask.EnabledMasks = "upper";
    mask.UpperMask = [...
          0 -17; ...
         90 -17; ...
         90  30; ...
        110  30; ...
        110 -17; ...
        500 -17];
    
    scope = spectrumAnalyzer(PlotAsTwoSidedSpectrum=false,...
        ShowLegend=true);
    scope.SpectralMask = mask;
    scope.SpectralMask
    ans = 
      SpectralMaskConfiguration with properties:
    
                EnabledMasks: 'upper'
                   UpperMask: [6×2 double]
                   LowerMask: -Inf
              ReferenceLevel: 'custom'
        CustomReferenceLevel: 0
         MaskFrequencyOffset: 0
    
      Events for class SpectralMaskConfiguration: MaskTestFailed
    
    

    Run the spectrum analyzer using a sine wave spectrum. In the Spectral Mask panel at the bottom of the Spectrum Analyzer window, see how the spectrum succeeded or failed to stay within the spectral mask.

    sine = dsp.SineWave(Frequency=[98 100],SampleRate=1000);
    sine.SamplesPerFrame = 1024;   
    scope.SampleRate = sine.SampleRate;
    
    for i=1:100       
        scope(sine() + 0.05*randn(1024,2));
    end
    release(scope)

    Create a new model based on the dsp_basic_filter template. Add a spectral mask to the Spectrum Analyzer block in the model. Run the model.

    Masks are overlaid on the spectrum. If the mask is green, the signal is passing. If the mask is red, the signal is failing. The Spectral Mask panel shows what percentage of the time the mask is succeeding, which mask is failing, how many times the mask(s) failed, and which channels are causing the failure.

      [~,mdl] = fileparts(tempname);
      open_system(new_system(mdl,'FromTemplate','dsp_basic_filter'));
      saBlock = find_system(mdl,'BlockType','SpectrumAnalyzer');
    
      scopeConfig = get_param(saBlock{1},'ScopeConfiguration');
      upperMask = [0 50; 1200 50; 1200 -10; 24000 -10];
      scopeConfig.SpectralMask.UpperMask = upperMask;
      scopeConfig.SpectralMask.LowerMask = -100;
      scopeConfig.SpectralMask.EnabledMasks = 'Upper and lower';
    
      sim(mdl,'StopTime','20');
    

    Add a spectral mask to an existing spectrumAnalyzer object. Use the getSpectralMaskStatus function to get the spectral mask status.

    sine = dsp.SineWave(Frequency=[98 100],SampleRate=1000);
    sine.SamplesPerFrame = 1024;   
    scope = spectrumAnalyzer(SampleRate=sine.SampleRate,...
           PlotAsTwoSidedSpectrum=false,ShowLegend=true,YLimits=[-60 40]);
    hide(scope);
    
    scope.SpectralMask.EnabledMasks = "upper-and-lower";
    upperMask = [0 -10; 90 -10; 90 30; 110 30; 110 -10; 500 -10];
    set(scope.SpectralMask,UpperMask=upperMask,LowerMask=-55);
    
    for i=1:100       
        scope(sine() + 0.05*randn(1024,2));
    end
    
    res = getSpectralMaskStatus(scope)
    res = struct with fields:
        IsCurrentlyPassing: 1
            NumPassedTests: 50
             NumTotalTests: 50
               SuccessRate: 100
              FailingMasks: ''
           FailingChannels: [1×0 double]
            SimulationTime: 102.3990
    
    

    You can also view the status in the Spectral Mask tab on the Spectrum Analyzer toolstrip.

    show(scope);
    release(scope);

    Version History

    Introduced in R2022a