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()))
def clippingHGMevaluation(input_generator, branches, iden_method, Plot, reference=None): """ Evaluation of System Identification method by hard clipping system nonlinear system - virtual clipping systems which hard clips the signal amplitute which are not in the threshold range plot - the virtual nl system output and the identified nl system output expectation - utmost similarity between the two outputs """ 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)) found_filter_spec, nl_functions = iden_method(input_generator, ref_nlsystem.GetOutput(), branches) iden_nlsystem = nlsp.HammersteinGroupModel_up( input_signal=input_signal, nonlinear_functions=nl_functions, filter_irs=found_filter_spec, max_harmonics=range(1, branches + 1)) # 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()))
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 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()))
def computationtime_evaluation(input_generator, branches, iden_method, Plot, rangevalue=10, save=False): inputgenerator = input_generator branch = reversed(range(2, branches + 1)) length = reversed([2**14, 2**15, 2**16]) for branches, signal_length in itertools.product(branch, length): sim = [] iden = [] reference = nlsp.WhiteGaussianGenerator( sampling_rate=input_generator.GetOutput().GetSamplingRate(), length=signal_length, distribution=sumpf.modules.NoiseGenerator.LaplaceDistribution()) reference = reference.GetOutput() for i in range(rangevalue): inputgenerator.SetLength(signal_length) input_signal = inputgenerator.GetOutput() filter_spec_tofind = nlsp.log_bpfilter(branches=branches, input=input_signal) nl_func = nlsp.nl_branches(nlsp.function_factory.power_series, branches) ref_nlsystem = nlsp.HammersteinGroupModel_up( input_signal=input_signal, nonlinear_functions=nl_func, filter_irs=filter_spec_tofind, max_harmonics=range(1, branches + 1)) identification_time_start = time.clock() found_filter_spec, nl_functions = iden_method( input_generator, ref_nlsystem.GetOutput(), branches) identification_time_stop = time.clock() if save is True: found_filter_spec_save, nl_functions_save = nlsp.systemidentification( "powerhgmweight", iden_method, branches, inputgenerator, ref_nlsystem.GetOutput()) iden_nlsystem = nlsp.HammersteinGroupModel_up( input_signal=input_signal, nonlinear_functions=nl_functions, filter_irs=found_filter_spec, max_harmonics=range(1, branches + 1)) iden_nlsystem.GetOutput() simulation_time_start = time.clock() iden_nlsystem.SetInput(reference) iden_nlsystem.GetOutput() simulation_time_stop = time.clock() simulation_time = simulation_time_stop - simulation_time_start identification_time = identification_time_stop - identification_time_start iden.append(identification_time) sim.append(simulation_time) print "Signal length: %r, branches: %r, simulation time: %r, identification time: %r" % ( signal_length, branches, numpy.average(sim), numpy.average(iden))
def puretone_evaluation(input_generator, branches, iden_method, Plot, reference=None): input_signal = input_generator.GetOutput() filter_spec_tofind = nlsp.log_bpfilter(branches=branches, input=input_signal) ref_nlsystem = nlsp.HammersteinGroupModel_up( input_signal=input_signal, nonlinear_functions=nlsp.nl_branches( nlsp.function_factory.power_series, branches), filter_irs=filter_spec_tofind, max_harmonics=range(1, branches + 1)) found_filter_spec, nl_functions = iden_method(input_generator, ref_nlsystem.GetOutput(), branches) iden_nlsystem = nlsp.HammersteinGroupModel_up( input_signal=input_signal, nonlinear_functions=nl_functions, filter_irs=found_filter_spec, max_harmonics=range(1, branches + 1)) 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 sweep: %r" % nlsp.snr( ref_nlsystem.GetOutput(), iden_nlsystem.GetOutput()) pure_tones = nlsp.generate_puretones([200, 1000, 3000, 5000, 10000, 20000], input_signal.GetSamplingRate(), length=len(input_signal)) ref_nlsystem.SetInput(pure_tones) iden_nlsystem.SetInput(pure_tones) 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 puretone: %r" % nlsp.snr( ref_nlsystem.GetOutput(), iden_nlsystem.GetOutput())
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())
def hgmwithreversedfilter_evaluation(input_generator, branches, nlfunction, Plot, reference=None): 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)] 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 reversed filter orders: %r" % nlsp.snr( ref_nlsystem.GetOutput(), iden_nlsystem.GetOutput())
def computationtime_adaptive_evaluation(input_generator, branches): identification = [nlsp.adaptive_identification_powerseries] nlfunctions = [ nlsp.function_factory.power_series, nlsp.function_factory.chebyshev1_polynomial, nlsp.function_factory.hermite_polynomial, nlsp.function_factory.legrendre_polynomial ] for identification_alg, nl_function in itertools.product( identification, nlfunctions): sim = [] iden = [] print identification_alg print nl_function for i in range(5): input_signal = input_generator.GetOutput() filter_spec_tofind = nlsp.log_bpfilter(branches=branches, input=input_signal) nl_func = nlsp.nl_branches(nlsp.function_factory.power_series, branches) ref_nlsystem = nlsp.HammersteinGroupModel_up( input_signal=input_signal, nonlinear_functions=nl_func, filter_irs=filter_spec_tofind, max_harmonics=range(1, branches + 1)) simulation_time_start = time.clock() identification_time_start = time.clock() found_filter_spec, nl_functions = identification_alg( input_generator, ref_nlsystem.GetOutput(), branches, nl_function) identification_time_stop = time.clock() iden_nlsystem = nlsp.HammersteinGroupModel_up( input_signal=input_signal, nonlinear_functions=nl_functions, filter_irs=found_filter_spec, max_harmonics=range(1, branches + 1)) iden_nlsystem.GetOutput() simulation_time_stop = time.clock() simulation_time = simulation_time_stop - simulation_time_start identification_time = identification_time_stop - identification_time_start sim.append(simulation_time) iden.append(identification_time) print "simulation time: %r, identification time: %r" % ( numpy.average(sim), numpy.average(iden))
def uniqueness_evaluation_adaptive(): for input_generator in excitation: print "adaptive identification" print input_generator for nlfunc_ref, nlfunc_iden in itertools.product( nl_functions_all, nl_functions_all): print "ref nl function %r" % nlfunc_ref print "iden nl function %r" % nlfunc_iden input_signal = input_generator.GetOutput() filter_spec_tofind = nlsp.log_bpfilter(branches=branches, input=input_signal) ref_nlsystem = nlsp.HammersteinGroupModel_up( input_signal=input_signal, nonlinear_functions=nlsp.nl_branches(nlfunc_ref, branches), filter_irs=filter_spec_tofind, max_harmonics=range(1, branches + 1)) found_filter_spec, nl_functions = nlsp.adaptive_identification( input_generator, ref_nlsystem.GetOutput(), branches, nonlinear_func=nlfunc_iden) 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_sum(filter_spec_tofind, found_filter_spec) nlsp.filterkernel_evaluation_plot(filter_spec_tofind, found_filter_spec) if Plot is True: plot.relabelandplot(sumpf.modules.FourierTransform( ref_nlsystem.GetOutput()).GetSpectrum(), "Reference Output", show=False) plot.relabelandplot(sumpf.modules.FourierTransform( iden_nlsystem.GetOutput()).GetSpectrum(), "Identified Output", show=True) print "SNR between Reference and Identified output without overlapping filters: %r" % nlsp.snr( ref_nlsystem.GetOutput(), iden_nlsystem.GetOutput()) print print print
def uniqueness_evaluation_allexceptadaptive(): for method, input_generator, label in zip(iden_method, excitation, labels): print method, input_generator for nlfunc in nl_functions_all: print nlfunc input_signal = input_generator.GetOutput() filter_spec_tofind = nlsp.log_bpfilter(branches=branches, input=input_signal) ref_nlsystem = nlsp.HammersteinGroupModel_up( input_signal=input_signal, nonlinear_functions=nlsp.nl_branches(nlfunc, branches), filter_irs=filter_spec_tofind, max_harmonics=range(1, branches + 1)) found_filter_spec, nl_functions = method(input_generator, ref_nlsystem.GetOutput(), branches) iden_nlsystem = nlsp.HammersteinGroupModel_up( input_signal=input_signal, nonlinear_functions=nl_functions, filter_irs=found_filter_spec, max_harmonics=range(1, branches + 1)) nlsp.filterkernel_evaluation_sum(filter_spec_tofind, found_filter_spec) nlsp.filterkernel_evaluation_plot(filter_spec_tofind, found_filter_spec) 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(), label=label) print print print
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)
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()))
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())
# plot.plot(sumpf.modules.FourierTransform(nlsystem_lp.GetOutput()).GetSpectrum(), show=True) sampling_rate = 48000 sweep_start_freq = 20.0 sweep_stop_freq = 20000.0 branches = 5 sweep_length = 2**18 input_sweep = sumpf.modules.SweepGenerator( samplingrate=sampling_rate, length=sweep_length, start_frequency=sweep_start_freq, stop_frequency=sweep_stop_freq).GetSignal() # Nonlinear functions nonlinear_functions_power = nlsp.nonlinearconvolution_powerseries_nlfunction( branches) #nonlinear_functions_chebyshev = nlsp.nonlinearconvolution_chebyshev_nlfunction(branches) #nonlinear_functions_power = [nlsp.function_factory.power_series(1),]*branches #nonlinear_functions_chebyshev = [nlsp.function_factory.chebyshev1_polynomial(1),]*branches # Filter Specifications filter_spec_tofind = nlsp.log_bpfilter(sweep_start_freq, sweep_stop_freq, branches, input_sweep) # filter_spec_tofind = [sumpf.modules.ImpulseGenerator(samplingrate=input_sweep.GetSamplingRate(),length=len(input_sweep)).GetSignal(),]*branches # Max harmonics max_harmonics = [1, 2, 3, 4, 5] #max_harmonics = [1,]*branches sweep_evaluation_power()
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) wgn_normal_g = nlsp.WhiteGaussianGenerator(sampling_rate=sampling_rate, length=length, start_frequency=start_freq, stop_frequency=stop_freq, distribution=normal) wgn_uniform_g = nlsp.WhiteGaussianGenerator(sampling_rate=sampling_rate, length=length, start_frequency=start_freq, stop_frequency=stop_freq, distribution=uniform) wgn_laplace_g = nlsp.WhiteGaussianGenerator(sampling_rate=sampling_rate, length=length, start_frequency=start_freq, stop_frequency=stop_freq, distribution=laplace) reference = nlsp.WhiteGaussianGenerator(sampling_rate=sampling_rate, length=length, start_frequency=start_freq, stop_frequency=stop_freq, distribution=sumpf.modules.NoiseGenerator.LaplaceDistribution()) reference = sumpf.modules.ClipSignal(reference.GetOutput()).GetOutput() input = wgn_normal_g.GetOutput() filter_spec_tofind_noise = nlsp.log_bpfilter(branches=branches,input=input) i = 5 ################################################################### # adaptive_initializedwith_sweepidentification() ################################################################## # inputg = [wgn_normal_g,wgn_uniform_g,wgn_laplace_g] # for input in inputg: # input = input.GetOutput() # adaptive_differentnlfunctions() ################################################################## # reference = nlsp.WhiteGaussianGenerator(sampling_rate=sampling_rate, length=2**18, start_frequency=start_freq, # stop_frequency=stop_freq, distribution=sumpf.modules.NoiseGenerator.LaplaceDistribution()) # reference = sumpf.modules.ClipSignal(reference.GetOutput()).GetOutput() #
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())
import sumpf import nlsp import nlsp.common.plots as plot start_frequency = 20.0 stop_frequency = 20000.0 length = 2**15 branches = 3 sampling_rate = 48000 novak_sweep = nlsp.NovakSweepGenerator_Sine(start_frequency=start_frequency, stop_frequency=stop_frequency, sampling_rate=sampling_rate, length=length) farina_sweep = nlsp.FarinaSweepGenerator_Sine(start_frequency=start_frequency, stop_frequency=stop_frequency, sampling_rate=sampling_rate, length=length) input_signal_novak = novak_sweep.GetOutput() input_signal_farina = farina_sweep.GetOutput() filter_spec_tofind_novak = nlsp.log_bpfilter(branches=branches,input=input_signal_novak) filter_spec_tofind_farina = nlsp.log_bpfilter(branches=branches,input=input_signal_farina) ref_nlsystem_novak = nlsp.HammersteinGroupModel_up(nonlinear_functions=nlsp.nl_branches(nlsp.function_factory.power_series,branches), filter_irs=filter_spec_tofind_novak, max_harmonics=range(1,branches+1)) ref_nlsystem_farina = nlsp.HammersteinGroupModel_up(nonlinear_functions=nlsp.nl_branches(nlsp.function_factory.power_series,branches), filter_irs=filter_spec_tofind_farina, max_harmonics=range(1,branches+1)) ref_nlsystem_novak.SetInput(input_signal_novak) ref_nlsystem_farina.SetInput(input_signal_farina) ir_novak = nlsp.getnl_ir(novak_sweep,ref_nlsystem_novak.GetOutput(),branches) ir_farina = nlsp.getnl_ir(farina_sweep,ref_nlsystem_farina.GetOutput(),branches) plot.relabelandplot(ir_novak,"IR with synchronization",show=False) plot.relabelandplot(ir_farina,"IR without synchronization",show=True)