42 lines
745 B
Python
42 lines
745 B
Python
import numpy as np
|
|
|
|
import matplotlib.pyplot as plt
|
|
import fft
|
|
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
|
|
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
|
|
|
|
|
|
if time - self.freq_ts > self.tn:
|
|
self.freq = self.idx / self.tn
|
|
self.freq_ts = time
|
|
self.idx = 0
|
|
|
|
|
|
self.y_old = self.y
|
|
|
|
|
|
def print(self):
|
|
print(self.freq)
|