time_unit = 's' # --- create a synthetic signal --- eps = 0.5 # noise intensity alpha = 0.4 # AR1 parameter Nt = 500 # number of samples signal1 = ssg.create_noisy_chirp(T1=30 / dt, T2=50 / dt, Nt=Nt, eps=eps, alpha=alpha) # add slower oscillatory trend signal2 = ssg.create_chirp(T1=70 / dt, T2=70 / dt, Nt=Nt) # linear superposition signal = signal1 + 1.5 * signal2 # --- calculate trend --- trend = pyboat.sinc_smooth(signal, T_cut_off, dt) detr_signal = signal - trend # plot the signal/trend tvec = np.arange(len(signal)) * dt ax = pl.mk_signal_ax(time_unit='s') pl.draw_signal(ax, tvec, signal) # pl.draw_detrended(ax, tvec, signal) pl.draw_trend(ax, tvec, trend)
def create_signal(self): """ Retrieves all paramters from the synthesizer controls and calls the ssg. All line edits have validators set, however we have to check for intermediate empty inputs.. """ # the signal components components = [] weights = [] # number of sample points if not self.Nt_edit.hasAcceptableInput(): self.OutOfBounds = MessageWindow( "Minimum number of sample points is 10!", "Value Error") return self.Nt = int(self.Nt_edit.text()) if self.debug: print("Nt changed to:", self.Nt) self.set_initial_periods(force=True) self.set_initial_T_c(force=True) T_edits = [self.T11_edit, self.T12_edit, self.T21_edit, self.T22_edit] # check for valid inputs for T_e in T_edits: if self.debug: print(f"Is enabled: {T_e.isEnabled()}") print(f"Checking T_edits: {T_e.text()}") print(f"Validator output: {T_e.hasAcceptableInput()}") if not T_e.isEnabled(): continue if not T_e.hasAcceptableInput(): self.OutOfBounds = MessageWindow( "All periods must be greater than 0!", "Value Error") return # envelope before chirp creation if self.env_box.isChecked(): if not self.tau_edit.hasAcceptableInput(): self.OutOfBounds = MessageWindow("Missing envelope parameter!", "Value Error") return tau = float(self.tau_edit.text()) / self.dt env = ssg.create_exp_envelope(tau, self.Nt) if self.debug: print(f"Creating the envelope with tau = {tau}") else: env = 1 # no envelope if self.chirp1_box.isChecked(): if not self.A1_edit.hasAcceptableInput(): self.OutOfBounds = MessageWindow( "Set an amplitude for oscillator1!", "Value Error") return # the periods T11 = float(self.T11_edit.text()) / self.dt T12 = float(self.T12_edit.text()) / self.dt A1 = float(self.A1_edit.text()) chirp1 = ssg.create_chirp(T11, T12, self.Nt) components.append(env * chirp1) weights.append(A1) if self.chirp2_box.isChecked(): if not self.A2_edit.hasAcceptableInput(): self.OutOfBounds = MessageWindow( "Set an amplitude for oscillator2!", "Value Error") return T21 = float(self.T21_edit.text()) / self.dt T22 = float(self.T22_edit.text()) / self.dt A2 = float(self.A2_edit.text()) chirp2 = ssg.create_chirp(T21, T22, self.Nt) components.append(env * chirp2) weights.append(A2) # noise if self.noise_box.isChecked(): # QDoubleValidator is a screw up.. alpha = float(self.alpha_edit.text()) if not 0 < alpha < 1: self.OutOfBounds = MessageWindow( "AR1 parameter must be smaller than 1!", "Value Error") return if not self.d_edit.hasAcceptableInput(): self.OutOfBounds = MessageWindow("Missing noise parameters!", "Value Error") return d = float(self.d_edit.text()) noise = ssg.ar1_sim(alpha, self.Nt) components.append(noise) weights.append(d) if len(components) == 0: self.OutOfBounds = MessageWindow( "Activate at least one signal component!", "No Signal") return signal = ssg.assemble_signal(components, weights) # ---------------------------------------- self.raw_signal = signal self.tvec = self.dt * np.arange(self.Nt) # --------------------------------------- if self.debug: print("created synth. signal:", self.raw_signal[:10]) # plot right away self.set_initial_periods() self.set_initial_T_c() self.doPlot()