# Total Harmonic Distortion

Total harmonic distortion measurement

• Library:
• Simscape / Electrical / Control / Measurements

## Description

The Total Harmonic Distortion block calculates the total harmonic distortion (THD) percentage using these equations:

and

$%THD=100\frac{\sqrt{{\sum }_{i=2}^{n}{M}_{i}{}^{2}}}{{M}_{1}},$

where:

• Mi is the root mean squared (RMS) value of the harmonic magnitude that corresponds to the ith harmonic order.

• M is VRMS or IRMS.

• ${\sum }_{i=2}^{n}{M}_{i}{}^{2}$ is the sum of all harmonic components.

## Ports

### Input

expand all

Harmonic magnitude.

Data Types: `single` | `double`

### Output

expand all

Total harmonic distortion as a percentage.

Data Types: `single` | `double`

## Parameters

expand all

Fundamental frequency, in Hz.

Time between consecutive block executions. During execution, the block produces outputs and, if appropriate, updates its internal state. For more information, see What Is Sample Time? and Specify Sample Time.

For inherited discrete-time operation, specify `-1`. For discrete-time operation, specify a positive integer. For continuous-time operation, specify `0`.

To improve accuracy, set this value at least 10 times smaller than the Time constant parameter.

Note

If this block is in a masked subsystem, or another variant subsystem that allows either continuous or discrete operation, promote the sample time parameter to ensure correct switching between the continuous and discrete implementations of the block. For more information, see Promote Parameter to Mask.

## Extended Capabilities

### C/C++ Code GenerationGenerate C and C++ code using Simulink® Coder™.

Introduced in R2019b