예제 #1
0
def differentlength_evaluation(input_generator,
                               branches,
                               Plot,
                               reference=None):
    length_ref = [2**15, 2**16, 2**17]
    length_iden = [2**15, 2**16, 2**17]
    input_generator_ref = input_generator
    input_generator_iden = input_generator
    for signal_length, ref_length in zip(length_iden, length_ref):
        input_generator_ref.SetLength(ref_length)
        input_ref = input_generator_ref.GetOutput()
        filter_spec_tofind = nlsp.log_weightingfilter(branches=branches,
                                                      input=input_ref)
        ref_nlsystem = nlsp.HammersteinGroupModel_up(
            input_signal=input_ref,
            nonlinear_functions=nlsp.nl_branches(
                nlsp.function_factory.power_series, branches),
            filter_irs=filter_spec_tofind,
            max_harmonics=range(1, branches + 1))

        sweep = nlsp.NovakSweepGenerator_Sine(
            sampling_rate=input_ref.GetSamplingRate(), length=len(input_ref))
        ref_nlsystem.SetInput(sweep.GetOutput())
        init_coeffs, non = nlsp.nonlinearconvolution_powerseries_temporalreversal(
            sweep, ref_nlsystem.GetOutput(), branches=branches)
        init_coeffs = nlsp.change_length_filterkernels(init_coeffs,
                                                       filter_length)
        ref_nlsystem.SetInput(input_ref)
        found_filter_spec, nl_functions = nlsp.adaptive_identification_legendre(
            input_generator=input_generator_ref,
            outputs=ref_nlsystem.GetOutput(),
            branches=branches,
            init_coeffs=init_coeffs)

        input_generator_iden.SetLength(signal_length)
        input_iden = input_generator_iden.GetOutput()
        iden_nlsystem = nlsp.HammersteinGroupModel_up(
            input_signal=input_iden,
            nonlinear_functions=nl_functions,
            filter_irs=found_filter_spec,
            max_harmonics=range(1, branches + 1))
        if reference is not None:
            reference = nlsp.change_length_signal(reference,
                                                  length=len(input_ref))
            ref_nlsystem.SetInput(reference)
            iden_nlsystem.SetInput(reference)

        if Plot is True:
            plot.relabelandplotphase(
                sumpf.modules.FourierTransform(
                    ref_nlsystem.GetOutput()).GetSpectrum(),
                "Reference Output", False)
            plot.relabelandplotphase(
                sumpf.modules.FourierTransform(
                    iden_nlsystem.GetOutput()).GetSpectrum(),
                "Identified Output", True)
        print "SNR between Reference(length:%r) and Identified output(length:%r) : %r" % (
            len(input_ref), len(input_iden),
            nlsp.snr(ref_nlsystem.GetOutput(), iden_nlsystem.GetOutput()))
