Exemple #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()))
Exemple #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()))
Exemple #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()))
Exemple #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())
Exemple #5
0
def wgnasreference():

    branches = 3
    sampling_rate = 48000.0
    length = 2**18
    start_freq = 100.0
    stop_freq = 20000.0
    fade_out = 0.00
    fade_in = 0.00
    filter_taps = 2**11

    # input generator
    sine_g = nlsp.NovakSweepGenerator_Sine(sampling_rate=sampling_rate,
                                           length=length,
                                           start_frequency=start_freq,
                                           stop_frequency=stop_freq,
                                           fade_out=fade_out,
                                           fade_in=fade_in)
    cos_g = nlsp.NovakSweepGenerator_Cosine(sampling_rate=sampling_rate,
                                            length=length,
                                            start_frequency=start_freq,
                                            stop_frequency=stop_freq,
                                            fade_out=fade_out,
                                            fade_in=fade_in)

    # real world reference system, load input and output noise and sweeps
    load_noise = sumpf.modules.SignalFile(
        filename=
        "C:/Users/diplomand.8/Desktop/nl_recordings/rec_4_ls/Noise18.npz",
        format=sumpf.modules.SignalFile.WAV_FLOAT)
    load_sine = sumpf.modules.SignalFile(
        filename="C:/Users/diplomand.8/Desktop/nl_recordings/rec_4_ls/sine.npz",
        format=sumpf.modules.SignalFile.WAV_FLOAT)
    load_cosine = sumpf.modules.SignalFile(
        filename="C:/Users/diplomand.8/Desktop/nl_recordings/rec_4_ls/cos.npz",
        format=sumpf.modules.SignalFile.WAV_FLOAT)
    output_noise = sumpf.modules.SplitSignal(data=load_noise.GetSignal(),
                                             channels=[1]).GetOutput()
    input_noise = sumpf.modules.SplitSignal(data=load_noise.GetSignal(),
                                            channels=[0]).GetOutput()
    output_sine = sumpf.modules.SplitSignal(data=load_sine.GetSignal(),
                                            channels=[1]).GetOutput()
    output_cos = sumpf.modules.SplitSignal(data=load_cosine.GetSignal(),
                                           channels=[1]).GetOutput()
    impulse = sumpf.modules.ImpulseGenerator(
        length=filter_taps, samplingrate=sampling_rate).GetSignal()

    # initialize hgm
    iden_nlsystem = nlsp.HammersteinGroupModel_up(
        max_harmonics=range(1, branches + 1),
        nonlinear_functions=nlsp.nl_branches(
            nlsp.function_factory.power_series, branches),
        filter_irs=[
            impulse,
        ] * branches)

    # only sine based system identification
    found_filter_spec_sine, nl_function_sine = nlsp.nonlinearconvolution_powerseries_temporalreversal(
        sine_g, output_sine, branches)
    iden_nlsystem.SetInput(signal=input_noise)
    iden_nlsystem.SetNLFunctions(nl_function_sine)
    iden_nlsystem.SetFilterIRS(found_filter_spec_sine)
    plot.relabelandplotphase(sumpf.modules.FourierTransform(
        iden_nlsystem.GetOutput()).GetSpectrum(),
                             "Identified power noise",
                             show=False)
    print "SNR between Reference and Identified output Sine: %r" % nlsp.snr(
        output_noise, iden_nlsystem.GetOutput())

    # only cosine based system identification
    found_filter_spec_cos, nl_function_cos = nlsp.nonlinearconvolution_chebyshev_temporalreversal(
        cos_g, output_cos, branches)
    iden_nlsystem.SetInput(signal=input_noise)
    iden_nlsystem.SetNLFunctions(nl_function_cos)
    iden_nlsystem.SetFilterIRS(found_filter_spec_cos)
    plot.relabelandplotphase(sumpf.modules.FourierTransform(
        iden_nlsystem.GetOutput()).GetSpectrum(),
                             "Identified cheby noise",
                             show=False)
    print "SNR between Reference and Identified output Cos: %r" % nlsp.snr(
        output_noise, iden_nlsystem.GetOutput())

    # only noise based system identification
    found_filter_spec_adapt, nl_function_adapt = nlsp.adaptive_identification(
        input_generator=input_noise,
        outputs=output_noise,
        iterations=1,
        branches=branches,
        step_size=0.1,
        filtertaps=filter_taps,
        algorithm=nlsp.multichannel_nlms,
        Plot=False)
    iden_nlsystem.SetInput(signal=input_noise)
    iden_nlsystem.SetNLFunctions(nl_function_adapt)
    iden_nlsystem.SetFilterIRS(found_filter_spec_adapt)
    plot.relabelandplotphase(sumpf.modules.FourierTransform(
        iden_nlsystem.GetOutput()).GetSpectrum(),
                             "Identified Adapt noise",
                             show=False)
    print "SNR between Reference and Identified output Adapt: %r" % nlsp.snr(
        output_noise, iden_nlsystem.GetOutput())

    # 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, nl_function_sineadapt = nlsp.adaptive_identification(
        input_generator=input_noise,
        outputs=output_noise,
        iterations=1,
        branches=branches,
        step_size=0.1,
        filtertaps=filter_taps,
        algorithm=nlsp.multichannel_nlms,
        Plot=False,
        init_coeffs=found_filter_spec_sine_reducedlength)
    iden_nlsystem.SetInput(signal=input_noise)
    iden_nlsystem.SetNLFunctions(nl_function_sineadapt)
    iden_nlsystem.SetFilterIRS(found_filter_spec_sineadapt)
    plot.relabelandplotphase(sumpf.modules.FourierTransform(
        iden_nlsystem.GetOutput()).GetSpectrum(),
                             "Identified power Adapt noise",
                             show=False)
    print "SNR between Reference and Identified output Sine Adapt: %r" % nlsp.snr(
        output_noise, iden_nlsystem.GetOutput())

    # 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, nl_function_cosadapt = nlsp.adaptive_identification(
        input_generator=input_noise,
        outputs=output_noise,
        iterations=1,
        branches=branches,
        step_size=0.1,
        filtertaps=filter_taps,
        algorithm=nlsp.multichannel_nlms,
        Plot=False,
        init_coeffs=found_filter_spec_cos_reducedlength,
        nonlinear_func=nlsp.function_factory.chebyshev1_polynomial)
    iden_nlsystem.SetInput(signal=input_noise)
    iden_nlsystem.SetNLFunctions(nl_function_cosadapt)
    iden_nlsystem.SetFilterIRS(found_filter_spec_cosadapt)
    plot.relabelandplotphase(sumpf.modules.FourierTransform(
        iden_nlsystem.GetOutput()).GetSpectrum(),
                             "Identified chebyshev Adapt noise",
                             show=False)
    print "SNR between Reference and Identified output Cos Adapt: %r" % nlsp.snr(
        output_noise, iden_nlsystem.GetOutput())

    plot.relabelandplotphase(
        sumpf.modules.FourierTransform(output_noise).GetSpectrum(),
        "Reference Noise",
        show=True)
