## Choose a Simscape Electrical Function for an Offline Harmonic Analysis

### Harmonic Distortion

Nonlinear loads create power distortion in the form of harmonics, that is, voltages and currents that are multiples of the fundamental frequency. Harmonic waveforms can result in energy losses though heat dissipation and in reduced power quality. They can also cause equipment to malfunction or to become damaged. Standards development organizations such as the Institute of Electrical and Electronics Engineers (IEEE) and the International Electrotechnical Commission (IEC) define the recommended limits for harmonic content in electric power systems.

### Harmonic Analysis Functions

You can use the simulation and analysis functions in Simscape™ Electrical™ to perform an offline, that is post-simulation, analysis to examine harmonic distortion in your model. The `ee_plotHarmonics` function generates a bar chart. The `ee_getHarmonics` and `ee_calculateThdPercent` functions provide harmonic data in numerical form.

To decide which functions and workflows to use for your harmonic analysis, consider your goals. The table cross-references the harmonic functions with common harmonic analysis according to the data the function outputs and the task requires.

Goal`ee_plotHarmonics``ee_getHarmonics``ee_calculateThdPercent`
Evaluate the relative overall harmonic distortion
• Bar chart of the percentage of fundamental magnitude

• Fundamental peak value

• Total harmonic distortion (THD) percentage

Compare the harmonic distortion to standard limits
• Fundamental frequency

• Harmonic orders

• Harmonic magnitudes

Total harmonic distortion (THD) percentage

Determine the parameters for filtering harmonic distortion
• Fundamental frequency

• Harmonic orders

• Harmonic magnitudes

### Evaluate Relative Overall Harmonic Distortion

Use this workflow for a high-level understanding of the waveform distortion in your power system.

1. Enable Simscape data logging.

2. Save the logged voltage or current data to a variable.

3. Use the `ee_plotHarmonics` function to generate a bar chart of harmonic percentages with the peak fundamental magnitude and the total harmonic distortion (THD) percentage displayed in the plot title.

### Compare Harmonic Distortion to Standard Limits

Use this workflow to obtain values for evaluating the IEEE or IEC suitability of your power system.

1. Enable Simscape data logging.

2. Save the logged voltage or current data to a variable.

3. Use the `ee_getHarmonics` function to obtain the harmonic orders, the magnitude for each order, and the fundamental frequency.

4. Save the fundamental peak to a new variable.

5. Calculate the RMS voltage or current for each order.

6. Calculate the harmonic distortion percentage for individual harmonics.

7. Use the `ee_calculateThdPercent` function to obtain the total harmonic distortion (THD).

8. Compare the percentage data for each order and the THD percentage to the standard limits.

### Minimize Harmonic Distortion with Passive Filters

Use this workflow to determine the parameters for filtering the distorted waveforms with passive filters. Use individual, series-tuned filters for specific harmonic orders. Use a single high-pass filter to filter higher orders.

1. Enable Simscape data logging.

2. Save the logged voltage or current data in a variable.

3. Use the `ee_getHarmonics` function to obtain the harmonic orders, the magnitude for each order, and the fundamental frequency.

4. Identify the harmonic orders that you want to filter.

5. For each filter:

1. Specify the filter size, in terms of reactive power compensation, and specify the filter quality.

2. Calculate the capacitor reactance at the tuned harmonic order.

3. Calculate the filter capacitance.

4. Calculate the inductor reactance at the tuned harmonic order.

5. Calculate the filter inductance.

6. Calculate the filter resistance.

### Verify the Results of an Online Harmonic Analysis

You can examine harmonic distortion in your model online, that is during simulation, using the Simscape Spectrum Analyzer block. To verify the results from the Spectrum Analyzer block:

1. To determine the THD in your model, perform an online analysis. For information, see Perform an Online Harmonic Analysis Using the Simscape Spectrum Analyzer Block.

2. Use the `ee_getHarmonics` and `ee_calculateThdPercent` functions to determine the THD in your model.

3. Compare the THD values for the online and offline analyses. If the results differ, reconfigure the Spectrum Analyzer block.