Ejemplo n.º 1
0
def clippingHGMevaluation(input_generator, branches, Plot, reference=None):
    for t in range(8, 11):
        t = t / 10.0
        thresholds = [-t, t]
        input_signal = input_generator.GetOutput()
        nl_functions = [
            nlsp.function_factory.hardclip(thresholds),
        ] * branches
        filter_spec_tofind = nlsp.log_bpfilter(branches=branches,
                                               input=input_signal)
        ref_nlsystem = nlsp.HammersteinGroupModel_up(
            input_signal=input_signal,
            nonlinear_functions=nl_functions,
            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))
        # sine = sumpf.modules.SineWaveGenerator(frequency=5000.0,phase=0.0,samplingrate=input_signal.GetSamplingRate(),length=len(input_signal)).GetSignal()
        sine = sumpf.modules.SweepGenerator(
            samplingrate=input_signal.GetSamplingRate(),
            length=len(input_signal)).GetSignal()
        ref_nlsystem.SetInput(sine)
        iden_nlsystem.SetInput(sine)
        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 System",
                                show=False)
            plot.relabelandplot(sumpf.modules.FourierTransform(
                iden_nlsystem.GetOutput()).GetSpectrum(),
                                "Identified System",
                                show=False)
        print "SNR between Reference and Identified output for symmetric hardclipping HGM(thresholds:%r): %r" % (
            thresholds,
            nlsp.snr(ref_nlsystem.GetOutput(), iden_nlsystem.GetOutput()))
Ejemplo n.º 2
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()))
Ejemplo n.º 3
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()))
Ejemplo n.º 4
0
def hgmallpass_evaluation(input_generator,
                          branches,
                          nlfunction,
                          Plot,
                          reference=None):
    input_signal = input_generator.GetOutput()
    allpass = sumpf.modules.ImpulseGenerator(
        samplingrate=input_signal.GetSamplingRate(),
        length=len(input_signal)).GetSignal()
    filter_spec_tofind = [
        allpass,
    ] * branches
    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 System",
                            show=False)
        plot.relabelandplot(sumpf.modules.FourierTransform(
            iden_nlsystem.GetOutput()).GetSpectrum(),
                            "Identified System",
                            show=True)
    print "SNR between Reference and Identified output with all pass filters: %r" % nlsp.snr(
        ref_nlsystem.GetOutput(), iden_nlsystem.GetOutput())