예제 #2
0
def robustness_excitation_evaluation(input_generator,
                                     branches,
                                     Plot,
                                     reference=None):

    excitation_signal_amp = [0.5, 1.0]
    sample_signal_amp = [0.5, 1.0, 2.0]
    input = input_generator.GetOutput()
    for excitation_amp, sample_amp in itertools.product(
            excitation_signal_amp, sample_signal_amp):
        input_signal = sumpf.modules.AmplifySignal(
            input=input, factor=excitation_amp).GetOutput()
        sample_signal = nlsp.WhiteGaussianGenerator(
            sampling_rate=input_signal.GetSamplingRate(),
            length=len(input_signal),
            distribution=sumpf.modules.NoiseGenerator.UniformDistribution(
                minimum=-sample_amp, maximum=sample_amp))
        sample_signal = sample_signal.GetOutput()
        filter_spec_tofind = nlsp.log_weightingfilter(branches=branches,
                                                      input=input_signal)
        ref_nlsystem = nlsp.HammersteinGroupModel_up(
            input_signal=input_signal,
            nonlinear_functions=nlsp.nl_branches(
                nlsp.function_factory.power_series, branches),
            filter_irs=filter_spec_tofind,
            max_harmonics=range(1, branches + 1))
        sweep = nlsp.NovakSweepGenerator_Sine(
            sampling_rate=input_signal.GetSamplingRate(),
            length=len(input_signal))
        ref_nlsystem.SetInput(sweep.GetOutput())
        init_coeffs, non = nlsp.nonlinearconvolution_powerseries_temporalreversal(
            sweep, ref_nlsystem.GetOutput(), branches=branches)
        init_coeffs = nlsp.change_length_filterkernels(init_coeffs,
                                                       filter_length)
        ref_nlsystem.SetInput(input_signal)
        found_filter_spec, nl_functions = nlsp.adaptive_identification_legendre(
            input_generator=input_generator,
            outputs=ref_nlsystem.GetOutput(),
            branches=branches,
            init_coeffs=init_coeffs)
        iden_nlsystem = nlsp.HammersteinGroupModel_up(
            input_signal=sample_signal,
            nonlinear_functions=nl_functions,
            filter_irs=found_filter_spec,
            max_harmonics=range(1, branches + 1))
        ref_nlsystem.SetInput(sample_signal)
        if Plot is True:
            nlsp.relabelandplotphase(
                sumpf.modules.FourierTransform(
                    ref_nlsystem.GetOutput()).GetSpectrum(),
                "Reference Output Scaled", False)
            nlsp.relabelandplot(
                sumpf.modules.FourierTransform(
                    iden_nlsystem.GetOutput()).GetSpectrum(),
                "Identified Output", True)
        print "SNR between Scaled Identified with(amp:%r) and Tested with(amp:%r) output: %r" % (
            excitation_amp, sample_amp,
            nlsp.snr(ref_nlsystem.GetOutput(), iden_nlsystem.GetOutput()))
def differentlength_evaluation(input_generator,
                               branches,
                               iden_method,
                               Plot,
                               reference=None):
    """
    Evaluation of System Identification method by hgm virtual nl system
    nonlinear system - virtual hammerstein group model with power series polynomials as nl function and bandpass filters
                        as linear functions
    inputsignal - signal signal
    plot - the original filter spectrum and the identified filter spectrum, the reference output and identified output
    expectation - utmost similarity between the two spectrums
    """
    length_ref = [2**15, 2**16, 2**17]
    length_iden = [2**15, 2**16, 2**17]
    input_generator_ref = input_generator
    input_generator_iden = input_generator
    for signal_length, ref_length in zip(length_iden, length_ref):
        input_generator_ref.SetLength(ref_length)
        input_ref = input_generator_ref.GetOutput()
        filter_spec_tofind = nlsp.log_weightingfilter(branches=branches,
                                                      input=input_ref)
        ref_nlsystem = nlsp.HammersteinGroupModel_up(
            input_signal=input_ref,
            nonlinear_functions=nlsp.nl_branches(
                nlsp.function_factory.power_series, branches),
            filter_irs=filter_spec_tofind,
            max_harmonics=range(1, branches + 1))
        found_filter_spec, nl_functions = iden_method(input_generator,
                                                      ref_nlsystem.GetOutput(),
                                                      branches)

        input_generator_iden.SetLength(signal_length)
        input_iden = input_generator_iden.GetOutput()
        iden_nlsystem = nlsp.HammersteinGroupModel_up(
            input_signal=input_iden,
            nonlinear_functions=nl_functions,
            filter_irs=found_filter_spec,
            max_harmonics=range(1, branches + 1))
        if reference is not None:
            reference = nlsp.change_length_signal(reference,
                                                  length=len(input_ref))
            ref_nlsystem.SetInput(reference)
            iden_nlsystem.SetInput(reference)

        if Plot is True:
            plot.relabelandplotphase(
                sumpf.modules.FourierTransform(
                    ref_nlsystem.GetOutput()).GetSpectrum(),
                "Reference Output", False)
            plot.relabelandplotphase(
                sumpf.modules.FourierTransform(
                    iden_nlsystem.GetOutput()).GetSpectrum(),
                "Identified Output", True)
        print "SNR between Reference(length:%r) and Identified output(length:%r) : %r" % (
            len(input_ref), len(input_iden),
            nlsp.snr(ref_nlsystem.GetOutput(), iden_nlsystem.GetOutput()))
