Doing THD calc
This commit is contained in:
@@ -6,35 +6,25 @@ import IIR_filter
|
||||
|
||||
class zerocross_meas(object):
|
||||
"""docstring for fft_meas"""
|
||||
def __init__(self, fs=50e3, tn=1):
|
||||
self.fs = fs
|
||||
self.ts = 1/self.fs
|
||||
self.tn = tn
|
||||
self.time = 0
|
||||
self.freq = 0
|
||||
self.freq_ts = 0
|
||||
self.y = 0
|
||||
def __init__(self):
|
||||
|
||||
# Old value
|
||||
self.y_old = 0
|
||||
self.idx = 0
|
||||
self.LPfilter = IIR_filter.IIR_1_Order_LP(fs=self.fs, fc=200)
|
||||
|
||||
def step(self, x, time):
|
||||
|
||||
if time - self.time > self.ts:
|
||||
self.time = time
|
||||
self.y = self.LPfilter.step(x)
|
||||
|
||||
if self.y_old < 0 and self.y > 0:
|
||||
self.idx += 1
|
||||
# Zerocross flag
|
||||
self.flag = False
|
||||
|
||||
|
||||
if time - self.freq_ts > self.tn:
|
||||
self.freq = self.idx / self.tn
|
||||
self.freq_ts = time
|
||||
self.idx = 0
|
||||
def detect(self, y):
|
||||
|
||||
self.flag = 0
|
||||
|
||||
# If positive zerocross is detected
|
||||
if self.y_old < 0 and y > 0:
|
||||
self.flag = True
|
||||
|
||||
self.y_old = y
|
||||
|
||||
self.y_old = self.y
|
||||
|
||||
|
||||
def print(self):
|
||||
|
||||
Reference in New Issue
Block a user