Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-21 10:03:47

0001 /* filter/gsl_filter.h
0002  * 
0003  * Copyright (C) 2018 Patrick Alken
0004  * 
0005  * This program is free software; you can redistribute it and/or modify
0006  * it under the terms of the GNU General Public License as published by
0007  * the Free Software Foundation; either version 3 of the License, or (at
0008  * your option) any later version.
0009  * 
0010  * This program is distributed in the hope that it will be useful, but
0011  * WITHOUT ANY WARRANTY; without even the implied warranty of
0012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0013  * General Public License for more details.
0014  * 
0015  * You should have received a copy of the GNU General Public License
0016  * along with this program; if not, write to the Free Software
0017  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
0018  */
0019 
0020 #ifndef __GSL_FILTER_H__
0021 #define __GSL_FILTER_H__
0022 
0023 #include <gsl/gsl_math.h>
0024 #include <gsl/gsl_vector.h>
0025 #include <gsl/gsl_movstat.h>
0026 
0027 #undef __BEGIN_DECLS
0028 #undef __END_DECLS
0029 #ifdef __cplusplus
0030 # define __BEGIN_DECLS extern "C" {
0031 # define __END_DECLS }
0032 #else
0033 # define __BEGIN_DECLS /* empty */
0034 # define __END_DECLS /* empty */
0035 #endif
0036 
0037 __BEGIN_DECLS
0038 
0039 /* end point handling methods */
0040 typedef enum
0041 {
0042   GSL_FILTER_END_PADZERO = GSL_MOVSTAT_END_PADZERO,
0043   GSL_FILTER_END_PADVALUE = GSL_MOVSTAT_END_PADVALUE,
0044   GSL_FILTER_END_TRUNCATE = GSL_MOVSTAT_END_TRUNCATE
0045 } gsl_filter_end_t;
0046 
0047 /* robust scale estimates */
0048 typedef enum
0049 {
0050   GSL_FILTER_SCALE_MAD, /* median absolute deviation */
0051   GSL_FILTER_SCALE_IQR, /* interquartile range */
0052   GSL_FILTER_SCALE_SN,  /* S_n scale statistic */
0053   GSL_FILTER_SCALE_QN   /* Q_n scale statistic */
0054 } gsl_filter_scale_t;
0055 
0056 /* workspace for Gaussian filter */
0057 typedef struct
0058 {
0059   size_t K;        /* window size */
0060   double *kernel;  /* Gaussian kernel, size K */
0061   gsl_movstat_workspace *movstat_workspace_p;
0062 } gsl_filter_gaussian_workspace;
0063 
0064 gsl_filter_gaussian_workspace *gsl_filter_gaussian_alloc(const size_t K);
0065 void gsl_filter_gaussian_free(gsl_filter_gaussian_workspace * w);
0066 int gsl_filter_gaussian(const gsl_filter_end_t endtype, const double alpha, const size_t order, const gsl_vector * x,
0067                         gsl_vector * y, gsl_filter_gaussian_workspace * w);
0068 int gsl_filter_gaussian_kernel(const double alpha, const size_t order, const int normalize, gsl_vector * kernel);
0069 
0070 /* workspace for standard median filter */
0071 typedef struct
0072 {
0073   gsl_movstat_workspace *movstat_workspace_p;
0074 } gsl_filter_median_workspace;
0075 
0076 gsl_filter_median_workspace *gsl_filter_median_alloc(const size_t K);
0077 void gsl_filter_median_free(gsl_filter_median_workspace * w);
0078 int gsl_filter_median(const gsl_filter_end_t endtype, const gsl_vector * x, gsl_vector * y, gsl_filter_median_workspace * w);
0079 
0080 /* workspace for recursive median filter */
0081 typedef struct
0082 {
0083   size_t H;                            /* window half-length (K / 2) */
0084   size_t K;                            /* window size */
0085   void *state;                         /* workspace for min/max accumulator */
0086   double *window;                      /* array holding first window */
0087   const gsl_movstat_accum * minmaxacc; /* minimum/maximum accumulator */
0088   gsl_movstat_workspace *movstat_workspace_p;
0089 } gsl_filter_rmedian_workspace;
0090 
0091 gsl_filter_rmedian_workspace *gsl_filter_rmedian_alloc(const size_t K);
0092 void gsl_filter_rmedian_free(gsl_filter_rmedian_workspace * w);
0093 int gsl_filter_rmedian(const gsl_filter_end_t, const gsl_vector * x, gsl_vector * y, gsl_filter_rmedian_workspace * w);
0094 
0095 typedef struct
0096 {
0097   gsl_movstat_workspace *movstat_workspace_p;
0098 } gsl_filter_impulse_workspace;
0099 
0100 gsl_filter_impulse_workspace *gsl_filter_impulse_alloc(const size_t K);
0101 void gsl_filter_impulse_free(gsl_filter_impulse_workspace * w);
0102 int gsl_filter_impulse(const gsl_filter_end_t endtype, const gsl_filter_scale_t scale_type, const double t,
0103                        const gsl_vector * x, gsl_vector * y, gsl_vector * xmedian, gsl_vector * xsigma, size_t * noutlier,
0104                        gsl_vector_int * ioutlier, gsl_filter_impulse_workspace * w);
0105 
0106 __END_DECLS
0107 
0108 #endif /* __GSL_FILTER_H__ */