예제 #4
0
def hgmwithalphafilter_evaluation(input_generator,
                                  branches,
                                  nlfunction,
                                  Plot,
                                  label=None,
                                  reference=None):
    input_signal = input_generator.GetOutput()
    filter_spec_tofind = nlsp.log_weightingfilter(branches=branches,
                                                  input=input_signal)
    ref_nlsystem = nlsp.HammersteinGroupModel_up(
        input_signal=input_signal,
        nonlinear_functions=nlsp.nl_branches(nlfunction, branches),
        filter_irs=filter_spec_tofind,
        max_harmonics=range(1, branches + 1))

    sweep = nlsp.NovakSweepGenerator_Sine(
        sampling_rate=input_signal.GetSamplingRate(), length=len(input_signal))
    ref_nlsystem.SetInput(sweep.GetOutput())
    init_coeffs, non = nlsp.nonlinearconvolution_powerseries_temporalreversal(
        sweep, ref_nlsystem.GetOutput(), branches=branches)
    init_coeffs = nlsp.change_length_filterkernels(init_coeffs, filter_length)
    ref_nlsystem.SetInput(input_signal)
    found_filter_spec, nl_functions = nlsp.adaptive_identification_legendre(
        input_generator=input_generator,
        outputs=ref_nlsystem.GetOutput(),
        branches=branches,
        init_coeffs=init_coeffs)

    iden_nlsystem = nlsp.HammersteinGroupModel_up(
        input_signal=input_signal,
        nonlinear_functions=nl_functions,
        filter_irs=found_filter_spec,
        max_harmonics=range(1, branches + 1))
    if reference is not None:
        reference = nlsp.change_length_signal(reference,
                                              length=len(input_signal))
        ref_nlsystem.SetInput(reference)
        iden_nlsystem.SetInput(reference)
    if Plot is True:
        plot.relabelandplot(sumpf.modules.FourierTransform(
            ref_nlsystem.GetOutput()).GetSpectrum(),
                            "Reference Output",
                            show=False)
        plot.relabelandplot(sumpf.modules.FourierTransform(
            iden_nlsystem.GetOutput()).GetSpectrum(),
                            "Identified Output",
                            show=True)
    print "SNR between Reference and Identified output with weighted filtering: %r" % nlsp.snr(
        ref_nlsystem.GetOutput(), iden_nlsystem.GetOutput())
def differentbranches_evaluation(input_generator,
                                 branches,
                                 iden_method,
                                 Plot,
                                 reference=None):
    ref_branches = 3
    for branches in range(1, branches):
        input_signal = input_generator.GetOutput()

        filter_spec_tofind = nlsp.log_weightingfilter(branches=ref_branches,
                                                      input=input_signal)
        ref_nlsystem = nlsp.HammersteinGroupModel_up(
            input_signal=input_signal,
            nonlinear_functions=nlsp.nl_branches(
                nlsp.function_factory.power_series, ref_branches),
            filter_irs=filter_spec_tofind,
            max_harmonics=range(1, ref_branches + 1))

        found_filter_spec, nl_functions = iden_method(input_generator,
                                                      ref_nlsystem.GetOutput(),
                                                      branches)
        iden_nlsystem = nlsp.HammersteinGroupModel_up(
            input_signal=input_signal,
            nonlinear_functions=nl_functions,
            filter_irs=found_filter_spec,
            max_harmonics=range(1, branches + 1))
        if reference is not None:
            reference = nlsp.change_length_signal(reference,
                                                  length=len(input_signal))
            ref_nlsystem.SetInput(reference)
            iden_nlsystem.SetInput(reference)
        if Plot is True:
            plot.relabelandplotphase(
                sumpf.modules.FourierTransform(
                    ref_nlsystem.GetOutput()).GetSpectrum(),
                "Reference Output", False)
            plot.relabelandplotphase(
                sumpf.modules.FourierTransform(
                    iden_nlsystem.GetOutput()).GetSpectrum(),
                "Identified Output", True)
        print "SNR between Reference and Identified output : %r, with number of ref_branches: %r and iden_branches: %r" % (
            nlsp.snr(ref_nlsystem.GetOutput(),
                     iden_nlsystem.GetOutput()), ref_branches, branches)
