Loading files
This file is pinned to the selected release. Download the original to open it in your design tool.
import numpy as np
from scipy.fft import fft
def thd(data, n_periods): # total harmonic distortion
result = np.abs(fft(data))**2
result = result[1:int(len(result)/2)]
if n_periods is None:
ref = max(result)
else:
ref = result[n_periods-1]
return np.sqrt((sum(result)-ref) / ref)
c305a21f7This file is pinned to the selected release. Download the original to open it in your design tool.