Ejemplo n.º 5
0
def adaptive_differentnlfunctions():
    # generate virtual nonlinear system using HGM
    ref_nlsystem = nlsp.HammersteinGroupModel_up(nonlinear_functions=nlsp.nl_branches(nlsp.function_factory.power_series,branches),
                                                 filter_irs=filter_spec_tofind_noise,
                                                 max_harmonics=range(1,branches+1))

    # give input and get output from the virtual nlsystem
    ref_nlsystem.SetInput(input)
    output_noise = ref_nlsystem.GetOutput()
    input_noise = input

    # only noise based system identification
    found_filter_spec_adapt_power, nl_function_adapt_power = nlsp.adaptive_identification_powerseries(input_generator=input_noise,outputs=output_noise,
                                                                                                      branches=branches,iterations=i,filtertaps=filter_taps,Print=True)
    found_filter_spec_adapt_cheby, nl_function_adapt_cheby = nlsp.adaptive_identification_chebyshev(input_generator=input_noise,outputs=output_noise,
                                                                                                      branches=branches,iterations=i,filtertaps=filter_taps,Print=True)
    found_filter_spec_adapt_hermite, nl_function_adapt_hermite = nlsp.adaptive_identification_hermite(input_generator=input_noise,outputs=output_noise,
                                                                                                      branches=branches,iterations=i,filtertaps=filter_taps,Print=True)
    found_filter_spec_adapt_legendre, nl_function_adapt_legendre = nlsp.adaptive_identification_legendre(input_generator=input_noise,outputs=output_noise,
                                                                                                      branches=branches,iterations=i,filtertaps=filter_taps,Print=True)

    iden_nlsystem_adapt_power = nlsp.HammersteinGroupModel_up(max_harmonics=range(1,branches+1),nonlinear_functions=nl_function_adapt_power,
                                                  filter_irs=found_filter_spec_adapt_power)
    iden_nlsystem_adapt_cheby = nlsp.HammersteinGroupModel_up(max_harmonics=range(1,branches+1),nonlinear_functions=nl_function_adapt_cheby,
                                                  filter_irs=found_filter_spec_adapt_cheby)
    iden_nlsystem_adapt_hermite = nlsp.HammersteinGroupModel_up(max_harmonics=range(1,branches+1),nonlinear_functions=nl_function_adapt_hermite,
                                                  filter_irs=found_filter_spec_adapt_hermite)
    iden_nlsystem_adapt_legendre = nlsp.HammersteinGroupModel_up(max_harmonics=range(1,branches+1),nonlinear_functions=nl_function_adapt_legendre,
                                                  filter_irs=found_filter_spec_adapt_legendre)


    # set reference input to virtual nlsystem and identified nl system
    ref_nlsystem.SetInput(reference)
    iden_nlsystem_adapt_power.SetInput(reference)
    iden_nlsystem_adapt_cheby.SetInput(reference)
    iden_nlsystem_adapt_hermite.SetInput(reference)
    iden_nlsystem_adapt_legendre.SetInput(reference)

    # calculate snr value
    adaptive_powerseries_snr = nlsp.snr(ref_nlsystem.GetOutput(),iden_nlsystem_adapt_power.GetOutput())
    adaptive_chebyshev_snr = nlsp.snr(ref_nlsystem.GetOutput(),iden_nlsystem_adapt_cheby.GetOutput())
    adaptive_hermite_snr = nlsp.snr(ref_nlsystem.GetOutput(),iden_nlsystem_adapt_hermite.GetOutput())
    adaptive_legendre_snr = nlsp.snr(ref_nlsystem.GetOutput(),iden_nlsystem_adapt_legendre.GetOutput())

    # print snr value
    print "adaptive_powerseries_snr: %r" %adaptive_powerseries_snr
    print "adaptive_chebyshev_snr: %r" %adaptive_chebyshev_snr
    print "adaptive_hermite_snr: %r" %adaptive_hermite_snr
    print "adaptive_legendre_snr: %r" %adaptive_legendre_snr
def nlechocancellation(input):
    iden_nl_system, ref_nl_system = nlsystem(
        branches=branches,
        excitation=nl_system_iden_excitation,
        system_identification_alg=system_identification_alg)
    iden_nl_system.SetInput(input)
    echoic_op = echoic_nonlinear_chamber(input)
    desired_op = echoic_op - iden_nl_system.GetOutput()
    kernel, nlfunction = nlsp.adaptive_identification_legendre(
        iden_nl_system.GetOutput(), desired_op, branches=1, filtertaps=2**10)
    iden_lin_system = nlsp.HammersteinGroupModel_up(
        nonlinear_functions=nlfunction, filter_irs=kernel)
    iden_lin_system.SetInput(iden_nl_system.GetOutput())
    determined_output = iden_lin_system.GetOutput() + iden_nl_system.GetOutput(
    )
    speech = determined_output - desired_op
    return speech
