def doublehgm_samenl_evaluation(input_generator, branches, iden_method, 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) 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.power_series, 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 = iden_method(input_generator, ref_nlsystem.GetOutput(2), branches) iden_nlsystem = nlsp.HammersteinGroupModel_up( input_signal=input_signal, nonlinear_functions=nl_functions, filter_irs=found_filter_spec, max_harmonics=range(1, branches + 1)) if reference is not None: reference = nlsp.change_length_signal(reference, length=len(input_signal)) ref_nlsystem = nlsp.HammersteinGroup_Series( input_signal=reference, nonlinear_functions=(nlsp.nl_branches( nlsp.function_factory.power_series, branches), nlsp.nl_branches( nlsp.function_factory.power_series, 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 same nl: %r" % nlsp.snr( ref_nlsystem.GetOutput(2), iden_nlsystem.GetOutput())
def doublehgm_same_evaluation(input_generator, branches, iden_method, Plot, reference=None): """ Evaluation of System Identification method by double hgm virtual nl system with same nonlinear degree and filters nonlinear system - two 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) 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.power_series, branches)), filter_irs=(filter_spec_tofind, filter_spec_tofind), max_harmonics=(range(1, branches + 1), range(1, branches + 1)), hgm_type=(nlsp.HammersteinGroupModel_up, nlsp.HammersteinGroupModel_up)) found_filter_spec, nl_functions = iden_method(input_generator, ref_nlsystem.GetOutput(2), branches) iden_nlsystem = nlsp.HammersteinGroupModel_up( input_signal=input_signal, nonlinear_functions=nl_functions, filter_irs=found_filter_spec, max_harmonics=range(1, branches + 1)) if reference is not None: reference = nlsp.change_length_signal(reference, length=len(input_signal)) ref_nlsystem = nlsp.HammersteinGroup_Series( input_signal=reference, nonlinear_functions=(nlsp.nl_branches( nlsp.function_factory.power_series, branches), nlsp.nl_branches( nlsp.function_factory.power_series, branches)), filter_irs=(filter_spec_tofind, filter_spec_tofind), 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 all same: %r" % nlsp.snr( ref_nlsystem.GetOutput(2), iden_nlsystem.GetOutput())
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())