labplot  2.8.2
About: LabPlot is an application for plotting and analysis of 2D and 3D functions and data. It is a complete rewrite of LabPlot1 and lacks in the first release a lot of features available in the predecessor. On the other hand, the GUI and the usability is more superior.
  Fossies Dox: labplot-2.8.2.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

nsl_sf_window.c
Go to the documentation of this file.
1 /***************************************************************************
2  File : nsl_sf_window.c
3  Project : LabPlot
4  Description : NSL special window functions
5  --------------------------------------------------------------------
6  Copyright : (C) 2016-2017 by Stefan Gerlach (stefan.gerlach@uni.kn)
7 
8  ***************************************************************************/
9 
10 /***************************************************************************
11  * *
12  * This program is free software; you can redistribute it and/or modify *
13  * it under the terms of the GNU General Public License as published by *
14  * the Free Software Foundation; either version 2 of the License, or *
15  * (at your option) any later version. *
16  * *
17  * This program is distributed in the hope that it will be useful, *
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
20  * GNU General Public License for more details. *
21  * *
22  * You should have received a copy of the GNU General Public License *
23  * along with this program; if not, write to the Free Software *
24  * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
25  * Boston, MA 02110-1301 USA *
26  * *
27  ***************************************************************************/
28 
29 #include "nsl_sf_window.h"
30 #include "nsl_common.h"
31 #include <gsl/gsl_math.h>
32 #include <gsl/gsl_sf_trig.h>
33 
34 const char* nsl_sf_window_type_name[] = {i18n("rectangular (uniform)"), i18n("triangular"), i18n("triangular II (Bartlett)"), i18n("triangular III (Parzen)") ,
35  i18n("Welch (parabolic)"), i18n("Hann (raised cosine)"), i18n("Hamming"), i18n("Blackman"), i18n("Nuttall"), i18n("Blackman-Nuttall"), i18n("Blackman-Harris"),
36  i18n("Flat top"), i18n("Cosine"), i18n("Bartlett-Hann"), i18n("Lanczos")};
37 
38 int nsl_sf_apply_window(double data[], size_t N, nsl_sf_window_type type) {
39  if (N == 0)
40  return -1;
41 
42  size_t i;
43  switch (type) {
45  /* do nothing */
46  break;
48  for (i = 0; i < N; i++)
49  data[i] = 1.0 - 2./N*fabs(i-(N-1)/2.);
50  break;
52  for (i = 0; i < N; i++)
53  data[i] = 1.0 - 2./(N-1)*fabs(i-(N-1)/2.);
54  break;
56  for (i = 0; i < N; i++)
57  data[i] = 1.0 - 2./(N+1)*fabs(i-(N-1)/2.);
58  break;
60  for (i = 0; i < N; i++)
61  data[i] = 1.0 - gsl_pow_2(2*(i-(N-1)/2.)/(N+1));
62  break;
63  case nsl_sf_window_hann:
64  for (i = 0; i < N; i++)
65  data[i] = 0.5*(1. - cos(2.*M_PI*i/(N-1)));
66  break;
68  for (i = 0; i < N; i++)
69  data[i] = 0.54 - 0.46*cos(2.*M_PI*i/(N-1));
70  break;
72  for (i = 0; i < N; i++)
73  data[i] = 0.42 - 0.5*cos(2.*M_PI*i/(N-1)) + 0.08*cos(4.*M_PI*i/(N-1));
74  break;
76  for (i = 0; i < N; i++)
77  data[i] = 0.355768 - 0.487396*cos(2.*M_PI*i/(N-1)) + 0.144232*cos(4.*M_PI*i/(N-1)) - 0.012604*cos(6.*M_PI*i/(N-1));
78  break;
80  for (i = 0; i < N; i++)
81  data[i] = 0.3635819 - 0.4891775*cos(2.*M_PI*i/(N-1)) + 0.1365995*cos(4.*M_PI*i/(N-1)) - 0.0106411*cos(6.*M_PI*i/(N-1));
82  break;
84  for (i = 0; i < N; i++)
85  data[i] = 0.35875 - 0.48829*cos(2.*M_PI*i/(N-1)) + 0.14128*cos(4.*M_PI*i/(N-1)) - 0.01168*cos(6.*M_PI*i/(N-1));
86  break;
88  for (i = 0; i < N; i++)
89  data[i] = 1 - 1.93*cos(2.*M_PI*i/(N-1)) + 1.29*cos(4.*M_PI*i/(N-1)) - 0.388*cos(6.*M_PI*i/(N-1)) + 0.028*cos(8.*M_PI*i/(N-1));
90  break;
92  for (i = 0; i < N; i++)
93  data[i] = sin(M_PI*i/(N-1));
94  break;
96  for (i = 0; i < N; i++)
97  data[i] = 0.62 - 0.48*fabs(i/(double)(N-1)-0.5) - 0.38*cos(2.*M_PI*i/(N-1));
98  break;
100  for (i = 0; i < N; i++)
101  data[i] = gsl_sf_sinc(2.*i/(N-1)-1.);
102  break;
103  }
104 
105  return 0;
106 }
#define i18n(m)
Definition: nsl_common.h:38
int nsl_sf_apply_window(double data[], size_t N, nsl_sf_window_type type)
Definition: nsl_sf_window.c:38
const char * nsl_sf_window_type_name[]
Definition: nsl_sf_window.c:34
nsl_sf_window_type
Definition: nsl_sf_window.h:35
@ nsl_sf_window_blackman_nuttall
Definition: nsl_sf_window.h:37
@ nsl_sf_window_triangleIII
Definition: nsl_sf_window.h:35
@ nsl_sf_window_bartlett_hann
Definition: nsl_sf_window.h:38
@ nsl_sf_window_hann
Definition: nsl_sf_window.h:36
@ nsl_sf_window_welch
Definition: nsl_sf_window.h:36
@ nsl_sf_window_lanczos
Definition: nsl_sf_window.h:38
@ nsl_sf_window_triangle
Definition: nsl_sf_window.h:35
@ nsl_sf_window_nuttall
Definition: nsl_sf_window.h:36
@ nsl_sf_window_triangleII
Definition: nsl_sf_window.h:35
@ nsl_sf_window_blackman_harris
Definition: nsl_sf_window.h:37
@ nsl_sf_window_flat_top
Definition: nsl_sf_window.h:37
@ nsl_sf_window_blackman
Definition: nsl_sf_window.h:36
@ nsl_sf_window_cosine
Definition: nsl_sf_window.h:37
@ nsl_sf_window_hamming
Definition: nsl_sf_window.h:36
@ nsl_sf_window_uniform
Definition: nsl_sf_window.h:35