Ejemplo n.º 7
0
def doublehgm_different_evaluation(input_generator,
                                   branches,
                                   Plot,
                                   reference=None):
    input_signal = input_generator.GetOutput()
    filter_spec_tofind1 = nlsp.log_bpfilter(branches=branches,
                                            input=input_signal)
    filter_spec_tofind2 = nlsp.log_chebyfilter(branches=branches,
                                               input=input_signal)

    sweep = nlsp.NovakSweepGenerator_Sine(
        sampling_rate=input_signal.GetSamplingRate(), length=len(input_signal))
    ref_nlsystem = nlsp.HammersteinGroup_Series(
        input_signal=sweep.GetOutput(),
        nonlinear_functions=(nlsp.nl_branches(
            nlsp.function_factory.power_series, branches),
                             nlsp.nl_branches(
                                 nlsp.function_factory.chebyshev1_polynomial,
                                 branches)),
        filter_irs=(filter_spec_tofind1, filter_spec_tofind2),
        max_harmonics=(range(1, branches + 1), range(1, branches + 1)),
        hgm_type=(nlsp.HammersteinGroupModel_up,
                  nlsp.HammersteinGroupModel_up))
    init_coeffs, non = nlsp.nonlinearconvolution_powerseries_temporalreversal(
        sweep, ref_nlsystem.GetOutput(2), branches=branches)
    init_coeffs = nlsp.change_length_filterkernels(init_coeffs, filter_length)
    ref_nlsystem = nlsp.HammersteinGroup_Series(
        input_signal=input_signal,
        nonlinear_functions=(nlsp.nl_branches(
            nlsp.function_factory.power_series, branches),
                             nlsp.nl_branches(
                                 nlsp.function_factory.chebyshev1_polynomial,
                                 branches)),
        filter_irs=(filter_spec_tofind1, filter_spec_tofind2),
        max_harmonics=(range(1, branches + 1), range(1, branches + 1)),
        hgm_type=(nlsp.HammersteinGroupModel_up,
                  nlsp.HammersteinGroupModel_up))
    found_filter_spec, nl_functions = nlsp.adaptive_identification_legendre(
        input_generator=input_generator,
        outputs=ref_nlsystem.GetOutput(2),
        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 = nlsp.HammersteinGroup_Series(
            input_signal=reference,
            nonlinear_functions=(
                nlsp.nl_branches(nlsp.function_factory.power_series, branches),
                nlsp.nl_branches(nlsp.function_factory.chebyshev1_polynomial,
                                 branches)),
            filter_irs=(filter_spec_tofind1, filter_spec_tofind2),
            max_harmonics=(range(1, branches + 1), range(1, branches + 1)),
            hgm_type=(nlsp.HammersteinGroupModel_up,
                      nlsp.HammersteinGroupModel_up))
        iden_nlsystem.SetInput(reference)
    if Plot is True:
        plot.relabelandplotphase(sumpf.modules.FourierTransform(
            ref_nlsystem.GetOutput(2)).GetSpectrum(),
                                 "Reference System",
                                 show=False)
        plot.relabelandplotphase(sumpf.modules.FourierTransform(
            iden_nlsystem.GetOutput()).GetSpectrum(),
                                 "Identified System",
                                 show=True)
    print "SNR between Reference and Identified output for double hgm different: %r" % nlsp.snr(
        ref_nlsystem.GetOutput(2), iden_nlsystem.GetOutput())
Ejemplo n.º 8
0
def hgmwithfilter_evaluation_sweepadaptive(input_generator,
                                           branches,
                                           nlfuntion,
                                           Plot,
                                           reference=None):
    input_signal = input_generator.GetOutput()
    # filter_spec_tofind = nlsp.create_bpfilter([2000,8000,30000],input_signal)
    filter_spec_tofind = nlsp.log_bpfilter(branches=branches,
                                           input=input_signal)
    # filter_spec_tofind = nlsp.log_chebyfilter(branches=branches,input=input_signal)
    ref_nlsystem = nlsp.HammersteinGroupModel_up(
        input_signal=input_signal,
        nonlinear_functions=nlsp.nl_branches(nlfuntion, 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())
    sweep_start = time.clock()
    init_coeffs, non = nlsp.nonlinearconvolution_powerseries_temporalreversal(
        sweep, ref_nlsystem.GetOutput(), branches=branches)
    sweep_stop = time.clock()
    init_coeffs = nlsp.change_length_filterkernels(init_coeffs, filter_length)
    ref_nlsystem.SetInput(input_signal)
    adapt_sweep_start = time.clock()
    found_filter_spec, nl_functions = nlsp.adaptive_identification_legendre(
        input_generator=input_generator,
        outputs=ref_nlsystem.GetOutput(),
        branches=branches,
        init_coeffs=init_coeffs,
        filtertaps=filter_length)
    adapt_sweep_stop = time.clock()
    adapt_start = time.clock()
    found_filter_spec, nl_functions = nlsp.adaptive_identification_legendre(
        input_generator=input_generator,
        outputs=ref_nlsystem.GetOutput(),
        branches=branches,
        filtertaps=filter_length)
    adapt_stop = time.clock()
    print "sweep_identification time %r" % (sweep_start - sweep_stop)
    print "sweep_adapt_identification time %r" % (adapt_sweep_start -
                                                  adapt_sweep_stop)
    print "adapt_identification time %r" % (adapt_start - adapt_stop)
    iden_nlsystem = nlsp.HammersteinGroupModel_up(
        input_signal=input_signal,
        nonlinear_functions=nl_functions,
        filter_irs=found_filter_spec,
        max_harmonics=range(1, branches + 1))
    # nlsp.filterkernel_evaluation_plot(filter_spec_tofind,found_filter_spec)
    # nlsp.filterkernel_evaluation_sum(filter_spec_tofind,found_filter_spec)
    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 without overlapping filters: %r" % nlsp.snr(
        ref_nlsystem.GetOutput(), iden_nlsystem.GetOutput())
Ejemplo n.º 9
0
def linearmodel_evaluation(input_generator,
                           branches,
                           nlfunction,
                           Plot,
                           reference=None):
    input_signal = input_generator.GetOutput()
    prp = sumpf.modules.ChannelDataProperties()
    prp.SetSignal(input_signal)
    filter_ir = sumpf.modules.FilterGenerator(
        filterfunction=sumpf.modules.FilterGenerator.BUTTERWORTH(order=10),
        frequency=10000.0,
        transform=False,
        resolution=prp.GetResolution(),
        length=prp.GetSpectrumLength()).GetSpectrum()
    ref_nlsystem = nlsp.AliasCompensatingHammersteinModelUpandDown(
        filter_impulseresponse=sumpf.modules.InverseFourierTransform(
            filter_ir).GetSignal())

    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))

    # linear system identification
    sweep = nlsp.NovakSweepGenerator_Sine(
        length=len(input_signal), sampling_rate=input_signal.GetSamplingRate())
    ref_nlsystem.SetInput(sweep.GetOutput())
    kernel_linear = nlsp.linear_identification_temporalreversal(
        sweep, ref_nlsystem.GetOutput())
    iden_linsystem = nlsp.AliasCompensatingHammersteinModelUpandDown(
        filter_impulseresponse=kernel_linear)

    if reference is not None:
        reference = nlsp.change_length_signal(reference,
                                              length=len(input_signal))
        ref_nlsystem.SetInput(reference)
        iden_linsystem.SetInput(reference)
        iden_nlsystem.SetInput(reference)
    if Plot is True:
        plot.relabelandplot(sumpf.modules.FourierTransform(
            ref_nlsystem.GetOutput()).GetSpectrum(),
                            "Reference System",
                            show=False)
        plot.relabelandplot(sumpf.modules.FourierTransform(
            iden_nlsystem.GetOutput()).GetSpectrum(),
                            "Identified System",
                            show=False)
        plot.relabelandplot(sumpf.modules.FourierTransform(
            iden_linsystem.GetOutput()).GetSpectrum(),
                            "Identified linear System",
                            show=True)
    print "SNR between Reference and Identified output for linear systems: %r" % nlsp.snr(
        ref_nlsystem.GetOutput(), iden_nlsystem.GetOutput())
    print "SNR between Reference and Identified output for linear systems(linear identification): %r" % nlsp.snr(
        ref_nlsystem.GetOutput(), iden_linsystem.GetOutput())