def hgmwithalphafilter_evaluation(input_generator,
                                  branches,
                                  nlfunction,
                                  iden_method,
                                  Plot,
                                  label=None,
                                  reference=None):
    input_signal = input_generator.GetOutput()
    filter_spec_tofind = nlsp.log_weightingfilter(branches=branches,
                                                  input=input_signal)
    ref_nlsystem = nlsp.HammersteinGroupModel_up(
        input_signal=input_signal,
        nonlinear_functions=nlsp.nl_branches(nlfunction, branches),
        filter_irs=filter_spec_tofind,
        max_harmonics=range(1, branches + 1))
    found_filter_spec, nl_functions = iden_method(input_generator,
                                                  ref_nlsystem.GetOutput(),
                                                  branches)
    iden_nlsystem = nlsp.HammersteinGroupModel_up(
        input_signal=input_signal,
        nonlinear_functions=nl_functions,
        filter_irs=found_filter_spec,
        max_harmonics=range(1, branches + 1))
    if reference is not None:
        reference = nlsp.change_length_signal(reference,
                                              length=len(input_signal))
        ref_nlsystem.SetInput(reference)
        iden_nlsystem.SetInput(reference)
    if Plot is True:
        plot.relabelandplot(sumpf.modules.FourierTransform(
            ref_nlsystem.GetOutput()).GetSpectrum(),
                            "Reference Output",
                            show=False)
        plot.relabelandplot(sumpf.modules.FourierTransform(
            iden_nlsystem.GetOutput()).GetSpectrum(),
                            "Identified Output",
                            show=True)
    print "SNR between Reference and Identified output with weighted filtering: %r" % nlsp.snr(
        ref_nlsystem.GetOutput(), iden_nlsystem.GetOutput())
예제 #7
0
def adaptive_polynomial_evaluation_virtual():
    for input_generator, nlfunc in itertools.product(excitation, nl_functions):
        print input_generator
        print nlfunc
        input_signal = input_generator.GetOutput()
        filter_spec_tofind = nlsp.log_weightingfilter(branches=branches,
                                                      input=input_signal)
        ref_nlsystem = nlsp.HammersteinGroupModel_up(
            input_signal=input_signal,
            nonlinear_functions=nlsp.nl_branches(
                nlsp.function_factory.power_series, branches),
            filter_irs=filter_spec_tofind,
            max_harmonics=range(1, branches + 1))
        found_filter_spec, nl_func = nlsp.adaptive_identification(
            input_generator,
            ref_nlsystem.GetOutput(),
            branches,
            nonlinear_func=nlfunc)
        iden_nlsystem = nlsp.HammersteinGroupModel_up(
            input_signal=input_signal,
            nonlinear_functions=nl_func,
            filter_irs=found_filter_spec,
            max_harmonics=range(1, branches + 1))
        ref_nlsystem.SetInput(wgn_pink.GetOutput())
        iden_nlsystem.SetInput(wgn_pink.GetOutput())
        if Plot is True:
            plot.relabelandplot(sumpf.modules.FourierTransform(
                ref_nlsystem.GetOutput()).GetSpectrum(),
                                "Reference Output",
                                show=False)
            plot.relabelandplot(sumpf.modules.FourierTransform(
                iden_nlsystem.GetOutput()).GetSpectrum(),
                                "Identified Output",
                                show=True)
        print "SNR between Reference and Identified output without overlapping filters: %r" % nlsp.snr(
            ref_nlsystem.GetOutput(), iden_nlsystem.GetOutput())
        print
        print
