:param ip: DAQ IP
:param port: DAQ port
:param channel: DAQ channel, data type is List
:param maxTime: data save renew period(second) ## Default : 10*60(10min)
:param highPassFilter: 1 : OFF, 2 : ON, 3 : OFF + Detrend, 4 : ON + Detrend ## Default : 1(OFF)
:param currentExcitation: 1 : OFF, 2 : ON ## Default : 2(ON)
:param freqSpan: 1 : 128, 2 : 256, 3 : 512, 4 : 1024, 5 : 2048, 6 : 4096, 7 : 8192, 9 : 32768, 10 : 65536 ## Default : 3(512)
:param FFTLine: 1 : 128, 2 : 256, 3 : 512, 4 : 1024, 5 : 2048, 6 : 4096, 7 : 8192, 9 : 32768, 10 : 65536 ## Default : 4(1024)
:param windowType: 1 : Uniform, 2 : Hanning, 3 : Exponential, 4 : Flat-Top, 5 : Kaiser-Bessel ## Default : 5(Kaiser-Bessel)
:param overlap: 1: 0 %, 2: 25 %, 3: 50 %, 4: 75 %, 5: 90 % ## Default : 3(50%)
:param timeData: 1 : don't send, 2 : send ## Default : 2(send)
:param FFTData: 1 : don't send, 2 : send ## Default : 2(send)
## Calibration param
:param gain: ## Default : 1.00F. ex.) 1.00F → ±5.00V, 0.50F → ±2.50V
:param offset: ## Default: 0.00F. ex.) 0.10F → s(t) = ADC(t) + 0.10V, -0.30F → s(t) = ADC(t) - 0.30V
## Filter param
:param N: Section Number, dType is int
:param fGain: Filter Gain, dType is float list
:param fb: b values, dType is float list
:param fa: a values, dType is float list
:param kwargs: ## for param extension
TIMEdata, FFTdata csv 파일이 저장 될 디렉토리를 생성
DAQ 장비와 TCP 소켓 연결
사용할 채널에 각각 setup 메세지와 calibration 메세지 및 start 메세지를 DAQ 장비로 송신한다. (필요에 따라 filter coeffcient 메세지도 DAQ 장비로 송신)
Raw Data를 저장할 각 변수들을 동적으로 생성
filter coeffcient는 해당 라이브러리 내의 필터 함수들을 이용하여 산출 가능
DAQctrl = dh.DAQDataRequest(ip='192.168.1.5', port=500, channel=[1, 3, 4], maxTime=30, FreqSpan=3)
:param channel: seleted channel
send setup message to DAQ
Use this function after DAQ TCP socket connection
channel parameter is not List type but 'int' type
daqSetup(channel=3)
:param channel: seleted channel
send calibration message to DAQ
channel parameter is not List type but 'int' type
Use this function after DAQ TCP socket connection
daqCalibration(channel=3)
:param channel: seleted channel
send 'use filter' message to DAQ
channel parameter is not List type but 'int' type
Use this function after DAQ TCP socket connection
daqFilterCoefficient(channel=3)
:param channel: seleted channel
send start message to DAQ
channel parameter is not List type but 'int' type
Use this function after DAQ TCP socket connection
※ 해당 channel parameter에 0 번 대입 시 연결된 모든 채널에 start message를 송신, 상기 클래스에서는 0을 대입하여 사용
daqStart(channel=0)
-
send RTC reset message to DAQ
Use this function after DAQ TCP socket connection
daqRTCReset()
-
send DAQ reset message to DAQ
Use this function after DAQ TCP socket connection
daqReset()
-
send stop message to DAQ
DAQ는 해당 메세지 수신 후 DAQ는 데이터를 User에게 송신하지 않습니다.
Use this function after DAQ TCP socket connection
daqStop()
:param tID: Thread ID
:param filterSpec: DAQhandle 라이브러리의 함수를 이용한 filterSpec값(gain=None, offset=None, N=None, fGain=None, fb=None, fa=None에 대한 정보)을 대입(list)
=> spec.txt 파일에 데이터를 추가하기 위함
:param endtime: 얼마동안 데이터를 수신할 지 인터럽트 타임을 대입. 0이하는 무한루프, 이외에는 해당 sec만큼 동작
DAQ 장비로부터 실시간으로 Raq Data를 수신하며 Time data 및 FFT data(FFT데이터 수신을 ON 했을 경우)를 csv 파일에 저장하고 해당 시점의 DAQ setting에 관한 정보를 text 파일로 저장
해당 함수는 Thread를 이용하여 사용하는 것을 권장
DAQctrl = DAQDataRequest(ip='192.168.1.5', port=500, channel=[1, 3, 4], maxTime=30, FreqSpan=3, FFTLine=4)
getData = Thread(target=DAQctrl.daqDataRecv, args=(1, 10)) # 10초 동안만 데이터 수신
getData.setDaemon(True)
getData.start()
-
DAQ 장비로와의 소켓 연결을 정상 종료하는 매크로
stop_msg 함수, socket close, 열려있는 csv file을 close하는 기능을 수행
-
daqFinishProcess()
:param ch: seleted channel
:param amp: amplify time data
:param dB: FFT data multipled by log10, 0: do not multiple 1: apply log scale option to FFT data
선택된 채널의 Time data, FFT data를 리턴
amp 값을 Time data에 곱하여 증폭시킬 수 있음(출력 데이터에만 적용되고 csv 파일에는 원형의 Raw Data가 저장됨)
dB가 1일 때 FFT data에 로그스케일(10log)을 취하여 증폭시킬 수 있음(출력 데이터에만 적용되고 csv 파일에는 원형의 Raw Data가 저장됨)
timex: Time data 수신을 ON 했을 경우 해당 값이 return됨
timey: Time data 수신을 ON 했을 경우 해당 값이 return됨
ffty: FFT data 수신을 ON 했을 경우 해당 값이 return됨
Time data 수신을 OFF 할 경우 FFT data 데이터 또한 수신할 수 없음
timex, timey, ffty = daqSavedData(3, amp=1, dB=1)
:param data: raw data
:param type: set return type, 1: sos, 2: ba, 3: filtered data(numpy array)
:param fs: sampling frequency
:param lowCut: low cut frequency
:param highCut: high cut frequency
:param order: order value
:param bs: if you use band stop filter set this value 1
raw data에 Butter worth 필터를 적용
sos: ndarray, Second-order sections representation of the IIR filter.Only returned if ``output=='sos'``.
(type 1일 때 반환값)
b, a: ndarray, ndarray, Numerator (`b`) and denominator (`a`) polynomials of the IIR filter. Only returned if ``output='ba'``.
(type 2일 때 반환값)
y: filtered data (type 3일 때 반환값)
sos return 값은 DAQ protocol 메세지 중 filterCoefficient_msg 함수의 ba값으로 대입할 수 있음
sos 리스트의 길이는 filterCoefficient_msg 함수의 N(section number)에 해당함
실시간 Plotting시 상기 함수를 Filter Coefficient로 사용한다면 order는 N의 길이가 32가 넘지 않는 값으로 조정하여 사용해야함
sos = butterFilter(data=None, type=1, fs=1024, lowcut=0, highcut=10, order=5, bs=None)
b, a = butterFilter(data=rawdata, type=2, fs=1024, lowcut=0, highcut=10, order=5, bs=None)
y = butterFilter(data=rawdata, type=3, fs=1024, lowcut=0, highcut=10, order=5, bs=None)
:param data: raw data
:param type: set return type, 1: sos, 2: ba, 3: filtered data(numpy array)
:param fs: sampling frequency
:param lowCut: low cut frequency
:param highCut: High cut frequency
:param order: order value
:param rp: ripple value
:param bs: if you use band stop filter set this value 1
raw data에 Chebyshev 1 필터를 적용
sos: ndarray, Second-order sections representation of the IIR filter.Only returned if ``output=='sos'``.
(type 1일 때 반환값)
b, a: ndarray, ndarray, Numerator (`b`) and denominator (`a`) polynomials of the IIR filter. Only returned if ``output='ba'``.
(type 2일 때 반환값)
y: filtered data (type 3일 때 반환값)
sos return 값은 DAQ protocol 메세지 중 filterCoefficient_msg 함수의 ba값으로 대입할 수 있음
sos 리스트의 길이는 filterCoefficient_msg 함수의 N(section number)에 해당함
실시간 Plotting시 상기 함수를 Filter Coefficient로 사용한다면 order는 N의 길이가 32가 넘지 않는 값으로 조정하여 사용해야함
sos = cheby1Filter(data=None, type=1, fs=1024, lowcut=0, highcut=10, order=5, rp=5, bs=None)
b, a = cheby1Filter(data=rawdata, type=2, fs=1024, lowcut=0, highcut=10, order=5, rp=5 , bs=None)
y = cheby1Filter(data=rawdata, type=3, fs=1024, lowcut=0, highcut=10, order=5, rp=5 , bs=None)
:param data: raw data
:param type: set return type, 1: sos, 2: ba, 3: filtered data(numpy array)
:param fs: sampling frequency
:param lowCut: low cut frequency
:param highCut: high cut frequency
:param order: order value
:param att: attenuation value
:param bs: if you use band stop filter set this value 1
raw data에 Chebyshev 2 필터를 적용
sos: ndarray, Second-order sections representation of the IIR filter.Only returned if ``output=='sos'``.
(type 1일 때 반환값)
b, a: ndarray, ndarray, Numerator (`b`) and denominator (`a`) polynomials of the IIR filter. Only returned if ``output='ba'``.
(type 2일 때 반환값)
y: filtered data (type 3일 때 반환값)
sos return 값은 DAQ protocol 메세지 중 filterCoefficient_msg 함수의 ba값으로 대입할 수 있음
sos 리스트의 길이는 filterCoefficient_msg 함수의 N(section number)에 해당함
실시간 Plotting시 상기 함수를 Filter Coefficient로 사용한다면 order는 N의 길이가 32가 넘지 않는 값으로 조정하여 사용해야함
sos = cheby2Filter(data=None, type=1, fs=1024, lowcut=0, highcut=10, order=5, att=40, bs=None)
b, a = cheby2Filter(data=rawdata, type=2, fs=1024, lowcut=0, highcut=10, order=5, att=40 , bs=None)
y = cheby2Filter(data=rawdata, type=3, fs=1024, lowcut=0, highcut=10, order=5, att=40 , bs=None)
:param data: raw data
:param type: set return type, 1: sos, 2: ba, 3: filtered data(numpy array)
:param fs: sampling frequency
:param lowCut: low cut frequency
:param highCut: high cut frequency
:param order: order value
:param rp: ripple value
:param att: attenuation value
:param bs: if you use band stop filter set this value 1
raw data에 Elliptic 필터를 적용
sos: ndarray, Second-order sections representation of the IIR filter.Only returned if ``output=='sos'``.
(type 1일 때 반환값)
b, a: ndarray, ndarray, Numerator (`b`) and denominator (`a`) polynomials of the IIR filter. Only returned if ``output='ba'``.
(type 2일 때 반환값)
y: filtered data (type 3일 때 반환값)
sos return 값은 DAQ protocol 메세지 중 filterCoefficient_msg 함수의 ba값으로 대입할 수 있음
sos 리스트의 길이는 filterCoefficient_msg 함수의 N(section number)에 해당함
실시간 Plotting시 상기 함수를 Filter Coefficient로 사용한다면 order는 N의 길이가 32가 넘지 않는 값으로 조정하여 사용해야함
sos = ellipFilter(data=None, type=1, fs=1024, lowcut=0, highcut=10, order=5, rp=5, att=40 , bs=None)
b, a = ellipFilter(data=rawdata, type=2, fs=1024, lowcut=0, highcut=10, order=5, rp=5, att=40 , bs=None)
y = ellipFilter(data=rawdata, type=3, fs=1024, lowcut=0, highcut=10, order=5, rp=5, att=40 , bs=None)
:param data: raw data
:param type: set return type, 1: coeff, 2: y
:param fs: sampling frequency
:param lowCut: low cut frequency
:param highCut: high cut frequency
:param numtaps: int
Length of the filter (number of coefficients, i.e. the filter
order + 1). `numtaps` must be odd if a passband includes the
Nyquist frequency.
:param window : string or tuple of string and parameter values, optional
Desired window to use. See `scipy.signal.get_window` for a list
of windows and required parameters.
:param bs: if you use band stop filter set this value 1
numtaps를 홀수로 변환
raw data에 FIR 1 필터를 적용
coeff: Coefficient value (type 1일 때 반환값)
y: filtered data (type 2일 때 반환값)
This function computes the coefficients of a finite impulse response filter. The filter will have linear phase; it will be Type I if `numtaps` is odd and Type II if `numtaps` is even.
Type II filters always have zero response at the Nyquist frequency, so a ValueError exception is raised if firwin is called with `numtaps` even and
having a passband whose right end is at the Nyquist frequency.
coeff return 값은 DAQ protocol 메세지 중 filterCoefficient_msg 함수의 ba값으로 대입하기 위해
sos 리스트의 길이는 filterCoefficient_msg 함수의 N(section number)에 해당함
실시간 Plotting시 상기 함수를 Filter Coefficient로 사용한다면 order는 N의 길이가 32가 넘지 않는 값으로 조정하여 사용해야함
coeff = fir1Filter(type=1, fs=1024, lowcut=0, highcut=0, numtaps=3, window="hamming", bs=None)
[a.append(1) for i in b]
sos = tf2sos(b, a)
y = fir1Filter(rawdata, type=1, fs=1024, lowcut=0, highcut=0, numtaps=3, window="hamming", bs=None)
:param data: raw data
:param type: set return type, 1: coeff, 2: y
:param fs: sampling frequency
:param lowCut: low cut frequency
:param highCut: High cut frequency
:param numtaps: int type, Length of the filter (number of coefficients, i.e. the filter order + 1). `numtaps` must be odd if a passband includes the Nyquist frequency.
:param window : string or tuple of string and parameter values, optional Desired window to use. See `scipy.signal.get_window` for a list of windows and required parameters.
:param bs: if you use band stop filter set this value 1
numtaps를 짝수로 변환(HPF, BSP는 홀수로 사용)
raw data에 FIR 2필터를 적용
coeff: Coefficient value (type 1일 때 반환값)
y: filtered data (type 2일 때 반환값)
This function computes the coefficients of a finite impulse response filter. The filter will have linear phase; it will be Type I if `numtaps` is odd and Type II if `numtaps` is even.
Type II filters always have zero response at the Nyquist frequency, so a ValueError exception is raised if firwin is called with `numtaps` even and
having a passband whose right end is at the Nyquist frequency.
coeff return 값은 DAQ protocol 메세지 중 filterCoefficient_msg 함수의 ba값으로 대입하기 위해
sos 리스트의 길이는 filterCoefficient_msg 함수의 N(section number)에 해당함
실시간 Plotting시 상기 함수를 Filter Coefficient로 사용한다면 order는 N의 길이가 32가 넘지 않는 값으로 조정하여 사용해야함
coeff = fir2Filter(type=1, fs=1024, lowcut=0, highcut=0, numtaps=3, window="hamming", bs=None)
[a.append(1) for i in b]
sos = tf2sos(b, a)
y = fir2Filter (rawdata, type=1, fs=1024, lowcut=0, highcut=0, numtaps=3, window="hamming", bs=None)
:param ch: channel receiving raw data to apply python filter
:param filterType: 0: raw Data, 1: butter_filter, 2: cheby1_filter, 3: cheby2_filter, 4: ellip_filter, 5: fir1_filter, 6: fir2_filter
:param fs: sampling frequency
:param lowCut: low cut frequency
:param highCut: high cut frequency
:param order: order value
:param bs: if you use band stop filter set this value 1
Python 필터를 이용해 필터된 Raw Data(Time data)를 fft하는 함수
fftx: sampling frequency만큼의 x축 생성
yf: time 데이터를 FFT한 결과
real time plotting에서만 사용 권장
plotting 시 x축의 길이를 sampling frequency의 절반으로 잘라서 사용할 것
from QoTLib import DAQhandle as dh
import matplotlib.pyplot as plt
x, y = dh.transFFT(ch=3, fs=1024, filterType=1, lowcut=40)
plt.plot(x, abs(y))
plt.xlim([0, 512])
plt.pause(0.1)
plt.show()
:param data: time data
:param view: 1: Upper, 2: Lower, 3: Both
:param type: 1: distance, 2: prominence, 3: width
:param Val: distance => use when type 1 On, prominence => use when type 2 On, width => use when type 3 On
distance : number, optional. Required minimal horizontal distance (>= 1) in samples between neighbouring peaks. Smaller peaks are removed first until the condition is fulfilled for all remaining peaks.
prominence : number or ndarray or sequence, optional. Required prominence of peaks. Either a number, ``None``, an array matching `x` or a 2-element sequence of the former. The first element is always interpreted as the minimal and the second, if supplied, as the maximal required prominence.
width : number or ndarray or sequence, optional. Required width of peaks in samples. Either a number, ``None``, an array matching `x` or a 2-element sequence of the former. The first element is always interpreted as the minimal and the second, if supplied, as the maximal required width.
Time data를 이용해 Envelope Detect를 수행
x(p): ndarray. Indices of peaks in `x` that satisfy all given conditions.
prop(pprop): dict. A dictionary containing properties of the returned peaks which were calculated as intermediate results during evaluation of the specified conditions
m: max peak x값의 index를 반환 (view 3일 때만 return)
mprop: max peak와 관련된 dictionary를 반환 (view 3일 때만 return)
x(p)와 m은 유사한 반환값을 가지나 view가 1 또는 2일 경우 x만 반환됨(소스코드 참조)
prop(pprop), mprop의 key :
* 'peak_heights'
If `height` is given, the height of each peak in `x`.
* 'left_thresholds', 'right_thresholds'
If `threshold` is given, these keys contain a peaks vertical
distance to its neighbouring samples.
* 'prominences', 'right_bases', 'left_bases'
If `prominence` is given, these keys are accessible. See
`peak_prominences` for a description of their content.
* 'width_heights', 'left_ips', 'right_ips'
If `width` is given, these keys are accessible. See `peak_widths`
for a description of their content.
* 'plateau_sizes', left_edges', 'right_edges'
If `plateau_size` is given, these keys are accessible and contain
the indices of a peak's edges (edges are still part of the
plateau) and the calculated plateau sizes.
peaks, prop = envelopDetect(data=rawdata, view=1, type=1, Val=None)
peaks1, prop1, peaks2, prop2 = envelopDetect(data=rawdata, view=3, type=1, Val=None)
:param evt: check close event in figure(matplotlib)
matplotlib을 이용해 Plotting 되고 있는 여러 창 중 하나(multi channel plotting 시)를 close시 해당 figure를 판별하여 정상종료하기 위한 함수
fig, ax = plt.subplots(figsize=(12.8, 7.2))
fig.canvas.mpl_connect('close_event', handle_close) # close btn handler
:param channel: data type is 'list', plotting channel
:param fs: sampling frequency
:param amp: amplify raw data(Time data)
:param maxTime: max x axis lenth (x axis is time axis)
:param dB: apply Log scale(log10) to FFT data
:param spectrogram: plotting spectrogram. 0: off/1: on
:param edOn: Envelope detect option. 0: off/1: on
:param view: 1: Upper, 2: Lower, 3: Both
:param edType: 1: distance, 2: prominence, 3: width
:param edVal: distance => use when type 1 On, prominence => use when type 2 On, width => use when type 3 On
:param yMin: y axis minimum value
:param yMax: y axis maximum value
:param dMethod: check design method is IIR or FIR. 1: IIR, 2: FIR. If FIR is selected, then plotting with python fir filter
:param lowCut: low cut frequency
:param highCut: high cut frequency
:param numtaps: int
Length of the filter (number of coefficients, i.e. the filter
order + 1). `numtaps` must be odd if a passband includes the
Nyquist frequency.
:param window : string or tuple of string and parameter values, optional
Desired window to use. See `scipy.signal.get_window` for a list
of windows and required parameters.
:param bs: if you use band stop filter set this value 1
DAQ로부터 받은 Raw data를 실시간 plotting하는 함수
DAQ로부터 실시간 data를 수신하고 있을 때에만 사용 가능
dMethod, lowcut, highcut, numtaps, window, bs parameter는 실시간 raw data를 FIR 필터를 이용해 Filtering할 때 사용되는 인자값이다.
reaTimePlotting(channel=[1, 3, 4], fs=1024, amp=1, maxtime=10, dB=1, specgram=0, edOn=1, view=1, edType=1, yMin=-1.5, yMax=5)
created with
HTML Editor .