Ejemplo n.º 10
0
def adaptive_initializedwith_sweepidentification():
    # generate virtual nonlinear system using HGM
    ref_nlsystem = nlsp.HammersteinGroupModel_up(nonlinear_functions=nlsp.nl_branches(nlsp.function_factory.power_series,branches),
                                                 filter_irs=filter_spec_tofind_noise,
                                                 max_harmonics=range(1,branches+1))

    # give input and get output from the virtual nlsystem
    ref_nlsystem.SetInput(input)
    output_noise = ref_nlsystem.GetOutput()
    input_noise = input
    ref_nlsystem.SetInput(sine_g.GetOutput())
    output_sine = ref_nlsystem.GetOutput()
    ref_nlsystem.SetInput(cos_g.GetOutput())
    output_cos = ref_nlsystem.GetOutput()

    # only sine based system identification
    found_filter_spec_sine, nl_function_sine = nlsp.systemidentification("powerhgmbp1",nlsp.nonlinearconvolution_powerseries_temporalreversal,
                                                                         branches,sine_g,output_sine)
    iden_nlsystem_sine = nlsp.HammersteinGroupModel_up(max_harmonics=range(1,branches+1),nonlinear_functions=nl_function_sine,
                                                  filter_irs=found_filter_spec_sine)

    # only cosine based system identification
    found_filter_spec_cos, nl_function_cos = nlsp.systemidentification("powerhgmbp1",nlsp.nonlinearconvolution_chebyshev_temporalreversal,
                                                                         branches,cos_g,output_cos)
    iden_nlsystem_cos = nlsp.HammersteinGroupModel_up(max_harmonics=range(1,branches+1),nonlinear_functions=nl_function_cos,
                                                  filter_irs=found_filter_spec_cos)

    # only noise based system identification
    found_filter_spec_adapt, nl_function_adapt = nlsp.systemidentification("powerhgmbp1",nlsp.adaptive_identification_hermite,
                                                                           branches,wgn_normal_g,output_noise)
    iden_nlsystem_adapt = nlsp.HammersteinGroupModel_up(max_harmonics=range(1,branches+1),nonlinear_functions=nl_function_adapt,
                                                  filter_irs=found_filter_spec_adapt)

    # sine based as init coeff for noise based system identification
    found_filter_spec_sine_reducedlength = nlsp.change_length_filterkernels(found_filter_spec_sine,length=filter_taps)
    found_filter_spec_sineadapt_power, nl_function_sineadapt_power = nlsp.adaptive_identification_powerseries(input_generator=input_noise,outputs=output_noise,iterations=i,branches=branches,
                                                                   step_size=0.1,filtertaps=filter_taps,algorithm=nlsp.multichannel_nlms,Plot=False,init_coeffs=found_filter_spec_sine_reducedlength,Print=True)
    found_filter_spec_sineadapt_hermite, nl_function_sineadapt_hermite = nlsp.adaptive_identification_hermite(input_generator=input_noise,outputs=output_noise,iterations=i,branches=branches,
                                                                   step_size=0.1,filtertaps=filter_taps,algorithm=nlsp.multichannel_nlms,Plot=False,init_coeffs=found_filter_spec_sine_reducedlength,Print=True)
    found_filter_spec_sineadapt_legendre, nl_function_sineadapt_legendre = nlsp.adaptive_identification_legendre(input_generator=input_noise,outputs=output_noise,iterations=i,branches=branches,
                                                                   step_size=0.1,filtertaps=filter_taps,algorithm=nlsp.multichannel_nlms,Plot=False,init_coeffs=found_filter_spec_sine_reducedlength,Print=True)
    found_filter_spec_sineadapt_cheby, nl_function_sineadapt_cheby = nlsp.adaptive_identification_chebyshev(input_generator=input_noise,outputs=output_noise,iterations=i,branches=branches,
                                                                   step_size=0.1,filtertaps=filter_taps,algorithm=nlsp.multichannel_nlms,Plot=False,init_coeffs=found_filter_spec_sine_reducedlength,Print=True)
    iden_nlsystem_sineadapt_power = nlsp.HammersteinGroupModel_up(max_harmonics=range(1,branches+1),nonlinear_functions=nl_function_sineadapt_power,
                                                  filter_irs=found_filter_spec_sineadapt_power)
    iden_nlsystem_sineadapt_cheby = nlsp.HammersteinGroupModel_up(max_harmonics=range(1,branches+1),nonlinear_functions=nl_function_sineadapt_cheby,
                                                  filter_irs=found_filter_spec_sineadapt_cheby)
    iden_nlsystem_sineadapt_hermite = nlsp.HammersteinGroupModel_up(max_harmonics=range(1,branches+1),nonlinear_functions=nl_function_sineadapt_hermite,
                                                  filter_irs=found_filter_spec_sineadapt_hermite)
    iden_nlsystem_sineadapt_legendre = nlsp.HammersteinGroupModel_up(max_harmonics=range(1,branches+1),nonlinear_functions=nl_function_sineadapt_legendre,
                                                  filter_irs=found_filter_spec_sineadapt_legendre)

    # cos based as init coeff for noise based system identification
    found_filter_spec_cos_reducedlength = nlsp.change_length_filterkernels(found_filter_spec_cos,length=filter_taps)
    found_filter_spec_cosadapt_cheby, nl_function_cosadapt_cheby = nlsp.adaptive_identification_chebyshev(input_generator=input_noise,outputs=output_noise,iterations=i,branches=branches,
                                                                   step_size=0.1,filtertaps=filter_taps,algorithm=nlsp.multichannel_nlms,Plot=False,init_coeffs=found_filter_spec_cos_reducedlength,Print=True)
    found_filter_spec_cosadapt_power, nl_function_cosadapt_power = nlsp.adaptive_identification_powerseries(input_generator=input_noise,outputs=output_noise,iterations=i,branches=branches,
                                                                   step_size=0.1,filtertaps=filter_taps,algorithm=nlsp.multichannel_nlms,Plot=False,init_coeffs=found_filter_spec_cos_reducedlength,Print=True)
    found_filter_spec_cosadapt_legendre, nl_function_cosadapt_legendre = nlsp.adaptive_identification_legendre(input_generator=input_noise,outputs=output_noise,iterations=i,branches=branches,
                                                                   step_size=0.1,filtertaps=filter_taps,algorithm=nlsp.multichannel_nlms,Plot=False,init_coeffs=found_filter_spec_cos_reducedlength,Print=True)
    found_filter_spec_cosadapt_hermite, nl_function_cosadapt_hermite = nlsp.adaptive_identification_hermite(input_generator=input_noise,outputs=output_noise,iterations=i,branches=branches,
                                                                   step_size=0.1,filtertaps=filter_taps,algorithm=nlsp.multichannel_nlms,Plot=False,init_coeffs=found_filter_spec_cos_reducedlength,Print=True)

    iden_nlsystem_cosadapt_cheby = nlsp.HammersteinGroupModel_up(max_harmonics=range(1,branches+1),nonlinear_functions=nl_function_cosadapt_cheby,
                                                  filter_irs=found_filter_spec_cosadapt_cheby)
    iden_nlsystem_cosadapt_power = nlsp.HammersteinGroupModel_up(max_harmonics=range(1,branches+1),nonlinear_functions=nl_function_cosadapt_power,
                                                  filter_irs=found_filter_spec_cosadapt_power)
    iden_nlsystem_cosadapt_hermite = nlsp.HammersteinGroupModel_up(max_harmonics=range(1,branches+1),nonlinear_functions=nl_function_cosadapt_hermite,
                                                  filter_irs=found_filter_spec_cosadapt_hermite)
    iden_nlsystem_cosadapt_legendre = nlsp.HammersteinGroupModel_up(max_harmonics=range(1,branches+1),nonlinear_functions=nl_function_cosadapt_legendre,
                                                  filter_irs=found_filter_spec_cosadapt_legendre)


    # set reference input to virtual nlsystem and identified nl system
    ref_nlsystem.SetInput(reference)
    iden_nlsystem_sine.SetInput(reference)
    iden_nlsystem_cos.SetInput(reference)
    iden_nlsystem_adapt.SetInput(reference)
    iden_nlsystem_sineadapt_power.SetInput(reference)
    iden_nlsystem_sineadapt_cheby.SetInput(reference)
    iden_nlsystem_sineadapt_legendre.SetInput(reference)
    iden_nlsystem_sineadapt_hermite.SetInput(reference)
    iden_nlsystem_cosadapt_power.SetInput(reference)
    iden_nlsystem_cosadapt_cheby.SetInput(reference)
    iden_nlsystem_cosadapt_legendre.SetInput(reference)
    iden_nlsystem_cosadapt_hermite.SetInput(reference)

    # calculate snr value
    powerseries_snr = nlsp.snr(ref_nlsystem.GetOutput(),iden_nlsystem_sine.GetOutput())
    chebyshev_snr = nlsp.snr(ref_nlsystem.GetOutput(),iden_nlsystem_cos.GetOutput())
    adaptive_snr = nlsp.snr(ref_nlsystem.GetOutput(),iden_nlsystem_adapt.GetOutput())
    adaptivesine_power_snr = nlsp.snr(ref_nlsystem.GetOutput(),iden_nlsystem_sineadapt_power.GetOutput())
    adaptivesine_cheby_snr = nlsp.snr(ref_nlsystem.GetOutput(),iden_nlsystem_sineadapt_cheby.GetOutput())
    adaptivesine_hermite_snr = nlsp.snr(ref_nlsystem.GetOutput(),iden_nlsystem_sineadapt_hermite.GetOutput())
    adaptivesine_legendre_snr = nlsp.snr(ref_nlsystem.GetOutput(),iden_nlsystem_sineadapt_legendre.GetOutput())
    adaptivecos_power_snr = nlsp.snr(ref_nlsystem.GetOutput(),iden_nlsystem_cosadapt_power.GetOutput())
    adaptivecos_cheby_snr = nlsp.snr(ref_nlsystem.GetOutput(),iden_nlsystem_cosadapt_cheby.GetOutput())
    adaptivecos_legendre_snr = nlsp.snr(ref_nlsystem.GetOutput(),iden_nlsystem_cosadapt_legendre.GetOutput())
    adaptivecos_hermite_snr = nlsp.snr(ref_nlsystem.GetOutput(),iden_nlsystem_cosadapt_hermite.GetOutput())

    # print snr value
    print "SNR of powerseries nl convolution: %r" %powerseries_snr
    print "SNR of chebyshev nl convolution: %r" %chebyshev_snr
    print "SNR of adaptive: %r" %adaptive_snr
    print "SNR of adaptive sine power: %r" %adaptivesine_power_snr
    print "SNR of adaptive sine cheby: %r" %adaptivesine_cheby_snr
    print "SNR of adaptive sine hermite: %r" %adaptivesine_hermite_snr
    print "SNR of adaptive sine legendre: %r" %adaptivesine_legendre_snr
    print "SNR of adaptive cos power: %r" %adaptivecos_power_snr
    print "SNR of adaptive cos cheby: %r" %adaptivecos_cheby_snr
    print "SNR of adaptive cos legendre: %r" %adaptivecos_legendre_snr
    print "SNR of adaptive cos hermite: %r" %adaptivecos_hermite_snr