コード例 #1
0
def calculate_sdr_add(reference_kernel_array,
                      identified_kernel_array,
                      plot=False):
    dist = []
    sdr = []
    reference_kernel_array = nlsp.change_length_filterkernels(
        reference_kernel_array, length=len(identified_kernel_array[0]))
    dummy_ref = sumpf.modules.ConstantSignalGenerator(
        value=0.0,
        samplingrate=reference_kernel_array[0].GetSamplingRate(),
        length=len(reference_kernel_array[0])).GetSignal()
    dummy_iden = sumpf.modules.ConstantSignalGenerator(
        value=0.0,
        samplingrate=identified_kernel_array[0].GetSamplingRate(),
        length=len(identified_kernel_array[0])).GetSignal()
    for number, (ref, iden) in enumerate(
            zip(reference_kernel_array, identified_kernel_array)):
        dummy_iden = dummy_iden + iden
        dummy_ref = dummy_ref + ref
    distortion = dummy_ref - dummy_iden
    if plot is True:
        nlsp.common.plots.plot_sdrvsfreq(dummy_ref,
                                         dummy_iden,
                                         label="kernel difference sum",
                                         show=True)
    print "distortion energy: %r" % nlsp.calculateenergy_betweenfreq_freq(
        distortion, [100, 19000])
    return nlsp.calculateenergy_betweenfreq_freq(distortion, [100, 19000])
コード例 #2
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()))
コード例 #3
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()))
コード例 #4
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 robustness_excitation_evaluation(input_generator,
                                     branches,
                                     iden_method,
                                     Plot,
                                     reference=None):

    excitation_signal_amp = [0.5, 1.0, 2.0]
    sample_signal_amp = [0.5, 1.0, 2.0]
    input_s = input_generator.GetOutput()
    sample_signal = sumpf.modules.NoiseGenerator(
        distribution=sumpf.modules.NoiseGenerator.UniformDistribution(),
        samplingrate=input_s.GetSamplingRate(),
        length=len(input_s)).GetSignal()
    sample_signal = nlsp.RemoveOutliers(thresholds=[-1.0, 1.0],
                                        signal=sample_signal,
                                        value=0.0)
    sample_signal = sample_signal.GetOutput()
    for excitation_amp, sample_amp in itertools.product(
            excitation_signal_amp, sample_signal_amp):
        input_generator.SetFactor(excitation_amp)
        input_signal = input_generator.GetOutput()
        sample_signal = sumpf.modules.AmplifySignal(
            input=sample_signal, factor=sample_amp).GetOutput()
        filter_spec_tofind = nlsp.log_bpfilter(branches=branches,
                                               input=input_signal)
        filter_spec_tofind = [i for i in reversed(filter_spec_tofind)]
        filter_length = len(filter_spec_tofind[0])
        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)
        found_filter_spec = nlsp.change_length_filterkernels(
            found_filter_spec, length=filter_length)
        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()))
