def removeDC_01(pipeline, name): # # This test removes the DC component from a stream of ones (i.e., the result should be zero) # rate = 2048 # Hz buffer_length = 1.0 # seconds test_duration = 50.0 # seconds DC = 1.0 wave = 0 volume = 0.0 # # build pipeline # src = test_common.test_src(pipeline, buffer_length=buffer_length, rate=16384, test_duration=test_duration, wave=wave, width=64) head = pipeparts.mkaudioamplify(pipeline, src, volume) head = pipeparts.mkgeneric(pipeline, head, "lal_add_constant", value=DC) head = calibration_parts.mkresample( pipeline, head, 5, True, "audio/x-raw,format=F64LE,rate=%d" % rate) head = calibration_parts.removeDC( pipeline, head, "audio/x-raw,format=F64LE,rate=%d" % rate) pipeparts.mknxydumpsink(pipeline, head, "%s_out.dump" % name) # # done # return pipeline
def lal_resample_01(pipeline, name): # # This test adds various noise into a stream and uses audioresample to remove it # rate = 16384 # Hz buffer_length = 1.0 # seconds test_duration = 2000.0 # seconds width = 64 # bits # # build pipeline # src = test_common.test_src(pipeline, buffer_length = buffer_length, wave = 5, volume = 1, rate = rate, test_duration = test_duration, width = width, verbose = False) tee = pipeparts.mktee(pipeline, src) identity = pipeparts.mkgeneric(pipeline, tee, "identity") head = pipeparts.mkgeneric(pipeline, tee, "lal_resample", quality = 5) head = pipeparts.mkcapsfilter(pipeline, head, "audio/x-raw,format=F64LE,rate=2048") head = pipeparts.mkgeneric(pipeline, head, "lal_resample", quality = 5) head = pipeparts.mkcapsfilter(pipeline, head, "audio/x-raw,format=F64LE,rate=16384") head = calibration_parts.mkinterleave(pipeline, [head, identity]) #pipeparts.mknxydumpsink(pipeline, head, "resampled_data.txt") #head = pipeparts.mkgeneric(pipeline, head, "splitcounter") pipeparts.mkgeneric(pipeline, head, "lal_transferfunction", fft_length = rate, fft_overlap = rate / 2, num_ffts = 1000, update_samples = rate * test_duration, filename = "lal_resample_tf.txt") # # done # return pipeline
def deinterleave_02(pipeline, name): buffer_length = 1.0 rate = 2048 width = 64 channels = 3 test_duration = 10.0 freq = 10 is_live = False src = test_common.test_src(pipeline, wave=5, freq=freq, test_duration=test_duration, volume=1, width=64, rate=rate, channels=channels, verbose=False) streams = calibration_parts.mkdeinterleave(pipeline, src, channels) for i in range(0, channels): pipeparts.mknxydumpsink(pipeline, streams[i], "%s_stream%d.txt" % (name, i)) return pipeline
def queue_02(pipeline, name): # # This test is intended to probe data flow with tees, firbanks, and queues # rate = 16384 # Hz buffer_length = 1.0 # seconds test_duration = 100.0 # seconds # # build pipeline # src = test_common.test_src(pipeline, buffer_length = buffer_length, rate = rate, test_duration = test_duration, width = 32) # tee = pipeparts.mktee(pipeline, src) head = pipeparts.mkgeneric(pipeline, src, "splitcounter", name = "before_resample") head = calibration_parts.mkresample(pipeline, head, "audio/x-raw, format=F32LE,rate=16")#fir_matrix=[numpy.hanning(600)], latency = 300, time_domain = True) # head = calibration_parts.mkinsertgap(pipeline, head, bad_data_intervals = [-1e35, 1e35], block_duration = buffer_length * 1000000000, remove_gap = False) head = pipeparts.mkgeneric(pipeline, head, "splitcounter", name = "after_resample") # head2 = pipeparts.mkfirbank(pipeline, tee, fir_matrix=[numpy.hanning(1000)], latency = 500, time_domain = True) # head2 = calibration_parts.mkinsertgap(pipeline, head2, bad_data_intervals = [-1e35, 1e35], block_duration = buffer_length * 1000000000, remove_gap = False) # head2 = pipeparts.mkgeneric(pipeline, tee, "splitcounter", name = "tee_to_adder") # head = calibration_parts.mkqueue(pipeline, head, 1) # head2 = calibration_parts.mkqueue(pipeline, head2, 1) # adder = calibration_parts.mkadder(pipeline, calibration_parts.list_srcs(pipeline, head, head2)) # head = pipeparts.mkgeneric(pipeline, adder, "splitcounter", name = "before_final_dump") pipeparts.mknxydumpsink(pipeline, head, "%s_out.dump" % name) # # done # return pipeline
def lal_smoothkappas_01(pipeline, name): # # This test is to check that the inputs are smoothed in a desirable way # rate = 10 # Hz width = 64 # bytes wave = 5 freq = 0.1 # Hz volume = 0.9 buffer_length = 1.0 # seconds test_duration = 10.0 # seconds # # build pipeline # head = test_common.test_src(pipeline, channels = 2, buffer_length = buffer_length, rate = rate, width = width, test_duration = test_duration, wave = wave, freq = freq, volume = volume) head = pipeparts.mktogglecomplex(pipeline, head) head = pipeparts.mktee(pipeline, head) pipeparts.mknxydumpsink(pipeline, pipeparts.mkqueue(pipeline, head), "%s_in.dump" % name) median = pipeparts.mkgeneric(pipeline, head, "lal_smoothkappas", array_size = 3, maximum_offset_re = 0.5, maximum_offset_im = 0.5, default_kappa_im = 0.5, default_kappa_re = 0.5, track_bad_kappa = False, default_to_median = True) median_avg = pipeparts.mkgeneric(pipeline, head, "lal_smoothkappas", array_size = 3, avg_array_size = 2, maximum_offset_re = 0.5, maximum_offset_im = 0.5, default_kappa_im = 0.5, default_kappa_re = 0.5, track_bad_kappa = False, default_to_median = True) pipeparts.mknxydumpsink(pipeline, pipeparts.mkqueue(pipeline, median), "%s_median.dump" % name) pipeparts.mknxydumpsink(pipeline, pipeparts.mkqueue(pipeline, median_avg), "%s_median_avg.dump" % name) # # done # return pipeline
def lal_add_constant_02(pipeline, name): # # This test adds a constant to a stream of double-precision floats # rate = 1000 # Hz buffer_length = 1.0 # seconds test_duration = 10.0 # seconds # # build pipeline # src = test_common.test_src(pipeline, buffer_length = buffer_length, rate = rate, test_duration = test_duration, width = 64) capsfilter1 = pipeparts.mkcapsfilter(pipeline, src, "audio/x-raw, format=F64LE, rate=%d" % int(rate)) tee1 = pipeparts.mktee(pipeline, capsfilter1) pipeparts.mknxydumpsink(pipeline, pipeparts.mkqueue(pipeline, tee1), "%s_in.dump" % name) add_constant = pipeparts.mkgeneric(pipeline, tee1, "lal_add_constant", value=3) capsfilter2 = pipeparts.mkcapsfilter(pipeline, add_constant, "audio/x-raw, format=F64LE, rate=%d" % int(rate)) pipeparts.mknxydumpsink(pipeline, pipeparts.mkqueue(pipeline, capsfilter2), "%s_out.dump" % name) # # done # return pipeline
def filters_01(pipeline, name): # # This tests whether the two filters files above behave identically when passed to a lal_firbank element. If so, the output file is ones. # rate = 32768 # Hz buffer_length = 1.0 # seconds test_duration = 1000.0 # seconds # # build pipeline # src = test_common.test_src(pipeline, buffer_length = buffer_length, rate = rate, test_duration = test_duration, width = 64) tee = pipeparts.mktee(pipeline, src) py_filt = pipeparts.mkfirbank(pipeline, tee, latency = int(py_ctrl_corr_delay), fir_matrix = [py_ctrl_corr_filt[::-1]], time_domain = True) mat_filt = pipeparts.mkfirbank(pipeline, tee, latency = int(mat_ctrl_corr_delay), fir_matrix = [mat_ctrl_corr_filt[::-1]], time_domain = True) py_filt = pipeparts.mkaudiorate(pipeline, py_filt, skip_to_first = True, silent = False) mat_filt = pipeparts.mkaudiorate(pipeline, mat_filt, skip_to_first = True, silent = False) py_filt_inv = pipeparts.mkpow(pipeline, py_filt, exponent = -1.0) ratio = calibration_parts.mkmultiplier(pipeline, calibration_parts.list_srcs(pipeline, mat_filt, py_filt_inv)) pipeparts.mknxydumpsink(pipeline, ratio, "%s_out.dump" % name) # # done # return pipeline
def queue_03(pipeline, name): # # Very simple test of data storage in queues # rate = 1000 # Hz buffer_length = 1.0 # seconds test_duration = 100.0 # seconds # # build pipeline # src = test_common.test_src(pipeline, buffer_length = buffer_length, rate = rate, test_duration = test_duration, width = 32) head = pipeparts.mkgeneric(pipeline, src, "splitcounter", name = "before_queue") head = calibration_parts.mkqueue(pipeline, head, 50) head = pipeparts.mkgeneric(pipeline, head, "splitcounter", name = "after_queue") pipeparts.mkfakesink(pipeline, head) # # done # return pipeline
def lal_property_test_01(pipeline, name): # # This test makes a stream changing between 2's and 8's. # It should square the 2's and take the 8's to the 8th power. # rate = 512 # Hz width = 64 buffer_length = 1.0 # seconds test_duration = 100.0 # seconds gap_frequency = 0.1 # Hz gap_threshold = 0.0 control_dump_filename = "control_property_test_01.dump" bad_data_intervals2 = [0.0, 1e35] bad_data_intervals = [-1e35, 1e-35] head = test_common.test_src(pipeline, buffer_length=buffer_length, rate=rate, width=width, channels=1, test_duration=test_duration, wave=0, freq=0.1, volume=1) head = pipeparts.mkgeneric(pipeline, head, "lal_insertgap", bad_data_intervals=bad_data_intervals, insert_gap=False, fill_discont=True, replace_value=2.0) head = pipeparts.mkgeneric(pipeline, head, "lal_insertgap", bad_data_intervals=bad_data_intervals2, insert_gap=False, fill_discont=True, replace_value=8.0) head = pipeparts.mktee(pipeline, head) pipeparts.mknxydumpsink(pipeline, head, "%s_in.dump" % name) lal_prop_exponent = pipeparts.mkgeneric(pipeline, head, "lal_property", update_when_change=True) head = calibration_parts.mkpow(pipeline, head, exponent=0.0) lal_prop_exponent.connect("notify::current-average", calibration_parts.update_property_simple, head, "current_average", "exponent", 1) pipeparts.mknxydumpsink(pipeline, head, "%s_out.dump" % name) # # done # return pipeline
def lal_multiple_srcs(pipeline, name): # # This test uses multiple source elements # rate = 1000 # Hz buffer_length = 1.0 # seconds test_duration = 10.0 # seconds # # build pipeline # src1 = test_common.test_src(pipeline, buffer_length=buffer_length, rate=rate, test_duration=test_duration, width=32, verbose=False) capsfilter1 = pipeparts.mkcapsfilter( pipeline, src1, "audio/x-raw, format=F32LE, rate=%d" % int(rate)) src2 = test_common.test_src(pipeline, buffer_length=buffer_length, rate=rate, test_duration=test_duration, width=32, verbose=False) capsfilter2 = pipeparts.mkcapsfilter( pipeline, src2, "audio/x-raw, format=F32LE, rate=%d" % int(rate)) combined = calibration_parts.mkadder( pipeline, calibration_parts.list_srcs(pipeline, capsfilter1, capsfilter2)) pipeparts.mknxydumpsink(pipeline, pipeparts.mkqueue(pipeline, combined), "multiple_srcs_out.dump") # # done # return pipeline
def lal_transferfunction_04(pipeline, name): # # This test produces three-channel data to be read into lal_transferfunction # rate = 16384 # Hz buffer_length = 1.0 # seconds test_duration = 500.0 # seconds width = 64 # bits channels = 1 freq = 512 # Hz # # build pipeline # hoft = test_common.test_src(pipeline, buffer_length=buffer_length, wave=5, volume=1, freq=freq, channels=channels, rate=rate, test_duration=test_duration, width=width, verbose=False) hoft = pipeparts.mktee(pipeline, hoft) shifted_hoft = pipeparts.mkgeneric(pipeline, hoft, "lal_shift", shift=35024) interleaved_data = calibration_parts.mkinterleave( pipeline, calibration_parts.list_srcs(pipeline, hoft, shifted_hoft)) pipeparts.mkgeneric(pipeline, interleaved_data, "lal_transferfunction", fft_length=4 * rate, fft_overlap=2 * rate, num_ffts=64, update_samples=rate * test_duration, make_fir_filters=1, fir_length=rate, update_after_gap=True, filename="lpfilter.txt") return pipeline
def lal_smoothkappas_03(pipeline, name): # # This pipeline uses lal_smoothkappas in a similar way that gstlal_compute_strain will # rate = 2000 # Hz width = 64 # bytes wave = 1 # 0=sine, 1=square freq = 0.05 # Hz volume = 0.01 buffer_length = 1.0 # seconds test_duration = 40.0 # seconds real_expected = 1 imag_expected = 0 N = 2048 Nav = 160 src = test_common.test_src(pipeline, buffer_length = buffer_length, rate = rate, width = width, test_duration = test_duration, wave = wave, freq = freq, volume = volume) tee = pipeparts.mktee(pipeline, src) real = pipeparts.mkgeneric(pipeline, tee, "lal_add_constant", value=1) kappas = calibration_parts.merge_into_complex(pipeline, real, tee) kappas = pipeparts.mktee(pipeline, kappas) pipeparts.mknxydumpsink(pipeline, pipeparts.mkqueue(pipeline, kappas), "%s_kappa_in.dump" % name) fake_statevector = pipeparts.mkgeneric(pipeline, tee, "pow", exponent=0) fake_statevector = pipeparts.mkgeneric(pipeline, fake_statevector, "lal_demodulate", line_frequency=0.5) fake_statevector = pipeparts.mkgeneric(pipeline, fake_statevector, "lal_togglecomplex") fake_statevector = pipeparts.mkgeneric(pipeline, fake_statevector, "lal_matrixmixer", matrix = [[1],[0]]) fake_statevector = pipeparts.mkgeneric(pipeline, fake_statevector, "lal_bitvectorgen", threshold=0.1, bit_vector=1) fake_coherence = pipeparts.mkgeneric(pipeline, tee, "pow", exponent=0) fake_coherence = pipeparts.mkgeneric(pipeline, fake_coherence, "lal_demodulate", line_frequency=0.10) fake_coherence = pipeparts.mkgeneric(pipeline, fake_coherence, "lal_togglecomplex") fake_coherence = pipeparts.mkgeneric(pipeline, fake_coherence, "lal_matrixmixer", matrix = [[1],[0]]) fake_coherence = pipeparts.mkgeneric(pipeline, fake_coherence, "lal_bitvectorgen", threshold=0.15, bit_vector=1) re, im = calibration_parts.smooth_complex_kappas(pipeline, kappas, fake_statevector, fake_coherence, real_expected, imag_expected, N, Nav) pipeparts.mknxydumpsink(pipeline, pipeparts.mkqueue(pipeline, re), "%s_re_kappa_out.dump" % name) pipeparts.mknxydumpsink(pipeline, pipeparts.mkqueue(pipeline, im), "%s_im_kappa_out.dump" % name) # # done # return pipeline
def lal_constantupsample_03(pipeline, name): # # This is a simple test that the sample rates are adjusted as expected for complex data # in_rate = 1 # Hz out_rate = 10 # Hz buffer_length = 1.0 # seconds test_duration = 10.0 # seconds # # build pipeline # src = test_common.test_src(pipeline, buffer_length=buffer_length, channels=2, rate=in_rate, test_duration=test_duration, width=64) togglecomplex1 = pipeparts.mktogglecomplex(pipeline, src) capsfilter1 = pipeparts.mkcapsfilter( pipeline, togglecomplex1, "audio/x-raw, format=Z128LE, rate=%d" % int(in_rate)) tee1 = pipeparts.mktee(pipeline, capsfilter1) pipeparts.mknxydumpsink( pipeline, pipeparts.mkqueue(pipeline, pipeparts.mktogglecomplex(pipeline, tee1)), "%s_in.dump" % name) upsample = pipeparts.mkgeneric(pipeline, tee1, "lal_constantupsample") capsfilter2 = pipeparts.mkcapsfilter( pipeline, upsample, "audio/x-raw, format=Z128LE, rate=%d" % int(out_rate)) #checktimestamps = pipeparts.mkchecktimestamps(pipeline, capsfilter2) pipeparts.mknxydumpsink( pipeline, pipeparts.mkqueue(pipeline, pipeparts.mktogglecomplex(pipeline, capsfilter2)), "%s_out.dump" % name) # # done # return pipeline
def lal_resample_01(pipeline, name): # # This test passes an impulse through the resampler # rate_in = 128 # Hz rate_out = 1024 # Hz buffer_length = 0.77 # seconds test_duration = 30.0 # seconds quality = 5 # # build pipeline # head = test_common.test_src(pipeline, buffer_length=buffer_length, wave=0, freq=0.25, rate=rate_in, test_duration=test_duration, width=64) head = calibration_parts.mkinsertgap( pipeline, head, bad_data_intervals=[0.999999999, 1.00000001], block_duration=int(0.5 * Gst.SECOND), insert_gap=False, replace_value=0.0) head = pipeparts.mktee(pipeline, head) pipeparts.mknxydumpsink(pipeline, head, "%s_in.txt" % name) head = pipeparts.mkgeneric(pipeline, head, "splitcounter") head = calibration_parts.mkresample( pipeline, head, quality, False, "audio/x-raw,format=F64LE,rate=%d" % rate_out) head = pipeparts.mkgeneric(pipeline, head, "splitcounter") pipeparts.mknxydumpsink(pipeline, head, "%s_out.txt" % name) # # done # return pipeline
def lal_tdwhiten_01(pipeline, name): # # This test passes ones through lal_tdwhiten # src = test_common.test_src(pipeline, buffer_length = buffer_length, wave = 0, freq = 0, rate = rate, test_duration = test_duration, width = 64) head = pipeparts.mkaudioamplify(pipeline, src, 0.0) head = pipeparts.mkgeneric(pipeline, head, "lal_add_constant", value = 1.0) head = pipeparts.mktee(pipeline, head) pipeparts.mknxydumpsink(pipeline, head, "%s_in.txt" % name) head = pipeparts.mkgeneric(pipeline, head, "lal_tdwhiten", kernel = fir_filt[::-1], latency = latency) pipeparts.mknxydumpsink(pipeline, head, "%s_out.txt" % name) # # done # return pipeline
def lal_complexfirbank_01(pipeline, name): # # This test passes ones through lal_complexfirbank # src = test_common.test_src(pipeline, buffer_length = buffer_length, wave = 0, freq = 0, rate = rate, test_duration = test_duration, width = 64) head = pipeparts.mkaudioamplify(pipeline, src, 0.0) head = pipeparts.mkgeneric(pipeline, head, "lal_add_constant", value = 1.0) head = pipeparts.mktee(pipeline, head) pipeparts.mknxydumpsink(pipeline, head, "%s_in.txt" % name) head = calibration_parts.mkcomplexfirbank(pipeline, head, latency = latency, fir_matrix = [fir_filt], time_domain = True) pipeparts.mknxydumpsink(pipeline, head, "%s_out.txt" % name) # # done # return pipeline
def lal_resample_04(pipeline, name): # # This test passes noise through the resampler, downsampling and then upsampling # rate_in = 16384 # Hz rate_out = 2048 # Hz buffer_length = 1.0 # seconds test_duration = 10 # seconds quality = 5 # # build pipeline # head = test_common.test_src(pipeline, buffer_length=buffer_length, wave=5, freq=0.0, rate=rate_in, test_duration=test_duration, width=64) #head = calibration_parts.mkinsertgap(pipeline, head, bad_data_intervals = [-2, 2]) head = pipeparts.mktee(pipeline, head) pipeparts.mknxydumpsink(pipeline, head, "%s_in.txt" % name) head = pipeparts.mkgeneric(pipeline, head, "splitcounter") head = calibration_parts.mkresample( pipeline, head, quality, False, "audio/x-raw,format=F64LE,rate=%d" % rate_out) head = pipeparts.mkgeneric(pipeline, head, "splitcounter") head = pipeparts.mktee(pipeline, head) pipeparts.mknxydumpsink(pipeline, head, "%s_down.txt" % name) head = calibration_parts.mkresample( pipeline, head, quality, False, "audio/x-raw,format=F64LE,rate=%d" % rate_in) pipeparts.mknxydumpsink(pipeline, head, "%s_out.txt" % name) # # done # return pipeline
def lal_demodulate_03(pipeline, name): # # This test checks sensitivity of the demodulation process used in the calibration pipeline to small changes in line frequency # rate_in = 16384 # Hz rate_out = 16 # Hz buffer_length = 1.0 # seconds test_duration = 1000 # seconds # # build pipeline # # Make fake data with a signal src = test_common.test_src(pipeline, buffer_length=buffer_length, rate=rate_in, test_duration=test_duration, wave=0, volume=1.0, freq=37.00, width=64) # Demodulate it head = calibration_parts.demodulate(pipeline, src, 37.10, True, rate_out, 20, 0.0) # Smoothing # head = pipeparts.mkgeneric(pipeline, head, "lal_smoothkappas", array_size = 128 * rate_out, avg_array_size = 10 * rate_out) # Measure the amplitude of the result head = pipeparts.mkgeneric(pipeline, head, "cabs") head = pipeparts.mkaudioamplify(pipeline, head, 2.0) pipeparts.mknxydumpsink(pipeline, head, "%s_out.dump" % name) # # done # return pipeline
def lal_demodulate_01(pipeline, name): # # This test is to check that the inputs are multiplied by exp(2*pi*i*f*t) using the correct timestamps # rate = 1000 # Hz buffer_length = 1.0 # seconds test_duration = 10.0 # seconds # # build pipeline # src = test_common.test_src(pipeline, buffer_length=buffer_length, rate=rate, test_duration=test_duration, width=32) capsfilter1 = pipeparts.mkcapsfilter( pipeline, src, "audio/x-raw, format=F32LE, rate=%d" % int(rate)) tee1 = pipeparts.mktee(pipeline, capsfilter1) pipeparts.mknxydumpsink(pipeline, pipeparts.mkqueue(pipeline, tee1), "%s_in.dump" % name) demodulate = pipeparts.mkgeneric(pipeline, tee1, "lal_demodulate", line_frequency=100) capsfilter2 = pipeparts.mkcapsfilter( pipeline, demodulate, "audio/x-raw, format=Z64LE, rate=%d" % int(rate)) togglecomplex = pipeparts.mktogglecomplex(pipeline, capsfilter2) capsfilter3 = pipeparts.mkcapsfilter( pipeline, togglecomplex, "audio/x-raw, format=F32LE, rate=%d" % int(rate)) pipeparts.mknxydumpsink(pipeline, pipeparts.mkqueue(pipeline, capsfilter3), "%s_out.dump" % name) # # done # return pipeline
def pyfilter_test_01(pipeline, name): # # This test removes the DC component from a stream of ones (i.e., the result should be zero) # rate = 16384 # Hz buffer_length = 1.0 # seconds test_duration = 10.0 # seconds DC = 1.0 wave = 0 freq = 90 volume = 1.0 # # build pipeline # src = test_common.test_src(pipeline, buffer_length=buffer_length, rate=rate, freq=freq, test_duration=test_duration, wave=wave, width=64) head = pipeparts.mkaudioamplify(pipeline, src, volume) head = pipeparts.mkgeneric(pipeline, head, "lal_add_constant", value=DC) head = pipeparts.mktee(pipeline, head) pipeparts.mknxydumpsink(pipeline, head, "%s_in.txt" % name) head = calibration_parts.bandstop(pipeline, head, rate) pipeparts.mknxydumpsink(pipeline, head, "%s_out.txt" % name) # # done # return pipeline
def remove_lines_with_witnesses_test_01(pipeline, name): # # This tests generates a fake signal and fake witness channels # to test the removal of lines using the witnesses. # signal_rate = 1024 # Hz witness_rate = 1024 # Hz width = 64 buffer_length = 1.0 # seconds test_duration = 500.0 # seconds compute_rate = 16 # Hz f0 = 60 num_harmonics = 2 f0_var = 0.02 filter_latency = 1.0 use_gate = False signal = test_common.test_src(pipeline, buffer_length=buffer_length, rate=signal_rate, width=width, channels=1, test_duration=test_duration, wave=5, freq=0.1, volume=1, src_suffix="signal") witness0 = test_common.test_src(pipeline, buffer_length=buffer_length, rate=witness_rate, width=width, channels=1, test_duration=test_duration, wave=5, freq=0.1, volume=1, src_suffix="witness0") witness1 = test_common.test_src(pipeline, buffer_length=buffer_length, rate=witness_rate, width=width, channels=1, test_duration=test_duration, wave=5, freq=0.1, volume=1, src_suffix="witness1") witnesses = [witness0, witness1] noisesub_gate_bit = None if use_gate: signal = pipeparts.mktee(pipeline, signal) noisesub_gate_bit = calibration_parts.mkresample( pipeline, noisesub_gate_bit, 0, False, compute_rate) noisesub_gate_bit = pipeparts.mkgeneric(pipeline, noisesub_gate_bit, "lal_add_constant", value=3.0) noisesub_gate_bit = pipeparts.mkgeneric(pipeline, noisesub_gate_bit, "lal_typecast") noisesub_gate_bit = pipeparts.mkcapsfilter( pipeline, noisesub_gate_bit, "audio/x-raw, format=U32LE, rate=%d" % compute_rate) clean = calibration_parts.remove_harmonics_with_witnesses( pipeline, signal, witnesses, f0, num_harmonics, f0_var, filter_latency, compute_rate=compute_rate, rate_out=signal_rate, num_median=2048, num_avg=160, noisesub_gate_bit=noisesub_gate_bit) pipeparts.mknxydumpsink(pipeline, clean, "clean.txt") #signal = pipeparts.mktogglecomplex(pipeline, pipeparts.mkmatrixmixer(pipeline, signal, matrix = [[1.0,1.0]])) #witness0 = pipeparts.mktogglecomplex(pipeline, pipeparts.mkmatrixmixer(pipeline, witness0, matrix = [[1.0,1.0]])) #witness1 = pipeparts.mktogglecomplex(pipeline, pipeparts.mkmatrixmixer(pipeline, witness1, matrix = [[1.0,1.0]])) #allchan = [signal, witness0, witness1] #allchan = calibration_parts.mkinterleave(pipeline, allchan, complex_data = True) #allchan = pipeparts.mktee(pipeline, allchan) #pipeparts.mknxydumpsink(pipeline, allchan, "allchan.txt") #allchan = calibration_parts.mkdeinterleave(pipeline, allchan, 3, complex_data = True) #allchan = calibration_parts.mkadder(pipeline, allchan) #pipeparts.mknxydumpsink(pipeline, allchan, "allchan_sum.txt") # # done # return pipeline
def single_pole_filter_test(pipeline, name, line_sep=0.5): rate = 16384 # Hz buffer_length = 1.0 # seconds test_duration = 1000 # seconds fcc_rate = 16 # Hz gain = 1.1 fcc = 430 # Hz update_time = 20 # seconds # # build pipeline # # Make a source of fake data to act as input values for a gain and a zero gain_fcc_data = test_common.test_src(pipeline, rate=fcc_rate, test_duration=test_duration, wave=5, src_suffix="_gain_fcc_data") # Take to the power of 0 to make it a stream of ones gain_fcc_data = calibration_parts.mkpow(pipeline, gain_fcc_data, exponent=0.0) # Make a copy which we can use to make both the gain and the fcc data gain_fcc_data = pipeparts.mktee(pipeline, gain_fcc_data) # Make the gain data by multiplying ones by the gain gain_data = pipeparts.mkaudioamplify(pipeline, gain_fcc_data, gain) # Make the fcc data by multiplying ones by fcc fcc_data = pipeparts.mkaudioamplify(pipeline, gain_fcc_data, fcc) # Now, this needs to be used in the element lal_adaptivefirfilt to turn it into a FIR filter. # lal_adaptivefirfilt takes as inputs (in this order) zeros, poles, a complex factor containing gain and phase. # Type "$ gst-inspect-1.0 lal_adaptivefirfilt" for info about the element. # Each of the inputs must be a complex data stream, so we first must make these real streams complex gain_data = pipeparts.mktogglecomplex( pipeline, pipeparts.mkmatrixmixer(pipeline, gain_data, matrix=[[1.0, 0.0]])) fcc_data = pipeparts.mktogglecomplex( pipeline, pipeparts.mkmatrixmixer(pipeline, fcc_data, matrix=[[1.0, 0.0]])) # Now we must interleave these streams, since lal_adaptivefirfilt takes a single multi-channel stream of interleaved data. # The fcc data (the zero frequency) must come first so that it is channel 0; that way lal_adaptivefirfilt recognizes it as such. filter_data = calibration_parts.mkinterleave(pipeline, [fcc_data, gain_data], complex_data=True) # Finally, send the interleaved data to lal_adaptivefirfilt, which will make a FIR filter. # Note that it needs to know the number of zeros and poles. # update_samples tells it how often to send a new filter to the filtering element # minimize_filter_length must be True for it to use a 2-tap filter. Otherwise, it makes a longer FIR filter using and iFFT from a frequency-domain model. # This will also write the filter coefficients to file. adaptive_invsens_filter = calibration_parts.mkadaptivefirfilt( pipeline, filter_data, update_samples=int(update_time * fcc_rate), average_samples=1, num_zeros=1, num_poles=0, filter_sample_rate=rate, minimize_filter_length=True, filename="%s_FIR_filter.txt" % name) # Now make time series source of white noise to be filtered (wave = 5 means white noise) in_signal = test_common.test_src(pipeline, rate=rate, test_duration=test_duration, wave=5, src_suffix="_in_signal") # Make a copy of input data so that we can write it to file in_signal = pipeparts.mktee(pipeline, in_signal) # Write input time series to file pipeparts.mknxydumpsink(pipeline, in_signal, "%s_in.txt" % name) # Filter the data using lal_tdwhiten, which handles smooth filter updates # The property "kernel" is the FIR filter we will update. To start, give a trivial default value. # The "taper_length" is the number of samples over which to handle filter transitions. It is set to be 1 second. out_signal = pipeparts.mkgeneric(pipeline, in_signal, "lal_tdwhiten", kernel=[0, 1], latency=0, taper_length=rate) # Hook up the adaptive filter from lal_adaptivefirfilt to lal_tdwhiten so that the filter gets updated adaptive_invsens_filter.connect("notify::adaptive-filter", calibration_parts.update_filter, out_signal, "adaptive_filter", "kernel") # Correct the 1/2-sample shift in timestamps by applying a linear-phase FIR filter # The last argument here (0.5) is the number of samples worth of timestamp advance to apply to the data. You might want to try -0.5 as well, since I often get advances and delays mixed up. out_signal = calibration_parts.linear_phase_filter(pipeline, out_signal, 0.5) # Make a copy, so that we can write the time series to file and send it to lal_transferfunction out_signal = pipeparts.mktee(pipeline, out_signal) # Finally, write the output to file pipeparts.mknxydumpsink(pipeline, out_signal, "%s_out.txt" % name) # Now, take the input and output and compute a transfer function. # First, we need to interleave the data for use by lal_transferfunction. The numerator comes first tf_input = calibration_parts.mkinterleave(pipeline, [out_signal, in_signal]) # Remove some initial samples in case they were filtered by the default dummy filter [0, 1] tf_input = calibration_parts.mkinsertgap( pipeline, tf_input, chop_length=Gst.SECOND * 50) # Removing 50 s of initial data # Send to lal_transferfunction, which will compute the frequency-domain transfer function between the input and output data and write it to file calibration_parts.mktransferfunction( pipeline, tf_input, fft_length=16 * rate, fft_overlap=8 * rate, num_ffts=(test_duration - 50) / 8 - 3, use_median=True, update_samples=1e15, filename="%s_filter_transfer_function.txt" % name) # You could, for instance, compare this transfer function to what you expect, i.e., gain * (1 + i f / fcc), and plot the comparison in the frequency-domain. I'm guessing there will be a fair amount of work involved in getting everything to work and getting the result correct. # # done # return pipeline
def lal_fcc_update_01(pipeline, name): # # This test passes an impulse through the fcc_updater # data_rate = 16384 # Hz fcc_rate = 16 # Hz fcc_default = 360 # Hz fcc_update = 345 # Hz fcc_averaging_time = 5 # seconds fcc_filter_duration = 1 # seconds fcc_filter_taper_length = 32768 # seconds impulse_separation = 1.0 # seconds buffer_length = 1.0 # seconds test_duration = 10.0 # seconds # # build pipeline # src = pipeparts.mktee( pipeline, test_common.test_src(pipeline, buffer_length=buffer_length, wave=0, freq=1.0 / impulse_separation, rate=data_rate, test_duration=test_duration, width=64)) impulses = calibration_parts.mkinsertgap( pipeline, src, bad_data_intervals=[0.999999999, 1.00000001], block_duration=buffer_length * Gst.SECOND) impulses = pipeparts.mktee(pipeline, impulses) pipeparts.mknxydumpsink(pipeline, impulses, "%s_impulses.txt" % name) fcc = calibration_parts.mkresample( pipeline, src, 0, False, "audio/x-raw,format=F64LE,rate=%d" % fcc_rate) fcc = pipeparts.mkpow(pipeline, fcc, exponent=0.0) fcc = pipeparts.mkgeneric(pipeline, fcc, "lal_add_constant", value=fcc_update - 1) fcc = pipeparts.mktee(pipeline, fcc) pipeparts.mknxydumpsink(pipeline, fcc, "%s_fcc.txt" % name) update_fcc = pipeparts.mkgeneric(pipeline, fcc, "lal_fcc_update", data_rate=data_rate, fcc_rate=fcc_rate, fcc_model=fcc_default, averaging_time=fcc_averaging_time, filter_duration=fcc_filter_duration) pipeparts.mkfakesink(pipeline, update_fcc) default_fir_matrix = numpy.zeros( int( numpy.floor(data_rate * fcc_filter_duration / 2.0 + 1) * 2.0 - 2.0)) latency = int(data_rate * fcc_filter_duration / 2.0 + 1) default_fir_matrix[latency] = 1.0 res = pipeparts.mkgeneric(pipeline, impulses, "lal_tdwhiten", kernel=default_fir_matrix[::-1], latency=latency, taper_length=fcc_filter_taper_length) update_fcc.connect("notify::fir-matrix", fir_matrix_update, res) pipeparts.mknxydumpsink(pipeline, res, "%s_out.txt" % name) # # done # return pipeline
def lal_transferfunction_01(pipeline, name): # # This test adds various noise into a stream and uses lal_transferfunction to remove it # rate = 16384 # Hz buffer_length = 1.0 # seconds test_duration = 3000.0 # seconds width = 64 # bits # # build pipeline # hoft = test_common.test_src(pipeline, buffer_length=buffer_length, wave=5, volume=0.001, rate=rate, test_duration=test_duration, width=width, verbose=False) hoft = pipeparts.mktee(pipeline, hoft) common_noise = test_common.test_src(pipeline, buffer_length=buffer_length, wave=5, freq=512, volume=1, rate=rate, test_duration=test_duration, width=width, verbose=False) common_noise = pipeparts.mktee(pipeline, common_noise) noise1 = test_common.test_src(pipeline, buffer_length=buffer_length, wave=5, freq=512, volume=1, rate=rate, test_duration=test_duration, width=width, verbose=False) noise1 = calibration_parts.mkadder( pipeline, calibration_parts.list_srcs(pipeline, common_noise, noise1)) noise1 = pipeparts.mktee(pipeline, noise1) noise1_for_cleaning = pipeparts.mkgeneric(pipeline, noise1, "identity") hoft_noise1 = pipeparts.mkshift(pipeline, noise1, shift=00000000) hoft_noise1 = pipeparts.mkaudioamplify(pipeline, hoft_noise1, 2) hoft_noise1 = pipeparts.mktee(pipeline, hoft_noise1) noise2 = test_common.test_src(pipeline, buffer_length=buffer_length, wave=5, freq=1024, volume=1, rate=rate, test_duration=test_duration, width=width, verbose=False) noise2 = calibration_parts.mkadder( pipeline, calibration_parts.list_srcs(pipeline, common_noise, noise2)) noise2 = pipeparts.mktee(pipeline, noise2) noise2_for_cleaning = pipeparts.mkgeneric(pipeline, noise2, "identity") hoft_noise2 = pipeparts.mkshift(pipeline, noise2, shift=00000) hoft_noise2 = pipeparts.mkaudioamplify(pipeline, hoft_noise2, 3) hoft_noise2 = pipeparts.mktee(pipeline, hoft_noise2) noisy_hoft = calibration_parts.mkadder( pipeline, calibration_parts.list_srcs(pipeline, hoft, hoft_noise1, hoft_noise2)) noisy_hoft = pipeparts.mktee(pipeline, noisy_hoft) clean_hoft = calibration_parts.clean_data( pipeline, calibration_parts.list_srcs(pipeline, noisy_hoft, noise1_for_cleaning, noise2_for_cleaning), rate / 4, rate / 8, 16384, test_duration * rate) clean_hoft = pipeparts.mktee(pipeline, clean_hoft) # hoft_inv = pipeparts.mkpow(pipeline, hoft, exponent = -1.0) # clean_hoft_over_hoft = calibration_parts.mkmultiplier(pipeline, calibration_parts.list_srcs(pipeline, hoft_inv, clean_hoft)) # pipeparts.mknxydumpsink(pipeline, clean_hoft_over_hoft, "%s_clean_hoft_over_hoft.txt" % name) pipeparts.mknxydumpsink(pipeline, hoft, "%s_hoft.txt" % name) pipeparts.mknxydumpsink(pipeline, hoft_noise1, "%s_hoft_noise1.txt" % name) pipeparts.mknxydumpsink(pipeline, hoft_noise2, "%s_hoft_noise2.txt" % name) pipeparts.mknxydumpsink(pipeline, noisy_hoft, "%s_noisy_hoft.txt" % name) pipeparts.mknxydumpsink(pipeline, clean_hoft, "%s_clean_hoft.txt" % name) # # done # return pipeline
def lal_gate_01(pipeline, name): # # This pipeline tests the behavior of lal_gate with respect to attack_length, start-of-stream, etc. # rate = 512 # Hz buffer_length = 1.0 # seconds test_duration = 16 # seconds frequency = 0.1 # Hz attack_length = -3 # seconds hold_length = 0 # seconds threshold = 1.0 DC_offset = 1.0 # # build pipeline # # Make a sine wave src = test_common.complex_test_src(pipeline, buffer_length=buffer_length, rate=rate, test_duration=test_duration, wave=0, freq=frequency, width=64) # Add a DC offset head = pipeparts.mkgeneric(pipeline, src, "lal_add_constant", value=DC_offset) head = pipeparts.mktee(pipeline, head) pipeparts.mknxydumpsink(pipeline, head, "%s_in.txt" % name) control = test_common.test_src(pipeline, buffer_length=buffer_length, rate=rate, test_duration=test_duration, wave=0, volume=1.0, freq=frequency, width=64, src_suffix="_control") control = pipeparts.mkgeneric(pipeline, control, "lal_add_constant", value=DC_offset) #control = pipeparts.mkgeneric(pipeline, control, "splitcounter", name = "control") #head = pipeparts.mkgeneric(pipeline, head, "splitcounter", name = "before") # Gate it head = calibration_parts.mkgate(pipeline, head, control, threshold, attack_length=int(attack_length * rate), hold_length=int(hold_length * rate)) #head = pipeparts.mkgeneric(pipeline, head, "splitcounter", name = "after") real, imag = calibration_parts.split_into_real(pipeline, head) pipeparts.mknxydumpsink(pipeline, real, "%s_real_out.txt" % name) pipeparts.mknxydumpsink(pipeline, imag, "%s_imag_out.txt" % name) # # done # return pipeline
def lal_transferfunction_03(pipeline, name): # # This test produces three-channel data to be read into lal_transferfunction # rate = 16384 # Hz buffer_length = 1.0 # seconds test_duration = 50.0 # seconds width = 64 # bits freq = 512 # Hz num_witnesses = 2 witness_factor = 0.5 # Ratio of amplitudes of witness / signal # # build pipeline # hoft = test_common.test_src(pipeline, buffer_length=buffer_length, wave=5, volume=1, freq=freq, channels=1, rate=rate, test_duration=test_duration, width=width, verbose=False) hoft = pipeparts.mktee(pipeline, hoft) noise = [] for i in range(0, num_witnesses): difference = test_common.test_src(pipeline, buffer_length=buffer_length, wave=5, volume=0.001, channels=1, rate=rate, test_duration=test_duration, width=width, verbose=False) noisy_hoft = calibration_parts.mkadder( pipeline, calibration_parts.list_srcs( pipeline, pipeparts.mkaudioamplify(pipeline, hoft, witness_factor), difference)) noisy_hoft = pipeparts.mkprogressreport(pipeline, noisy_hoft, "noisy_hoft_%d" % i) noise.append(noisy_hoft) clean_data = calibration_parts.clean_data(pipeline, hoft, rate, noise, rate, 2 * rate, rate, 10, rate * 1000, rate, 4, filename="tfs.txt") pipeparts.mknxydumpsink(pipeline, hoft, "%s_hoft.txt" % name) pipeparts.mknxydumpsink(pipeline, clean_data, "%s_out.txt" % name) return pipeline
def lal_transferfunction_02(pipeline, name): # # This test produces three-channel data to be read into lal_transferfunction # rate = 16384 # Hz buffer_length = 1.0 # seconds test_duration = 500.0 # seconds width = 64 # bits channels = 1 freq = 512 # Hz # # build pipeline # hoft = test_common.test_src(pipeline, buffer_length=buffer_length, wave=5, volume=1, freq=freq, channels=channels, rate=rate, test_duration=test_duration, width=width, verbose=False) hoft = pipeparts.mktee(pipeline, hoft) noise = test_common.test_src(pipeline, buffer_length=buffer_length, wave=5, volume=1, freq=freq, channels=channels, rate=rate, test_duration=test_duration, width=width, verbose=False) noise = pipeparts.mktee(pipeline, noise) witness1 = calibration_parts.mkadder( pipeline, calibration_parts.list_srcs( pipeline, calibration_parts.highpass(pipeline, hoft, rate, fcut=400), calibration_parts.lowpass(pipeline, noise, rate, fcut=400))) witness2 = calibration_parts.mkadder( pipeline, calibration_parts.list_srcs( pipeline, calibration_parts.lowpass(pipeline, hoft, rate, fcut=600), calibration_parts.highpass(pipeline, noise, rate, fcut=600))) hoft = calibration_parts.highpass(pipeline, hoft, rate) clean_data = calibration_parts.clean_data( pipeline, hoft, rate, calibration_parts.list_srcs(pipeline, witness1, witness2), rate, 4 * rate, 2 * rate, 128, rate * test_duration, int(0.5 * rate), 10.0, filename="highpass_lowpass_tfs.txt") pipeparts.mknxydumpsink(pipeline, clean_data, "%s_out.txt" % name) return pipeline