V
Vinod Chauhan_28
Guest
Hello Everyone,
I had written some functions in a python file and now, I want to call those functions from my vb.net application on a click of a button. Please help me in achieving that. Python file name is Digital_filter.py. I am posting my python file below:
from scipy import signal
# from EEG import eeg_data
#import EEG
import array as arr
import numpy as np
sample_rate = 250
fs_Hz = 250.0 # assumed sample rate for the EEG data
nyquist_rate = sample_rate /2
gMax_Blocks = 32
gMax_Samples = 8
gMax_Channel = 4
# Cofficient for IIR filters
b2 = arr.array('d' ,[0.965080986344733, -0.242468320175764, 1.94539149412878, -0.242468320175764, 0.965080986344733])
a2 = arr.array('d' ,[1, -0.246778261129785, 1.94417178469135, -0.238158379221743, 0.931381682126902])
b = arr.array('d' ,[0.200138725658073, 0, -0.400277451316145, 0, 0.200138725658073])
a = arr.array('d' ,[1, -2.35593463113158, 1.94125708865521, -0.784706375533419, 0.199907605296834])
def apply_filter1hz_Highpass(output):
fc = 1 # Cut-off frequency of the filter
w = fc / (sample_rate / 2) # Normalize the frequency
b, a = signal.butter(2, w, "highpass")
x = signal.lfilter(b, a, output, 0)
return x
def apply_filter50hz_Notch(output):
# fc = 50 # Cut-off frequency of the filter
# Q = 25.0 # Quality factor
# fs = sample_rate # Sample frequency (Hz)
#
# b, a = signal.iirnotch(fc,Q,fs=fs)
freq_Hz = 50
bp_stop_Hz = freq_Hz + 3.0 * np.array([-1, 1]) # set the stop band
b, a = signal.butter(3, bp_stop_Hz / (fs_Hz / 2.0), 'bandstop') # create the filter
x = signal.lfilter(b, a, output, 0)
return x
def apply_filter60hz_Notch(output):
# fc = 60 # Cut-off frequency of the filter
# Q = 30.0 # Quality factor
# fs = sample_rate # Sample frequency (Hz)
#
# b, a = signal.iirnotch(fc,Q,fs=fs)
freq_Hz = 60
bp_stop_Hz = freq_Hz + 3.0 * np.array([-1, 1]) # set the stop band
b, a = signal.butter(3, bp_stop_Hz / (fs_Hz / 2.0), 'bandstop') # create the filter
x = signal.lfilter(b, a, output, 0)
x = signal.lfilter(b, a, output, 0)
return x
def apply_filter120hz_Notch(output):
# fc = 120 # Cut-off frequency of the filter
# Q = 60.0 # Quality factor
# fs = sample_rate # Sample frequency (Hz)
#
# b, a = signal.iirnotch(fc,Q,fs=fs)
freq_Hz = 120
bp_stop_Hz = freq_Hz + 3.0 * np.array([-1, 1]) # set the stop band
b, a = signal.butter(3, bp_stop_Hz / (fs_Hz / 2.0), 'bandstop') # create the filter
x = signal.lfilter(b, a, output, 0)
x = signal.lfilter(b, a, output, 0)
return x
Continue reading...
I had written some functions in a python file and now, I want to call those functions from my vb.net application on a click of a button. Please help me in achieving that. Python file name is Digital_filter.py. I am posting my python file below:
from scipy import signal
# from EEG import eeg_data
#import EEG
import array as arr
import numpy as np
sample_rate = 250
fs_Hz = 250.0 # assumed sample rate for the EEG data
nyquist_rate = sample_rate /2
gMax_Blocks = 32
gMax_Samples = 8
gMax_Channel = 4
# Cofficient for IIR filters
b2 = arr.array('d' ,[0.965080986344733, -0.242468320175764, 1.94539149412878, -0.242468320175764, 0.965080986344733])
a2 = arr.array('d' ,[1, -0.246778261129785, 1.94417178469135, -0.238158379221743, 0.931381682126902])
b = arr.array('d' ,[0.200138725658073, 0, -0.400277451316145, 0, 0.200138725658073])
a = arr.array('d' ,[1, -2.35593463113158, 1.94125708865521, -0.784706375533419, 0.199907605296834])
def apply_filter1hz_Highpass(output):
fc = 1 # Cut-off frequency of the filter
w = fc / (sample_rate / 2) # Normalize the frequency
b, a = signal.butter(2, w, "highpass")
x = signal.lfilter(b, a, output, 0)
return x
def apply_filter50hz_Notch(output):
# fc = 50 # Cut-off frequency of the filter
# Q = 25.0 # Quality factor
# fs = sample_rate # Sample frequency (Hz)
#
# b, a = signal.iirnotch(fc,Q,fs=fs)
freq_Hz = 50
bp_stop_Hz = freq_Hz + 3.0 * np.array([-1, 1]) # set the stop band
b, a = signal.butter(3, bp_stop_Hz / (fs_Hz / 2.0), 'bandstop') # create the filter
x = signal.lfilter(b, a, output, 0)
return x
def apply_filter60hz_Notch(output):
# fc = 60 # Cut-off frequency of the filter
# Q = 30.0 # Quality factor
# fs = sample_rate # Sample frequency (Hz)
#
# b, a = signal.iirnotch(fc,Q,fs=fs)
freq_Hz = 60
bp_stop_Hz = freq_Hz + 3.0 * np.array([-1, 1]) # set the stop band
b, a = signal.butter(3, bp_stop_Hz / (fs_Hz / 2.0), 'bandstop') # create the filter
x = signal.lfilter(b, a, output, 0)
x = signal.lfilter(b, a, output, 0)
return x
def apply_filter120hz_Notch(output):
# fc = 120 # Cut-off frequency of the filter
# Q = 60.0 # Quality factor
# fs = sample_rate # Sample frequency (Hz)
#
# b, a = signal.iirnotch(fc,Q,fs=fs)
freq_Hz = 120
bp_stop_Hz = freq_Hz + 3.0 * np.array([-1, 1]) # set the stop band
b, a = signal.butter(3, bp_stop_Hz / (fs_Hz / 2.0), 'bandstop') # create the filter
x = signal.lfilter(b, a, output, 0)
x = signal.lfilter(b, a, output, 0)
return x
Continue reading...