Main Content

pe_getHarmonics

Return harmonic orders, magnitudes, and fundamental frequency

Description

example

[harmonicOrder,harmonicMagnitude,fundamentalFrequency] =...
pe_getHarmonics(loggingNode)
calculates the harmonic orders, magnitudes, and fundamental frequency of a simscape.logging.Node of an AC or periodic variable.

The function finds the points in the ith signal (valueIdx) where the Simscape™ log crosses a threshold (offsetOfInterest). It uses the crossing points to find the required number of periods (nPeriodOfInterest) preceding the specified time (tOfInterest). Then it inputs the down-selected data to the Goertzel algorithm, which calculates the harmonic magnitudes up to and including the required number of harmonics (nHarmonic).

You enter the input arguments in a specific order. The Simscape logging node input argument is required. All other input arguments are optional and have default values. If you are specifying a value for a subsequent optional input argument, enter [] to use the default value for an optional input argument.

You can use the pe_plotHarmonics function to obtain a bar chart from the same input arguments. You can use the outputs of this function as inputs to the pe_calculateThdPercent function to calculate the total harmonic distortion (THD) percentage.

[harmonicOrder,harmonicMagnitude,fundamentalFrequency] =...
pe_getHarmonics(loggingNode,valueIdx)
uses the index into value data.

[harmonicOrder,harmonicMagnitude,fundamentalFrequency] =...
pe_getHarmonics(loggingNode,valueIdx,tOfInterest)
uses the simulation time.

[harmonicOrder,harmonicMagnitude,fundamentalFrequency] =...
pe_getHarmonics(loggingNode,valueIdx,tOfInterest,nPeriodOfInterest)
uses the number of periods of fundamental frequency.

[harmonicOrder,harmonicMagnitude,fundamentalFrequency] =...
pe_getHarmonics(loggingNode,valueIdx,tOfInterest,nPeriodOfInterest,...
offsetOfInterest)
uses the DC offset.

[harmonicOrder,harmonicMagnitude,fundamentalFrequency] =...
pe_getHarmonics(loggingNode,valueIdx,tOfInterest,nPeriodOfInterest,...
offsetOfInterest,nHarmonic)
uses the number of harmonics.

Examples

Analyze Using Default Values

This set of function arguments uses the Simscape logging node simlog_ee_harmonics_rectifier.AC.N.V, which contains data from a three-phase voltage. The function analyzes the default signal, which is the first, or a-phase, signal at the final simulation time. The function uses the default values of 12 for the number of periods of the signal, 0V for the signal bias, and 30 for the number of harmonics.

open_system('ee_harmonics_rectifier')
sim('ee_harmonics_rectifier')
pe_getHarmonics(simlog_ee_harmonics_rectifier.AC.N.V)
ans =

  Columns 1 through 9

     0     1     2     3     4     5     6     7     8

  Columns 10 through 18

     9    10    11    12    13    14    15    16    17

  Columns 19 through 27

    18    19    20    21    22    23    24    25    26

  Columns 28 through 31

    27    28    29    30

Analyze Using Specified Values

This set of function arguments uses the Simscape logging node simlog_ee_harmonics_rectifier.AC.N.V, which contains data from a three-phase voltage. The function analyzes the second, or b-phase, signal at a simulation time of 0.5 s. The function uses 10 periods of the signal, which has a bias of 1 V. The function analyzes 15 harmonics.

open_system('ee_harmonics_rectifier')
sim('ee_harmonics_rectifier')
pe_getHarmonics(simlog_ee_harmonics_rectifier.AC.N.V,2,0.5,10,1,15)
ans =

  Columns 1 through 9

     0     1     2     3     4     5     6     7     8

  Columns 10 through 16

     9    10    11    12    13    14    15

Analyze Using Default and Specified Values

This set of function arguments uses the Simscape logging node simlog_ee_harmonics_rectifier.AC.N.V, which contains data from a three-phase voltage. The function analyzes the first, or a-phase, signal at a simulation time of 0.5 s. The function uses 12 periods of the signal, which has a bias of 1 V. The function analyzes the default number, 30, of harmonics.

open_system('ee_harmonics_rectifier')
sim('ee_harmonics_rectifier')
pe_getHarmonics(simlog_ee_harmonics_rectifier.AC.N.V,[],0.5,[],1)
ans =

  Columns 1 through 9

     0     1     2     3     4     5     6     7     8

  Columns 10 through 18

     9    10    11    12    13    14    15    16    17

  Columns 19 through 27

    18    19    20    21    22    23    24    25    26

  Columns 28 through 31

    27    28    29    30

Input Arguments

collapse all

Simscape logging node, specified as a 1-by-1 simscape.logging.Node. You create a simscape.logging.Node by running a simulation with Simscape logging enabled. For information, see Enable Simscape Data Logging for the Whole Model.

Example: simlog.Load.V

The Simscape logging node simlog.Load.V contains data from a three-phase voltage.

Index into value data, specified as a scalar. Specifies the ith variable of interest in the Simscape log.

Example: 2

Specify the b-phase, which is the second signal from a three-phase voltage.

Example: []

Use [] to specify the default value of 1. The a-phase, which is the first signal from a three-phase voltage, is the default signal of interest.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Simulation time of interest for harmonic analysis, specified as a scalar.

Example: 0.5

Specify a 0.5 s simulation time.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Number of periods of fundamental frequency to be included in harmonic analysis, specified as a scalar.

Example: 10

Specify 10 periods of the signal.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

DC offset in the input signal, specified as a scalar. The function uses this value to find the periods of interest.

Example: 1

Specify a bias of 1 V for the signal.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Number of harmonics to include in analysis, specified as a scalar.

Example: 15

Specify that the number of harmonics to be analyzed is 15.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Output Arguments

collapse all

Harmonic orders from 0 up to and including the number of harmonics used in the analysis, returned as a vector.

Harmonic magnitudes from the 0th harmonic up to and including the number of harmonics used in the analysis, returned as a vector.

Fundamental frequency over the range of the down-selected input data, returned as a scalar.

Limitations

  • This function requires that you use a fixed-step solver for the Simscape Electrical™ Power Systems network that you are analyzing. To specify a fixed-step solver for the physical network, use one of the configuration combinations in the table.

    Configuration CombinationGlobal Solver ConfigurationLocal Solver Configuration
    Global variable-step with local fixed-stepSet Type to Variable-stepEnable the options to Use local solver and Use fixed-cost runtime consistency iterations
    Global and local fixed-stepSet Type to Fixed-stepEnable the options to Use local solver and Use fixed-cost runtime consistency iterations
    Global fixed-stepSet Type to Fixed-stepClear the option to Use local solver

  • This function uses threshold crossing points to determine the fundamental frequency of the data. If your input data is noisy or crosses the threshold more frequently than half of the fundamental period, filter it before you use this function to analyze it.

  • This function requires a minimal number of periods. If the minimal number is not met, the function generates a warning message. To increase the number of periods, use one or both of these methods:

    • Increase the simulation time.

    • Increase the switching frequency.

Version History

Introduced in R2014a

expand all