# pe_getHarmonics

Return harmonic orders, magnitudes, and fundamental frequency

## Syntax

• ```[harmonicOrder,harmonicMagnitude,fundamentalFrequency] =... pe_getHarmonics(loggingNode)``` example
• ```[harmonicOrder,harmonicMagnitude,fundamentalFrequency] =...pe_getHarmonics(loggingNode,valueIdx) ``` example
• ```[harmonicOrder,harmonicMagnitude,fundamentalFrequency] =...pe_getHarmonics(loggingNode,valueIdx,tOfInterest)``` example
• ```[harmonicOrder,harmonicMagnitude,fundamentalFrequency] =...pe_getHarmonics(loggingNode,valueIdx,tOfInterest,nPeriodOfInterest)``` example
• ```[harmonicOrder,harmonicMagnitude,fundamentalFrequency] =... pe_getHarmonics(loggingNode,valueIdx,tOfInterest,nPeriodOfInterest,...offsetOfInterest)``` example
• ```[harmonicOrder,harmonicMagnitude,fundamentalFrequency] =... pe_getHarmonics(loggingNode,valueIdx,tOfInterest,nPeriodOfInterest,...offsetOfInterest,nHarmonic)``` example

## 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).Note:   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.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. You enter `[]` to use the default value for an optional input argument if you are going to specify a value for a subsequent 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.Load.V`, which contains data from a three-phase voltage. The function will analyze the default signal, which is the first, or a-phase, signal at the final simulation time. The function will use 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.

`pe_getHarmonics(simlog.Load.V)`

### Analyze using specified values

This set of function arguments uses the Simscape logging node `simlog.Load.V`, which contains data from a three-phase voltage. The function will analyze the second, or b-phase, signal at a simulation time of `2.3`s, The function will use `10` periods of the signal, which has a bias of `1`V. The function will analyze `15` harmonics.

`pe_getHarmonics(simlog.Load.V,2,2.3,10,1,15)`

### Analyze using default and specified values

This set of function arguments uses the Simscape logging node `simlog.Load.V`, which contains data from a three-phase voltage. The function will analyze the first, or a-phase, signal at a simulation time of `2.3`s, The function will use `12` periods of the signal, which has a bias of `1`V. The function will analyze the default number, `30`, of harmonics.

`pe_getHarmonics(simlog.Load.V,[],2.3,[],1)`

## Input Arguments

collapse all

### `loggingNode` — Simscape logging node1-by-1 simscape.logging.Node

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. See Enable Data Logging for the Whole Model to learn how to enable data logging.

Example: `simlog.Load.V`

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

### `valueIdx` — Index into value data`1` (default) | scalar

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`

### `tOfInterest` — Simulation timefinal time in Simscape log (default) | scalar

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

Example: `2.3`

Specify a 2.3s simulation time.

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

### `nPeriodOfInterest` — Number of periods`12` (default) | scalar

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`

### `offsetOfInterest` — DC offset`0` (default) | scalar

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`

### `nHarmonic` — Number of harmonics`30` (default) | scalar

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

### `harmonicOrder` — Harmonic ordervector

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

### `harmonicMagnitude` — Harmonic magnitudevector

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

### `fundamentalFrequency` — Fundamental frequencyscalar

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