diff --git a/src/backscattering_analyzer/analyzer.py b/src/backscattering_analyzer/analyzer.py index 89dbd4d..1d7525c 100644 --- a/src/backscattering_analyzer/analyzer.py +++ b/src/backscattering_analyzer/analyzer.py @@ -10,10 +10,10 @@ from numpy import loadtxt, array from scipy.io.matlab import loadmat # maths -from numpy import mean, zeros, pi, sin, cos, arange, sqrt +from numpy import mean, zeros, pi, sin, cos, arange, sqrt, where, real from scipy.signal import welch as psd from scipy.interpolate import CubicSpline - +from scipy.fft import fft, ifft, fftfreq class Analyzer: """ @@ -128,6 +128,7 @@ class Analyzer: ] ) self.movement[1] -= mean(self.movement[1]) + self.movement = self.movement[:,:-500000] def psd_signal(self, signal, fft_length=10): """ @@ -256,14 +257,8 @@ class Analyzer: ] ) - unpack = self.interpolate( - [factor_n, coupling_n, factor_d, coupling_d] - ) - factor_n, coupling_n, factor_d, coupling_d = ( - unpack[0], - unpack[1], - unpack[2], - unpack[3], + factor_n, coupling_n, factor_d, coupling_d = self.interpolate( + (factor_n, coupling_n, factor_d, coupling_d) ) frequencies = factor_n[0] @@ -273,8 +268,8 @@ class Analyzer: * self.settings.power_in / self.settings.power_out * ( - coupling_n[1] * factor_n[1] - + coupling_d[1] * factor_d[1] + sqrt(coupling_n[1]) * sqrt(factor_n[1]) + + sqrt(coupling_d[1]) * sqrt(factor_d[1]) ) ) return array( @@ -283,3 +278,14 @@ class Analyzer: result, ] ) + + def low_pass_filter(self, signal, cutoff): + """ + Cut higher frequencies than cutoff for a given temporal signal + """ + sample_spacing = signal[0,1] - signal[0,0] + freq_signal = fft(signal[1]) + frequencies = fftfreq(signal[1].shape[0], sample_spacing) + index_to_remove = where(abs(frequencies) > cutoff) + freq_signal[index_to_remove] = 0 + return array([signal[0], real(ifft(freq_signal))]) diff --git a/src/backscattering_analyzer/settings.py b/src/backscattering_analyzer/settings.py index 13c4a2c..ac6f00c 100644 --- a/src/backscattering_analyzer/settings.py +++ b/src/backscattering_analyzer/settings.py @@ -6,22 +6,20 @@ class Settings: self.version = "0.0.1" self.help = ( "[main]display[/main] [option]\\[options][/option]" - "\n [argument]-b --bench[argument] [description]bench of the experiment[/description]" - "\n [argument]-d --date[argument] [description]date of the experiment[/description]" - "\n [argument]-h --help[argument] [description]print this help and exit[/description]" - "\n [argument]-v --verbose[argument] [description]be verbose[/description]" - "\n [argument]-V --version[argument] [description]print version number and exit[/description]" + "\n [argument]-b --bench[/argument] [description]bench of the experiment[/description]" + "\n [argument]-d --date[/argument] [description]date of the experiment[/description]" + "\n [argument]-h --help[/argument] [description]print this help and exit[/description]" + "\n [argument]-v --verbose[/argument] [description]be verbose[/description]" + "\n [argument]-V --version[/argument] [description]print version number and exit[/description]" ) self.verbose = False self.bench = "SWEB" self.date = "2023_03_24" self.folder = Path("/home/demagny/data") - self.modelisation = "scatterCouplingO4.mat" + self.wavelength = 1.064e-6 # m + self.calib_bench = 1.15 self.calib_mirror = 1.15 - self.wavelength = 1.064e-6 # m - self.power_in = 23 # W - self.power_out = 8e-3 # W self.scattering_factor = [1e-17, 0] # parameter to change index = 0 @@ -112,6 +110,23 @@ class Settings: pass index += 1 + if self.date == "2023_03_24": + self.modelisation = "scatterCouplingO4.mat" + self.power_in = 23 # W + self.power_out = 8e-3 # W + elif self.date == "2023_12_21": + self.modelisation = "scatterCouplingMisalignSR.mat" + self.power_in = 12.1 # W + self.power_out = 8e-3 # W + elif self.date == "2024_01_21": + self.modelisation = "scatterCouplingMisalignSR.mat" + self.power_in = 12.1 # W + self.power_out = 8e-3 # W + else: + self.modelisation = "scatterCouplingO4.mat" + self.power_in = 23 # W + self.power_out = 8e-3 # W + def bench_file(self): return self.folder / ( "{bench}_{date}_ben.csv".format(