コード例 #6
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())
コード例 #7
0
def hgmwithreversedfilter_evaluation(input_generator,
                                     branches,
                                     nlfunction,
                                     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
    plot - the original filter spectrum and the identified filter spectrum, the reference output and identified output
    expectation - utmost similarity between the two spectrums
    """
    input_signal = input_generator.GetOutput()
    filter_spec_tofind = nlsp.log_bpfilter(branches=branches,
                                           input=input_signal)
    filter_spec_tofind = [i for i in reversed(filter_spec_tofind)]
    length_kernel = len(filter_spec_tofind[0])
    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)
    found_filter_spec = nlsp.change_length_filterkernels(found_filter_spec,
                                                         length=length_kernel)
    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 reversed filter orders: %r" % nlsp.snr(
        ref_nlsystem.GetOutput(), iden_nlsystem.GetOutput())
コード例 #8
0
def filterkernel_evaluation_plot(reference_kernels,
                                 identified_kernels,
                                 Plot="total"):
    """
    plot the difference between te reference and identified filter kernels
    :param reference_kernels: the array of reference filter kernels
    :param identified_kernels: the array of identified filter kernels
    :param Plot: either "individual" or "total"
    :return:
    """
    dummy_sum = sumpf.modules.ConstantSignalGenerator(
        value=0.0,
        samplingrate=reference_kernels[0].GetSamplingRate(),
        length=len(reference_kernels[0])).GetSignal()
    identified_kernels = nlsp.change_length_filterkernels(
        identified_kernels, len(reference_kernels[0]))
    for i, (reference_kernel, identified_kernel) in enumerate(
            zip(reference_kernels, identified_kernels)):
        sub = identified_kernel - reference_kernel
        dummy_sum = sub + dummy_sum
        # sub = sumpf.modules.FourierTransform(sub).GetSpectrum()
        # print nlsp.calculateenergy_freq(sub),i
        if Plot is "individual":
            nlsp.common.plots.relabelandplot(reference_kernel,
                                             "kernel %d reference" % (i + 1),
                                             show=False)
            nlsp.common.plots.relabelandplot(identified_kernel,
                                             "kernel %d identified" % (i + 1),
                                             show=False)
            nlsp.common.plots.relabelandplot(sub,
                                             "kernel %d difference" % (i + 1),
                                             show=True)
        elif Plot is "total":
            nlsp.common.plots.relabelandplot(sub,
                                             "kernel %d difference" % (i + 1),
                                             show=False)
    if Plot is "total":
        nlsp.common.plots.relabelandplot(dummy_sum,
                                         "diff_sum",
                                         show=True,
                                         line='g^')
コード例 #9
0
def filterkernel_evaluation_sum(reference_kernels,
                                identified_kernels,
                                Plot=False):
    """
    calculate the SNR of parallel filter kernels
    :param reference_kernels: the array of reference filter kernel
    :param identified_kernels: the array of identified filter kernel
    :param Plot: either True or False
    :return:
    """
    identified_kernels = nlsp.change_length_filterkernels(
        identified_kernels, len(reference_kernels[0]))
    temp_identified = sumpf.modules.ConstantSignalGenerator(
        value=0.0,
        samplingrate=identified_kernels[0].GetSamplingRate(),
        length=len(identified_kernels[0])).GetSignal()
    temp_reference = sumpf.modules.ConstantSignalGenerator(
        value=0.0,
        samplingrate=reference_kernels[0].GetSamplingRate(),
        length=len(reference_kernels[0])).GetSignal()
    snr_diff = []
    for i, (reference_kernel, identified_kernel) in enumerate(
            zip(reference_kernels, identified_kernels)):
        snr_diff.append(nlsp.snr(reference_kernel, identified_kernel)[0])
        temp_reference = temp_reference + reference_kernel
        temp_identified = temp_identified + identified_kernel
    temp_identified = sumpf.modules.FourierTransform(
        temp_identified).GetSpectrum()
    temp_reference = sumpf.modules.FourierTransform(
        temp_reference).GetSpectrum()
    if Plot is True:
        nlsp.common.plots.relabelandplot(temp_identified,
                                         "identified sum",
                                         show=False)
        nlsp.common.plots.relabelandplot(temp_reference,
                                         "reference sum",
                                         show=True)
    print "SNR between summed reference and identified kernels %r" % nlsp.snr(
        temp_reference, temp_identified)
    print "Mean SNR between reference and identified kernels %r,Individual SNR: %r" % (
        numpy.mean(snr_diff), snr_diff)
コード例 #10
0
def calculate_sdr(reference_kernel_array, identified_kernel_array, plot=False):
    dist = []
    sdr = []
    reference_kernel_array = nlsp.change_length_filterkernels(
        reference_kernel_array, length=len(identified_kernel_array[0]))
    for number, (ref, iden) in enumerate(
            zip(reference_kernel_array, identified_kernel_array)):
        distoriton = ref - iden
        if plot is True:
            nlsp.common.plots.plot_sdrvsfreq(ref,
                                             iden,
                                             label=str(number) + " kernel",
                                             show=False)
        dist.append(distoriton)
        distortion_energy = nlsp.calculateenergy_betweenfreq_freq(
            distoriton, [100, 19000])
        # input_energy = nlsp.calculateenergy_betweenfreq_freq(iden,[100,19000])
        # sdr.append(10*math.log10(input_energy[0]/distortion_energy[0]))
        sdr.append(distortion_energy[0])
    if plot is True:
        nlsp.common.plots.show()
    sdr = numpy.sum(sdr)
    print "distortion energy: %r" % sdr
    return sdr
コード例 #11
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())
コード例 #12
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())
コード例 #13
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
コード例 #14
0
def robustness_noise_evaluation(input_generator,
                                branches,
                                iden_method,
                                Plot,
                                reference=None):
    """
    Evaluation of System Identification method robustness by adding noise
    nonlinear system - virtual hammerstein group model with power series polynomials as nl function and bandpass filters
                        as linear functions
    plot - the original filter spectrum and the identified filter spectrum, the reference output and identified output
    expectation - utmost similarity between the two spectrums
    """
    noise_mean = [0, 0.5]
    noise_sd = [0.5, 0.7]
    for mean, sd in itertools.product(noise_mean, noise_sd):
        input_signal = input_generator.GetOutput()
        filter_spec_tofind = nlsp.log_bpfilter(branches=branches,
                                               input=input_signal)
        filter_spec_tofind = [i for i in reversed(filter_spec_tofind)]
        filter_length = len(filter_spec_tofind[0])
        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))
        ref_nlsystem_noise = nlsp.add_noise(
            ref_nlsystem.GetOutput(),
            sumpf.modules.NoiseGenerator.GaussianDistribution(mean, sd))
        found_filter_spec, nl_functions = iden_method(input_generator,
                                                      ref_nlsystem.GetOutput(),
                                                      branches)
        noise_filter_spec, nl_functions = iden_method(input_generator,
                                                      ref_nlsystem_noise,
                                                      branches)
        found_filter_spec = nlsp.change_length_filterkernels(
            found_filter_spec, length=filter_length)
        noise_filter_spec = nlsp.change_length_filterkernels(
            noise_filter_spec, length=filter_length)

        iden_nlsystem = nlsp.HammersteinGroupModel_up(
            input_signal=input_signal,
            nonlinear_functions=nl_functions,
            filter_irs=found_filter_spec,
            max_harmonics=range(1, branches + 1))
        noise_iden_nlsystem = nlsp.HammersteinGroupModel_up(
            input_signal=input_signal,
            nonlinear_functions=nl_functions,
            filter_irs=noise_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)
            noise_iden_nlsystem.SetInput(reference)
        if Plot is True:
            nlsp.relabelandplotphase(
                sumpf.modules.FourierTransform(
                    ref_nlsystem.GetOutput()).GetSpectrum(),
                "Reference Output", False)
            nlsp.relabelandplotphase(
                sumpf.modules.FourierTransform(
                    iden_nlsystem.GetOutput()).GetSpectrum(),
                "Identified Output", False)
            nlsp.relabelandplotphase(
                sumpf.modules.FourierTransform(
                    noise_iden_nlsystem.GetOutput()).GetSpectrum(),
                "Noise Identified Output", True)
        print "SNR between Reference and Identified output without noise: %r" % nlsp.snr(
            ref_nlsystem.GetOutput(), iden_nlsystem.GetOutput())
        print "SNR between Reference and Identified output with noise of sd %r and mean %r is %r" % (
            sd, mean,
            nlsp.snr(ref_nlsystem.GetOutput(),
                     noise_iden_nlsystem.GetOutput()))
コード例 #15
0
def hgmwithfilter_evaluation(input_generator,
                             branches,
                             nlfuntion,
                             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
    plot - the original filter spectrum and the identified filter spectrum, the reference output and identified output
    expectation - utmost similarity between the two spectrums
    """
    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 = [i for i in reversed(filter_spec_tofind)]
    length_kernel = len(filter_spec_tofind[0])
    # 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))
    found_filter_spec, nl_functions = iden_method(input_generator,
                                                  ref_nlsystem.GetOutput(),
                                                  branches)
    found_filter_spec = nlsp.change_length_filterkernels(found_filter_spec,
                                                         length=length_kernel)
    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(ref_nlsystem.GetOutput(),
                            "Reference Output",
                            show=False)
        plot.relabelandplot(iden_nlsystem.GetOutput(),
                            "Identified Output",
                            show=True)
    # nlsp.plot_array([sumpf.modules.FourierTransform(s).GetSpectrum() for s in filter_spec_tofind],label_array=["reference%d" %i for i in range(len(filter_spec_tofind))],Show=False)
    # nlsp.plot_array([sumpf.modules.FourierTransform(s).GetSpectrum() for s in found_filter_spec],label_array=["identified%d" %i for i in range(len(found_filter_spec))],Show=True)
    print "SNR between Reference and Identified output without overlapping filters: %r" % nlsp.snr(
        ref_nlsystem.GetOutput(), iden_nlsystem.GetOutput())
    sumpf.modules.SignalFile(
        filename=
        "C:/Users/diplomand.8/Desktop/linearHGM_explannation/cheby/noise/input",
        signal=reference,
        format=sumpf.modules.SignalFile.WAV_FLOAT)
    sumpf.modules.SignalFile(
        filename=
        "C:/Users/diplomand.8/Desktop/linearHGM_explannation/cheby/noise/%s" %
        iden_method.__name__,
        signal=iden_nlsystem.GetOutput(),
        format=sumpf.modules.SignalFile.WAV_FLOAT)
    sumpf.modules.SignalFile(
        filename=
        "C:/Users/diplomand.8/Desktop/linearHGM_explannation/cheby/noise/reference",
        signal=ref_nlsystem.GetOutput(),
        format=sumpf.modules.SignalFile.WAV_FLOAT)
コード例 #16
0
def db_evaluation_all(branches=3, Plot=False):

    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, "Speech1.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 = nlsp.linear_identification_temporalreversal(
        sine_g, output_sine)
    iden_nlsystem_linear = nlsp.AliasCompensatingHammersteinModelUpandDown(
        filter_impulseresponse=kernel_linear)

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

    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 power",
            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 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_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 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())
    print "SNR between Reference and Identified output Chebyshev Adaptive: %r" % nlsp.snr(
        output_sample, iden_nlsystem_cosadapt.GetOutput())
コード例 #17
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)
コード例 #18
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())