Exemple #6
0
def loudspeaker_evaluation_all(branches=3, Plot=True):

    branches = branches
    sampling_rate = 48000.0
    length = 2**18
    start_freq = 100.0
    stop_freq = 20000.0
    fade_out = 0.02
    fade_in = 0.02
    filter_taps = 2**10
    iterations = 5
    source_dir = "C:/Users/diplomand.8/Desktop/nl_recordings/rec_4_db/"

    # input generator
    sine_g = nlsp.NovakSweepGenerator_Sine(sampling_rate=sampling_rate,
                                           length=length,
                                           start_frequency=start_freq,
                                           stop_frequency=stop_freq,
                                           fade_out=fade_out,
                                           fade_in=fade_in)
    cos_g = nlsp.NovakSweepGenerator_Cosine(sampling_rate=sampling_rate,
                                            length=length,
                                            start_frequency=start_freq,
                                            stop_frequency=stop_freq,
                                            fade_out=fade_out,
                                            fade_in=fade_in)

    # real world reference system, load input and output noise and sweeps
    load_noise = sumpf.modules.SignalFile(
        filename=os.path.join(source_dir, "Noise18.npz"),
        format=sumpf.modules.SignalFile.WAV_FLOAT)
    load_sine = sumpf.modules.SignalFile(
        filename=os.path.join(source_dir, "sine_f.npz"),
        format=sumpf.modules.SignalFile.WAV_FLOAT)
    load_cosine = sumpf.modules.SignalFile(
        filename=os.path.join(source_dir, "cos_f.npz"),
        format=sumpf.modules.SignalFile.WAV_FLOAT)
    load_sample = sumpf.modules.SignalFile(
        filename=os.path.join(source_dir, "Music1.npz"),
        format=sumpf.modules.SignalFile.WAV_FLOAT)
    output_sample = sumpf.modules.SplitSignal(data=load_sample.GetSignal(),
                                              channels=[1]).GetOutput()
    input_sample = sumpf.modules.SplitSignal(data=load_sample.GetSignal(),
                                             channels=[0]).GetOutput()
    output_sample = nlsp.change_length_signal(output_sample, 2**18)
    input_sample = nlsp.change_length_signal(input_sample, 2**18)
    output_noise = sumpf.modules.SplitSignal(data=load_noise.GetSignal(),
                                             channels=[1]).GetOutput()
    input_noise = sumpf.modules.SplitSignal(data=load_noise.GetSignal(),
                                            channels=[0]).GetOutput()
    output_sine = sumpf.modules.SplitSignal(data=load_sine.GetSignal(),
                                            channels=[1]).GetOutput()
    output_cos = sumpf.modules.SplitSignal(data=load_cosine.GetSignal(),
                                           channels=[1]).GetOutput()
    impulse = sumpf.modules.ImpulseGenerator(
        length=filter_taps, samplingrate=sampling_rate).GetSignal()

    # linear identification
    kernel_linear, nlfunc = nlsp.linear_identification(sine_g, output_sine,
                                                       branches)
    iden_nlsystem_linear = nlsp.HammersteinGroupModel_up(
        filter_irs=kernel_linear, nonlinear_functions=nlfunc)

    # linear identification
    kernel_linear_hgm, nlfunc_hgm = nlsp.linear_identification_powerhgm(
        sine_g, output_sine, branches)
    iden_nlsystem_linear_hgm = nlsp.HammersteinGroupModel_up(
        filter_irs=kernel_linear_hgm, nonlinear_functions=nlfunc_hgm)

    # only sine based system identification
    # found_filter_spec_sine, nl_function_sine = nlsp.systemidentification("LS",nlsp.nonlinearconvolution_powerseries_temporalreversal,
    #                                                                      branches,sine_g,output_sine)
    found_filter_spec_sine, nl_function_sine = nlsp.nonlinearconvolution_powerseries_temporalreversal(
        sine_g, output_sine, branches)
    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("LS",nlsp.nonlinearconvolution_chebyshev_temporalreversal,
    #                                                                    branches,cos_g,output_cos)
    found_filter_spec_cos, nl_function_cos = nlsp.nonlinearconvolution_chebyshev_temporalreversal(
        cos_g, output_cos, branches)
    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.adaptive_identification_legendre(input_generator=input_noise,outputs=output_noise,iterations=iterations,branches=branches,
    #                                                                step_size=0.1,filtertaps=filter_taps,algorithm=nlsp.multichannel_nlms,Plot=False)
    # 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, nl_function_sineadapt = nlsp.adaptive_identification_legendre(input_generator=input_noise,outputs=output_noise,iterations=iterations,branches=branches,
    #                                                                step_size=0.1,filtertaps=filter_taps,algorithm=nlsp.multichannel_nlms,Plot=False,init_coeffs=found_filter_spec_sine_reducedlength)
    # iden_nlsystem_sineadapt = nlsp.HammersteinGroupModel_up(max_harmonics=range(1,branches+1),nonlinear_functions=nl_function_sineadapt,
    #                                               filter_irs=found_filter_spec_sineadapt)

    # 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, nl_function_cosadapt = nlsp.adaptive_identification_powerseries(input_generator=input_noise,outputs=output_noise,iterations=iterations,branches=branches,
    #                                                                step_size=0.1,filtertaps=filter_taps,algorithm=nlsp.multichannel_nlms,Plot=False,init_coeffs=found_filter_spec_cos_reducedlength,
    #                                                                                 nonlinear_func=nlsp.function_factory.chebyshev1_polynomial)
    # iden_nlsystem_cosadapt = nlsp.HammersteinGroupModel_up(max_harmonics=range(1,branches+1),nonlinear_functions=nl_function_cosadapt,
    #                                               filter_irs=found_filter_spec_cosadapt)

    # set excitation as input
    iden_nlsystem_linear.SetInput(sine_g.GetOutput())
    iden_nlsystem_linear_hgm.SetInput(sine_g.GetOutput())
    iden_nlsystem_sine.SetInput(sine_g.GetOutput())
    iden_nlsystem_cos.SetInput(cos_g.GetOutput())
    # iden_nlsystem_adapt.SetInput(input_noise)
    # iden_nlsystem_sineadapt.SetInput(input_noise)
    # iden_nlsystem_cosadapt.SetInput(input_noise)
    plot.relabelandplot(
        sumpf.modules.FourierTransform(output_sine).GetSpectrum(),
        "Reference system",
        show=False)
    plot.relabelandplot(sumpf.modules.FourierTransform(
        iden_nlsystem_sine.GetOutput()).GetSpectrum(),
                        "Sweep based system identification",
                        show=False)
    plot.relabelandplot(sumpf.modules.FourierTransform(
        iden_nlsystem_linear.GetOutput()).GetSpectrum(),
                        "Linear identified system",
                        show=True)

    if Plot is True:
        # plot.relabelandplot(sumpf.modules.FourierTransform(iden_nlsystem_sine.GetOutput()).GetSpectrum(),"Identified power",show=False)
        plot.relabelandplot(
            sumpf.modules.FourierTransform(output_sine).GetSpectrum(),
            "Reference system",
            show=False)
        plot.relabelandplot(sumpf.modules.FourierTransform(
            iden_nlsystem_linear.GetOutput()).GetSpectrum(),
                            "Linear identified system",
                            show=False)
        plot.relabelandplot(sumpf.modules.FourierTransform(
            iden_nlsystem_sineadapt.GetOutput()).GetSpectrum(),
                            "sweep-adaptive output",
                            show=True)
    #     plot.relabelandplot(sumpf.modules.FourierTransform(iden_nlsystem_cos.GetOutput()).GetSpectrum(),"Identified cheby",show=False)
    #     plot.relabelandplot(sumpf.modules.FourierTransform(output_cos).GetSpectrum(),"Reference cheby",show=True)
    #     plot.relabelandplot(sumpf.modules.FourierTransform(iden_nlsystem_adapt.GetOutput()).GetSpectrum(),"Identified Adapt noise",show=False)
    #     plot.relabelandplot(sumpf.modules.FourierTransform(iden_nlsystem_sineadapt.GetOutput()).GetSpectrum(),"Identified power Adapt noise",show=False)
    #     plot.relabelandplot(sumpf.modules.FourierTransform(iden_nlsystem_cosadapt.GetOutput()).GetSpectrum(),"Identified chebyshev Adapt noise",show=False)
    #     plot.relabelandplot(sumpf.modules.FourierTransform(output_noise).GetSpectrum(),"Reference Adapt noise",show=True)

    print "SNR between Reference and Identified output linear: %r" % nlsp.snr(
        output_sine, iden_nlsystem_linear.GetOutput())
    print "SNR between Reference and Identified output linear hgm: %r" % nlsp.snr(
        output_sine, iden_nlsystem_linear_hgm.GetOutput())
    print "SNR between Reference and Identified output Powerseries NL convolution: %r" % nlsp.snr(
        output_sine, iden_nlsystem_sine.GetOutput())
    print "SNR between Reference and Identified output Chebyshev NL convolution: %r" % nlsp.snr(
        output_cos, iden_nlsystem_cos.GetOutput())
    print "SNR between Reference and Identified output Adaptive: %r" % nlsp.snr(
        output_noise, iden_nlsystem_adapt.GetOutput())
    print "SNR between Reference and Identified output Powerseries Adaptive: %r" % nlsp.snr(
        output_noise, iden_nlsystem_sineadapt.GetOutput())
    # print "SNR between Reference and Identified output Chebyshev Adaptive: %r" %nlsp.snr(output_noise, iden_nlsystem_cosadapt.GetOutput())

    # set sample as input
    iden_nlsystem_linear.SetInput(input_sample)
    iden_nlsystem_linear_hgm.SetInput(input_sample)
    iden_nlsystem_sine.SetInput(input_sample)
    iden_nlsystem_cos.SetInput(input_sample)
    iden_nlsystem_adapt.SetInput(input_sample)
    iden_nlsystem_sineadapt.SetInput(input_sample)
    # iden_nlsystem_cosadapt.SetInput(input_sample)

    # if Plot is True:
    #     plot.relabelandplot(sumpf.modules.FourierTransform(iden_nlsystem_sine.GetOutput()).GetSpectrum(),"Identified power",show=False)
    #     plot.relabelandplot(sumpf.modules.FourierTransform(iden_nlsystem_cos.GetOutput()).GetSpectrum(),"Identified cheby",show=False)
    #     plot.relabelandplot(sumpf.modules.FourierTransform(iden_nlsystem_adapt.GetOutput()).GetSpectrum(),"Identified Adapt noise",show=False)
    #     plot.relabelandplot(sumpf.modules.FourierTransform(iden_nlsystem_sineadapt.GetOutput()).GetSpectrum(),"Identified power Adapt noise",show=False)
    #     plot.relabelandplot(sumpf.modules.FourierTransform(iden_nlsystem_cosadapt.GetOutput()).GetSpectrum(),"Identified chebyshev Adapt noise",show=False)
    #     plot.relabelandplot(sumpf.modules.FourierTransform(output_sample).GetSpectrum(),"Reference Adapt noise",show=True)

    print "SNR between Reference and Identified output linear: %r" % nlsp.snr(
        output_sample, iden_nlsystem_linear.GetOutput())
    print "SNR between Reference and Identified output linear hgm: %r" % nlsp.snr(
        output_sample, iden_nlsystem_linear_hgm.GetOutput())
    print "SNR between Reference and Identified output Powerseries NL convolution: %r" % nlsp.snr(
        output_sample, iden_nlsystem_sine.GetOutput())
    print "SNR between Reference and Identified output Chebyshev NL convolution: %r" % nlsp.snr(
        output_sample, iden_nlsystem_cos.GetOutput())
    print "SNR between Reference and Identified output Adaptive: %r" % nlsp.snr(
        output_sample, iden_nlsystem_adapt.GetOutput())
    print "SNR between Reference and Identified output Powerseries Adaptive: %r" % nlsp.snr(
        output_sample, iden_nlsystem_sineadapt.GetOutput())
Exemple #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())
Exemple #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())
Exemple #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())