def robustness_differentexcitation_evaluation(input_generator, branches,
                                              iden_method, Plot):
    input_signal = input_generator.GetOutput()
    sampling_rate = input_signal.GetSamplingRate()
    start_freq = input_generator.GetStartFrequency()
    stop_freq = input_generator.GetStopFrequency()
    length = len(input_signal)
    normal = sumpf.modules.NoiseGenerator.GaussianDistribution(
        mean=0.0, standard_deviation=1.0)
    uniform = sumpf.modules.NoiseGenerator.UniformDistribution()
    pink = sumpf.modules.NoiseGenerator.PinkNoise()
    laplace = sumpf.modules.NoiseGenerator.LaplaceDistribution(mean=0.0,
                                                               scale=0.3)

    sine = nlsp.NovakSweepGenerator_Sine(sampling_rate=sampling_rate,
                                         length=length,
                                         start_frequency=start_freq,
                                         stop_frequency=stop_freq)
    cos = nlsp.NovakSweepGenerator_Cosine(sampling_rate=sampling_rate,
                                          length=length,
                                          start_frequency=start_freq,
                                          stop_frequency=stop_freq)
    wgn_normal = nlsp.WhiteGaussianGenerator(sampling_rate=sampling_rate,
                                             length=length,
                                             start_frequency=start_freq,
                                             stop_frequency=stop_freq,
                                             distribution=normal)
    wgn_uniform = nlsp.WhiteGaussianGenerator(sampling_rate=sampling_rate,
                                              length=length,
                                              start_frequency=start_freq,
                                              stop_frequency=stop_freq,
                                              distribution=uniform)
    wgn_pink = nlsp.WhiteGaussianGenerator(sampling_rate=sampling_rate,
                                           length=length,
                                           start_frequency=start_freq,
                                           stop_frequency=stop_freq,
                                           distribution=pink)
    wgn_laplace = nlsp.WhiteGaussianGenerator(sampling_rate=sampling_rate,
                                              length=length,
                                              start_frequency=start_freq,
                                              stop_frequency=stop_freq,
                                              distribution=laplace)
    filter_spec_tofind = nlsp.log_weightingfilter(branches=branches,
                                                  input=input_signal)
    ref_nlsystem = nlsp.HammersteinGroupModel_up(
        input_signal=input_signal,
        nonlinear_functions=nlsp.nl_branches(
            nlsp.function_factory.power_series, branches),
        filter_irs=filter_spec_tofind,
        max_harmonics=range(1, branches + 1))
    found_filter_spec, nl_functions = iden_method(input_generator,
                                                  ref_nlsystem.GetOutput(),
                                                  branches)
    iden_nlsystem = nlsp.HammersteinGroupModel_up(
        input_signal=input_signal,
        nonlinear_functions=nl_functions,
        filter_irs=found_filter_spec,
        max_harmonics=range(1, branches + 1))
    inputs = [sine, cos, wgn_normal, wgn_uniform, wgn_pink, wgn_laplace]
    print "SNR between reference and identified output: %r" % (nlsp.snr(
        ref_nlsystem.GetOutput(), iden_nlsystem.GetOutput()))
    for input in inputs:
        ref_nlsystem.SetInput(input.GetOutput())
        iden_nlsystem.SetInput(input.GetOutput())
        if Plot is True:
            nlsp.relabelandplotphase(
                sumpf.modules.FourierTransform(
                    ref_nlsystem.GetOutput()).GetSpectrum(),
                "Reference Output Scaled", False)
            nlsp.relabelandplot(
                sumpf.modules.FourierTransform(
                    iden_nlsystem.GetOutput()).GetSpectrum(),
                "Identified Output", True)
        print "SNR between reference and identified output: %r for inputsignal: %r" % (
            nlsp.snr(ref_nlsystem.GetOutput(),
                     iden_nlsystem.GetOutput()), str(input))
        print
        print