Ejemplo n.º 1
0
    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()
Ejemplo n.º 2
0
dt = 1
wAn = WAnalyzer(periods, dt)

# create a bunch of chirp signals
# with diverging period over time
Nsignals = 50  # times 2
Tstart = 30  # initial period
Tmax = 50  # slowest signal
Nt = 500  # number of samples per signal
signals = [
    ssg.create_noisy_chirp(T1=Tstart, T2=Tend, Nt=Nt, eps=1)
    for Tend in np.linspace(Tstart, Tmax, Nsignals)
]

# add the same number of pure noise signals
noisy_ones = [ssg.ar1_sim(alpha=0.5, Nt=Nt) for i in range(Nsignals)]

# signals ids are just column numbers here
signals = pd.DataFrame(signals + noisy_ones).T

# get the the individual ridge readouts
ridge_results = {}

# store the individual time averaged Wavelet spectra
df_fouriers = pd.DataFrame(index=wAn.periods)

for ID in signals:

    wAn.compute_spectrum(signals[ID], do_plot=False)
    rd = wAn.get_maxRidge(smoothing_wsize=11)
    ridge_results[ID] = rd
Ejemplo n.º 3
0
import pandas as pd
from pyboat import WAnalyzer, ssg
from pyboat import plotting as pl
from pyboat.core import ar1_powerspec
import matplotlib.pyplot as ppl

# set up analyzing instance
periods = np.linspace(5, 80, 100)
dt = 1
wAn = WAnalyzer(periods, dt, p_max=20)

# create an ensemble of short AR(1) realizations
# in a real life scenario this would be the 'non-oscillatory'
# test signals
alpha = 0.7
signals = [ssg.ar1_sim(alpha, Nt=120) for i in range(100)]

# store the individual time averaged Wavelet spectra
df_fouriers = pd.DataFrame(index=wAn.periods)

# the individual Fourier estimates
for i, sig in enumerate(signals):

    wAn.compute_spectrum(sig, do_plot=False)
    df_fouriers[i] = wAn.get_averaged_spectrum()

# plot the Fourier spectra distribution
pl.Fourier_distribution(df_fouriers)

# compare to the theoretical spectrum,
# note the finite size effects suppressing the power for higher periods!