def __init__(self):
        self.logger = initialize_logger(__name__)
        self.results = []  # Position list

        # Modify global constants

        global_vars.speed_of_sound_mps = 2000

        # create initial simulation signal

        sim_signal = None

        self.simulation_chain = Chain(sim_signal)

        self.simulation_chain.add_component(
            InputGenerationStage(measurement_period=2, duty_cycle=0.05))

        self.sigma = 0.01
        self.simulation_chain.add_component(
            GaussianNoise(mu=0, sigma=self.sigma))

        self.simulation_chain.add_component(
            IdealADCStage(num_bits=12,
                          quantization_method=QuantizationType.midtread))

        num_samples = int(
            10 *
            (global_vars.sampling_frequency /
             global_vars.signal_frequency))  # sample 10 cycles of the wave
        threshold = 0.05 * (2**11)
        self.simulation_chain.add_component(
            ThresholdCaptureTrigger(num_samples=num_samples,
                                    threshold=threshold))

        self.simulation_chain.add_component(CrossCorrelationStage())

        self.initial_guess = PolarPosition(10, np.pi)
        self.simulation_chain.add_component(
            NLSPositionCalc(optimization_type=OptimizationType.nelder_mead,
                            initial_guess=self.initial_guess))
import global_vars
from components.tdoa.phase_analysis import PhaseAnalysis
import numpy as np
from sim_utils import plt_utils as plt
import logging
from sim_utils.output_utils import initialize_logger

# create logger object for this module
logger = initialize_logger(__name__)


class PhaseAnalysisStage:
    def __init__(self):

        # always using hydrophone 0 as reference
        self.num_components = len(global_vars.hydrophone_positions) - 1

        self.components = []
        for i in range(self.num_components):
            identifier = "Phase Analysis" + "[%0d]" % (i + 1)
            self.components.append(PhaseAnalysis(identifier=identifier))

    def apply(self, sim_signal):
        # plot hydrophone signals if log level in debug mode
        level = logger.getEffectiveLevel()
        if level <= logging.DEBUG:
            plt.plot_signals(*sim_signal,
                             title="Sampled and Quantized Signals")

        phase_analysis_inputs = [(sim_signal[0], sim_signal[i + 1])
                                 for i in range(self.num_components)]
Beispiel #3
0
# sim_config = import_module(args.config)

# configure logging parameters
output_utils.configure_logger(args.log_level, args.config)

# contain dependency to config so must be imported afterwards
import sim_utils.plt_utils as plt
from sim_utils import config_parser
from experiments.experiment import Experiment

##################################################
# main Simulation Tasks
##################################################
if __name__ == "__main__":
    # create logger object for this module
    logger = output_utils.initialize_logger(__name__)

    # create initial simulation data frame from configuration file
    frame = config_parser.generate_frame(global_vars)

    # Import the module
    experiment_module = import_module(
        f'experiments.experiment{str(args.experiment)}')

    # Import the class
    Experiment_class = getattr(experiment_module,
                               f'Experiment{str(args.experiment)}')

    # Instantiate the class. Try loading from a previous run.
    experiment = Experiment_class.load()  # type: Experiment
    if experiment is None: