diff --git a/gstlal-calibration/bin/gstlal_compute_strain b/gstlal-calibration/bin/gstlal_compute_strain index 74bf2c6998cba0bc09ec15d50c0c4b938c155dba..fc1e6fd6fe99acdd4ba8a85bed0a4a5302140640 100755 --- a/gstlal-calibration/bin/gstlal_compute_strain +++ b/gstlal-calibration/bin/gstlal_compute_strain @@ -1048,7 +1048,7 @@ if not options.no_kappac or not options.no_fcc or not options.no_kappapu or not # if options.apply_complex_kappapu: - # We will apply an adaptive FIR filter to the PUM\UIM component of the actuation that includes time-dependence in the gain and computational time delay + # We will apply an adaptive FIR filter to the PUM/UIM component of the actuation that includes time-dependence in the gain and computational time delay adaptive_pumuim_filter = pipeparts.mkgeneric(pipeline, smooth_kputee, "lal_adaptivefirfilt", update_samples = int(options.actuation_filter_update_time * options.compute_factors_sr), average_samples = int(options.actuation_filter_averaging_time * options.compute_factors_sr), phase_measurement_frequency = pu_act_esd_line_freq, static_filter = pumuimfilt, variable_filter_length = len(pumuimfilt), adaptive_filter_length = len(pumuimfilt), tukey_param = 0.5, filter_sample_rate = pumuimchainsr, filename = "adaptive_pumuim_filters.txt") if options.apply_complex_kappatst: diff --git a/gstlal-calibration/gst/cmath/Makefile.am b/gstlal-calibration/gst/cmath/Makefile.am index 04afb595237381729239478627f3bba26a7c53ec..fdec911a2b1124a3b6308141821487bc0d585852 100644 --- a/gstlal-calibration/gst/cmath/Makefile.am +++ b/gstlal-calibration/gst/cmath/Makefile.am @@ -11,7 +11,8 @@ libgstcmath_la_SOURCES = \ cmath_cln.c \ cmath_clog.c \ cmath_clog10.c \ - cmath_cpow.c + cmath_cpow.c \ + cmath_lpshiftfreq.c libgstcmath_la_CPPFLAGS = $(AM_CPPFLAGS) $(PYTHON_CPPFLAGS) libgstcmath_la_CFLAGS = $(AM_CFLAGS) $(LAL_CFLAGS) $(GSTLAL_CFLAGS) $(gstreamer_CFLAGS) $(gstreamer_audio_CFLAGS) libgstcmath_la_LDFLAGS = $(AM_LDFLAGS) $(LAL_LIBS) $(GSTLAL_LIBS) $(PYTHON_LIBS) $(gstreamer_LIBS) $(gstreamer_audio_LIBS) $(GSTLAL_PLUGIN_LDFLAGS) diff --git a/gstlal-calibration/gst/cmath/cmath.c b/gstlal-calibration/gst/cmath/cmath.c index 8975c0eb6d7ab3f9959ec47a041fcf4b78ee1e13..f07ca2b71bab7130d84cc2ff142448ed5a6aa576 100644 --- a/gstlal-calibration/gst/cmath/cmath.c +++ b/gstlal-calibration/gst/cmath/cmath.c @@ -52,14 +52,15 @@ */ -GType cmath_cabs_get_type (void); -GType cmath_creal_get_type (void); -GType cmath_cimag_get_type (void); -GType cmath_cexp_get_type (void); -GType cmath_cln_get_type (void); -GType cmath_clog_get_type (void); -GType cmath_clog10_get_type (void); -GType cmath_cpow_get_type (void); +GType cmath_cabs_get_type(void); +GType cmath_creal_get_type(void); +GType cmath_cimag_get_type(void); +GType cmath_cexp_get_type(void); +GType cmath_cln_get_type(void); +GType cmath_clog_get_type(void); +GType cmath_clog10_get_type(void); +GType cmath_cpow_get_type(void); +GType cmath_lpshiftfreq_get_type(void); static gboolean @@ -72,14 +73,15 @@ plugin_init (GstPlugin *plugin) } *element, elements[] = { { "cmath_base", CMATH_BASE_TYPE}, { - "cabs", cmath_cabs_get_type ()}, { - "creal", cmath_creal_get_type ()}, { - "cimag", cmath_cimag_get_type ()}, { - "cexp", cmath_cexp_get_type ()}, { - "cln", cmath_cln_get_type ()}, { - "clog", cmath_clog_get_type ()}, { - "clog10", cmath_clog10_get_type ()}, { - "cpow", cmath_cpow_get_type ()}, { + "cabs", cmath_cabs_get_type()}, { + "creal", cmath_creal_get_type()}, { + "cimag", cmath_cimag_get_type()}, { + "cexp", cmath_cexp_get_type()}, { + "cln", cmath_cln_get_type()}, { + "clog", cmath_clog_get_type()}, { + "clog10", cmath_clog10_get_type()}, { + "cpow", cmath_cpow_get_type()}, { + "lpshiftfreq", cmath_lpshiftfreq_get_type()}, { NULL, 0},}; /* diff --git a/gstlal-calibration/gst/cmath/cmath_lpshiftfreq.c b/gstlal-calibration/gst/cmath/cmath_lpshiftfreq.c new file mode 100644 index 0000000000000000000000000000000000000000..973d4c2dcb91c07de863b79cccf39c2eb40325d7 --- /dev/null +++ b/gstlal-calibration/gst/cmath/cmath_lpshiftfreq.c @@ -0,0 +1,211 @@ +/* + * Copyright (C) 2018 Aaron Viets + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + + +#include <cmath_base.h> + +#define TYPE_CMATH_LPSHIFTFREQ \ + (cmath_lpshiftfreq_get_type()) +#define CMATH_LPSHIFTFREQ(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST((obj),TYPE_CMATH_LPSHIFTFREQ,CMathLPShiftFreq)) +#define CMATH_LPSHIFTFREQ_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST((klass),TYPE_CMATH_LPSHIFTFREQ,CMathLPShiftFreqClass)) +#define IS_PLUGIN_TEMPLATE(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE((obj),TYPE_CMATH_LPSHIFTFREQ)) +#define IS_PLUGIN_TEMPLATE_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE((klass),TYPE_CMATH_LPSHIFTFREQ)) + +typedef struct _CMathLPShiftFreq CMathLPShiftFreq; +typedef struct _CMathLPShiftFreqClass CMathLPShiftFreqClass; + +GType +cmath_lpshiftfreq_get_type(void); + +struct _CMathLPShiftFreq +{ + CMathBase cmath_base; + double frequency_ratio; +}; + +struct _CMathLPShiftFreqClass +{ + CMathBaseClass parent_class; +}; + + +/* + * ============================================================================ + * + * GstBaseTransform vmethod Implementations + * + * ============================================================================ + */ + +/* An in-place transform really does the same thing as the chain function */ + +static GstFlowReturn transform_ip(GstBaseTransform *trans, GstBuffer *buf) +{ + CMathLPShiftFreq* element = CMATH_LPSHIFTFREQ(trans); + int bits = element -> cmath_base.bits; + int is_complex = element -> cmath_base.is_complex; + + GstMapInfo info; + if(!gst_buffer_map(buf, &info, GST_MAP_READWRITE)) { + GST_ERROR_OBJECT(trans, "gst_buffer_map failed\n"); + } + gpointer data = info.data; + gpointer data_end = data + info.size; + + const double n = element->frequency_ratio; + + if(is_complex == 1) { + + if(bits == 128) { + double complex *ptr, *end = data_end; + for(ptr = data; ptr < end; ptr++) { + *ptr = cabs(*ptr) * cexp(I * carg(*ptr) * n); + } + } else if(bits == 64) { + float complex *ptr, *end = data_end; + for(ptr = data; ptr < end; ptr++) { + *ptr = cabsf(*ptr) * cexpf(I * cargf(*ptr) * (float) n); + } + } else { + g_assert_not_reached(); + } + } else if(is_complex == 0) { + + /* Really, this is not the purpose of this element, but we'll just multiply by the frequency ratio */ + if(bits == 64) { + double *ptr, *end = data_end; + for(ptr = data; ptr < end; ptr++) { + *ptr = *ptr * n; + } + } else if(bits == 32) { + float *ptr, *end = data_end; + for(ptr = data; ptr < end; ptr++) { + *ptr = *ptr * (float) n; + } + } else { + g_assert_not_reached(); + } + } else { + g_assert_not_reached(); + } + gst_buffer_unmap(buf, &info); + return GST_FLOW_OK; +} + + +/* + * ============================================================================ + * + * Type Support + * + * ============================================================================ + */ + +/* Set the frequency ratio */ +enum property +{ + PROP_FREQUENCY_RATIO = 1, +}; + +static void +set_property(GObject * object, enum property id, const GValue * value, + GParamSpec * pspec) +{ + CMathLPShiftFreq *element = CMATH_LPSHIFTFREQ(object); + + GST_OBJECT_LOCK(element); + + switch(id) { + case PROP_FREQUENCY_RATIO: + element->frequency_ratio = g_value_get_double(value); + break; + } + + GST_OBJECT_UNLOCK(element); +} + +static void +get_property(GObject * object, enum property id, GValue * value, + GParamSpec * pspec) +{ + CMathLPShiftFreq *element = CMATH_LPSHIFTFREQ(object); + + GST_OBJECT_LOCK(element); + + switch(id) { + case PROP_FREQUENCY_RATIO: + g_value_set_double(value, element->frequency_ratio); + break; + } + + GST_OBJECT_UNLOCK(element); +} + +/* Initialize the plugin's class */ +static void +cmath_lpshiftfreq_class_init(gpointer klass, gpointer klass_data) +{ + GObjectClass *gobject_class = G_OBJECT_CLASS(klass); + GstBaseTransformClass *basetransform_class = GST_BASE_TRANSFORM_CLASS(klass); + + gst_element_class_set_details_simple(GST_ELEMENT_CLASS(klass), + "Multiply phase of a complex number", + "Filter/Audio", + "This element reads in a complex stream and multiplies the phase by a\n\t\t\t " + "constant without affecting the magnitude. This can be useful when a\n\t\t\t " + "function whose phase is proportional to frequency has a known value at a\n\t\t\t " + "particular frequency, and the user wishes to evaluate it at a different\n\t\t\t " + "frequency.", + "Aaron Viets <aaron.viets@ligo.org>"); + + basetransform_class -> transform_ip = GST_DEBUG_FUNCPTR(transform_ip); + basetransform_class -> set_caps = GST_DEBUG_FUNCPTR(set_caps); + + gobject_class->get_property = GST_DEBUG_FUNCPTR(get_property); + gobject_class->set_property = GST_DEBUG_FUNCPTR(set_property); + + g_object_class_install_property(gobject_class, + PROP_FREQUENCY_RATIO, + g_param_spec_double("frequency-ratio", + "Frequency Ratio", + "The factor by which you want to multiply the phase. In the above example,\n\t\t\t" + "this is equal to the ratio of the frequencies.", + -G_MAXDOUBLE, G_MAXDOUBLE, 2., + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT)); +} + +GType +cmath_lpshiftfreq_get_type(void) +{ + static GType type = 0; + + if(!type) { + static const GTypeInfo info = { + .class_size = sizeof(CMathBaseClass), + .class_init = cmath_lpshiftfreq_class_init, + .instance_size = sizeof(CMathLPShiftFreq), + }; + type = g_type_register_static(CMATH_BASE_TYPE, "CMathLPShiftFreq", &info, 0); + } + + return type; +}