필터 지우기
필터 지우기

How to calculate Total Harmonic Distortion (THD) by using matlab code from csv file

조회 수: 17 (최근 30일)
Hoang Le
Hoang Le 대략 19시간 전
댓글: Umar 대략 8시간 전
Hello everyone,
I have .csv exported from oscilloscope and I do not know how to calculate the THD (in percentage) from this file. The fundamental frequency is 60 Hz, and the file is about sinusoidal current waveform. Thank you so much for your help.
  댓글 수: 1
Umar
Umar 대략 7시간 전

Hi @Hoang Le ,

You are already familiar on how to read the data from the 'i7.csv' file using the readmatrix function in Matlab.

data = readmatrix('i7.csv');

Next, I set parameters by calculating the sample rate fs by multiplying the frequency f by 2. This is because the Nyquist theorem states that the sample rate should be at least twice the signal frequency. So, set the sample rate fs to 120 (adjusted for a 60Hz frequency) and the number of harmonics n to consider to 5.

fs = 120; % Adjusted sample rate for 60Hz frequency

n = 5; % Number of harmonics to consider

Afterwards, I calculate THD for multiple Ampere columns by iterating over columns 2 to 5 (assuming cur1 to cur5 are in columns 2 to 5) of the data matrix. So, for each column:

    * It selects the current column data and preprocesses it to handle non-finite values using isfinite(signal).
    * Calculates the THD value for the preprocessed signal using a custom thd function.
    * Converts the THD value to a percentage using the formula THD_percentage = 10^(THD_dBc/20).
    * Displays the THD value and THD percentage for the current column using disp.

Then, finally understanding the Output:

    * The output will show the THD value and THD percentage for each current column (cur1 to cur5).
    * THD is a measure of the harmonic distortion present in a signal, expressed in decibels (dBc). A lower THD percentage indicates a cleaner signal with fewer harmonic distortions.

For more information on thd function, please refer to

https://www.mathworks.com/help/signal/ref/thd.html

Please see attached results.

Hope this will help resolve your problem. Please let me know if you have any further questions.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Spectral Measurements에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by