diff --git a/functions.py b/functions.py index 8154be6..caced44 100644 --- a/functions.py +++ b/functions.py @@ -1,80 +1,96 @@ import scipy from scipy import signal import numpy as np import itertools def LowPass(data, ChimeraSettings, lowPass): """ Function used to filter data with a digital Bessel filter of the 4th order. Specially useful for high bandwidth recordings. Parameters ---------- data : Data to be filtered. samplerate : float Sampling frequency of the data aquisition. lowPass : float Cutoff frequency of the filter. Returns ------- output: a list of the currents filtered newsamplerate : float of new sampling frequency corresponding to 2*Cutoff frequency (Nyquist-Shannon sampling theorem). """ samplerate = ChimeraSettings.ADCSAMPLERATE Wn = round(2 * lowPass / samplerate, 4) # [0,1] nyquist frequency b, a = scipy.signal.bessel(4, Wn, btype='low', analog=False) # 4-th order digital filter z, p, k = signal.tf2zpk(b, a) eps = 1e-9 r = np.max(np.abs(p)) approx_impulse_len = int(np.ceil(np.log(eps) / np.log(r))) Filt_sig = (signal.filtfilt(b, a, data, method='gust', irlen=approx_impulse_len)) ds_factor = np.ceil(samplerate / (2 * lowPass)) output = {} output = scipy.signal.resample(Filt_sig, int(len(data) / ds_factor)) output = output[100:len(output)-100] newsamplerate = samplerate / ds_factor return output, newsamplerate def LowPassFast(data, ChimeraSettings, displaysubsample, lowPass): downsampled = signal.resample(data, int(1 / displaysubsample * len(data))) effsamplerate = (ChimeraSettings.ADCSAMPLERATE / displaysubsample) Wn = round(2 * lowPass / effsamplerate, 4) b, a = scipy.signal.bessel(4, Wn, btype='low', analog=False) z, p, k = signal.tf2zpk(b, a) eps = 1e-9 r = np.max(np.abs(p)) approx_impulse_len = int(np.ceil(np.log(eps) / np.log(r))) - Filt_sig = () output = signal.filtfilt(b, a, downsampled, method='gust', irlen=approx_impulse_len) output = output[100:len(output) - 100] return output, effsamplerate def EventDetection(inputtrace, Threshold=5, DwellTime=1): meanvalue = np.mean(inputtrace) stdeviation = np.std(inputtrace) limitdown = meanvalue - Threshold * stdeviation conditiondown = inputtrace < limitdown alldrops = [sum(1 for _ in group) for key, group in itertools.groupby(conditiondown) if key] downdrops = [item for item in alldrops if item>DwellTime] ndown = len(downdrops) if ndown == 0: ndown = False return ndown + + +def MakeAllVoltagesForIV(stepV, maxV): + NumberOfElements = int((2*maxV)/stepV+2) + AllVoltages = np.zeros(NumberOfElements) + + Counter = 1 + for i in range(1, int(NumberOfElements)-1): + if divmod(i, 2)[1]: + AllVoltages[i] = -stepV*Counter + else: + AllVoltages[i] = stepV*Counter + Counter += 1 + + print('IV Voltages: {}'.format(AllVoltages)) + + return AllVoltages \ No newline at end of file