Main Content

DistortionMeasurementsConfiguration

Compute and display harmonic and intermodulation distortion

    Description

    Use the DistortionMeasurementsConfiguration object to compute and display harmonic and intermodulation distortion.

    You can specify the distortion type, number of harmonics, and label the harmonics. You can control the distortion settings from the Spectrum Analyzer toolstrip or from the command line.

    To modify the distortion settings in the Spectrum Analyzer toolstrip, click the Measurements tab and edit the settings in the Distortion section.

    Snapshot showing distortion measurements.

    Creation

    Description

    example

    distmeas = DistortionMeasurementsConfiguration() creates a distortion measurements configuration object distmeas.

    Properties

    expand all

    All properties are tunable.

    Type of measurement data to display, specified as "harmonic" or "intermodulation".

    Scope Window Use

    Click the Measurements tab on the Spectrum Analyzer toolstrip. In the Distortion section, set Distortion Type to Harmonic or Intermodulation.

    The Measurements tab appears when you select Spectrum in the Analyzer tab.

    Data Types: char | string

    Number of harmonics to measure, specified as a positive integer less than or equal to 99.

    Dependency

    To enable this property, set Type to "harmonic".

    Scope Window Use

    Click the Measurements tab on the Spectrum Analyzer toolstrip. In the Distortion section, set Num Harmonics to a positive integer less than or equal to 99.

    The Measurements tab appears when you select Spectrum in the Analyzer tab.

    Data Types: double

    Label harmonics (for harmonic distortion) and frequency values (for intermodulation distortion), specified as true or false.

    Scope Window Use

    Click the Measurements tab on the Spectrum Analyzer toolstrip. In the Distortion section, select Label Harmonics.

    The Measurements tab appears when you select Spectrum in the Analyzer tab.

    Data Types: logical

    Enable distortion measurements, specified as true or false.

    Scope Window Use

    Click the Measurements tab on the Spectrum Analyzer toolstrip. In the Distortion section, select Distortion.

    The Measurements tab appears when you select Spectrum in the Analyzer tab.

    Data Types: logical

    Examples

    collapse all

    Compute and display the power spectrum of a noisy sinusoidal input signal using the spectrumAnalyzer MATLAB® object. Measure the peaks, cursor placements, adjacent channel power ratio, and distortion values in the spectrum by enabling these properties:

    • PeakFinder

    • CursorMeasurements

    • ChannelMeasurements

    • DistortionMeasurements

    Initialization

    The input sine wave has two frequencies: 1000 Hz and 5000 Hz. Create two dsp.SineWave System objects to generate these two frequencies. Create a spectrumAnalyzer object to compute and display the power spectrum.

    Fs = 44100;
    Sineobject1 = dsp.SineWave(SamplesPerFrame=1024,PhaseOffset=10,...
        SampleRate=Fs,Frequency=1000);
    Sineobject2 = dsp.SineWave(SamplesPerFrame=1024,...
        SampleRate=Fs,Frequency=5000);
    SA = spectrumAnalyzer(SampleRate=Fs,SpectrumType="power",...
        PlotAsTwoSidedSpectrum=false,ChannelNames={'Power spectrum of the input'},...
        YLimits=[-120 40],ShowLegend=true);
        

    Enable Measurements Data

    To obtain the measurements, set the Enabled property to true.

    SA.CursorMeasurements.Enabled = true;
    SA.ChannelMeasurements.Enabled = true;
    SA.PeakFinder.Enabled = true;
    SA.DistortionMeasurements.Enabled = true;

    Use getMeasurementsData

    Stream in the noisy sine wave input signal and estimate the power spectrum of the signal using the spectrum analyzer. Measure the characteristics of the spectrum. Use the getMeasurementsData function to obtain these measurements programmatically. The isNewDataReady function returns true when there is new spectrum data. Store the measured data in the variable data.

    data = [];
    for Iter = 1:1000
        Sinewave1 = Sineobject1();
        Sinewave2 = Sineobject2();
        Input = Sinewave1 + Sinewave2;
        NoisyInput = Input + 0.001*randn(1024,1);
        SA(NoisyInput);
         if SA.isNewDataReady
            data = [data;getMeasurementsData(SA)];
         end
    end

    The bottom of the spectrum analyzer shows the measurement panes you enabled. The values in these panes match the values in the last time step of the data variable. You can access the individual fields of data to obtain the various measurements programmatically.

    Compare Peak Values

    Use the PeakFinder property to obtain peak values. Verify that the peak values in the last time step of data match the values shown on the spectrum analyzer plot.

    peakvalues = data.PeakFinder(end).Value 
    peakvalues = 3×1
    
      -59.4124
      -59.8725
      -60.0010
    
    
    frequencieskHz = data.PeakFinder(end).Frequency/1000
    frequencieskHz = 3×1
    
        0.2799
        0.5383
        0.6029
    
    

    Version History

    Introduced in R2022a