0
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1 /*
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2 * Mex file that implements the core DFT part of the LPSD algorithm.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
3 *
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
4 * M Hewitson 15-01-08
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
5 *
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
6 * $Id: ltpda_dft.c,v 1.16 2009/08/18 10:53:27 hewitson Exp $
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
7 */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
8
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
9
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
10 #include <math.h>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
11 #include <stdio.h>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
12 #include <stdlib.h>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
13 #include <string.h>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
14 #include <mex.h>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
15
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
16 #include "ltpda_dft.h"
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
17 #include "version.h"
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
18 #include "../c_sources/polyreg.c"
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
19
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
20 #define DEBUG 0
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
21
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
22
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
23 /*
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
24 * Rounding function
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
25 *
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
26 */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
27 int myround(double x) {
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
28 return ((int) (floor(x + 0.5)));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
29 }
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
30
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
31
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
32 /*
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
33 * Matlab mex file to make a dft at a single frequency
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
34 *
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
35 * Inputs
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
36 * - data
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
37 * - seg length
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
38 * - DFT coefficients
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
39 * - overlap (%)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
40 * - order of detrending
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
41 *
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
42 * function [P, navs] = ltpda_dft(x, seglen, DFTcoeffs, olap, order);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
43 *
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
44 */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
45 void mexFunction( int nlhs, mxArray *plhs[],
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
46 int nrhs, const mxArray *prhs[]) {
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
47 /* Parse inputs */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
48 if( (nrhs == 0) && (nlhs == 0) ) {
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
49 print_usage(VERSION);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
50 return;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
51 }
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
52 else if ( (nrhs == 5) && (nlhs == 3) ) /* let's go */ {
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
53 double Pr, Vr;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
54 double *xdata, *Cr, *Ci;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
55 double olap;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
56 long int nData;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
57 long int nSegs;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
58 long int segLen;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
59 int order;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
60 double *ptr;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
61
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
62 if( !mxIsComplex(prhs[2]) )
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
63 mexErrMsgTxt("DFT coefficients must be complex.\n");
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
64
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
65 /* Extract inputs */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
66 xdata = mxGetPr(prhs[0]); /* Pointer to data */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
67 nData = mxGetNumberOfElements(prhs[0]); /* Number of data points */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
68 segLen = (int)mxGetScalar(prhs[1]); /* Segment length */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
69 Cr = mxGetPr(prhs[2]); /* Real part of DFT coefficients */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
70 Ci = mxGetPi(prhs[2]); /* Imag part of DFT coefficients */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
71 olap = mxGetScalar(prhs[3]); /* Overlap percentage */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
72 order = (int)mxGetScalar(prhs[4]); /* Order of detrending */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
73
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
74 if (order > 10 || order < -1)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
75 mexErrMsgTxt("Detrending order must be between -1 and 10");
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
76
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
77 /*mexPrintf("Input data: %d samples\n", nData);*/
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
78 /*mexPrintf("Segment length: %d\n", segLen);*/
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
79 /*mexPrintf("Overlap: %f\n", olap);*/
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
80
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
81 /* Compute DFT */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
82 dft(&Pr, &Vr, &nSegs, xdata, nData, segLen, Cr, Ci, olap, order);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
83
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
84 /* Set output matrices */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
85 plhs[0] = mxCreateDoubleMatrix(1, 1, mxCOMPLEX);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
86 plhs[1] = mxCreateDoubleMatrix(1, 1, mxCOMPLEX);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
87 plhs[2] = mxCreateDoubleMatrix(1, 1, mxCOMPLEX);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
88
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
89 /* Get pointers to output matrices */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
90 ptr = mxGetPr(plhs[0]);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
91 ptr[0] = Pr;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
92 ptr = mxGetPr(plhs[1]);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
93 ptr[0] = Vr;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
94 ptr = mxGetPr(plhs[2]);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
95 ptr[0] = nSegs;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
96
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
97 }
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
98 else if ( (nrhs == 6) && (nlhs == 5) ) /* let's go */ {
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
99 double Mr, Mi, XX, YY, M2;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
100 double *xdata, *ydata, *Cr, *Ci;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
101 double olap;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
102 long int nData, nxData, nyData;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
103 long int nSegs;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
104 long int segLen;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
105 int order;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
106 double *ptr;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
107
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
108 if( !mxIsComplex(prhs[3]) )
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
109 mexErrMsgTxt("DFT coefficients must be complex.\n");
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
110
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
111 /* Extract inputs */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
112 xdata = mxGetPr(prhs[0]); /* Pointer to data */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
113 ydata = mxGetPr(prhs[1]); /* Pointer to data */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
114 nxData = mxGetNumberOfElements(prhs[0]); /* Number of data points */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
115 nyData = mxGetNumberOfElements(prhs[0]); /* Number of data points */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
116 segLen = (int)mxGetScalar(prhs[2]); /* Segment length */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
117 Cr = mxGetPr(prhs[3]); /* Real part of DFT coefficients */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
118 Ci = mxGetPi(prhs[3]); /* Imag part of DFT coefficients */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
119 olap = mxGetScalar(prhs[4]); /* Overlap percentage */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
120 order = (int)mxGetScalar(prhs[5]); /* Order of detrending */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
121
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
122 if (order > 10 || order < -1)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
123 mexErrMsgTxt("Detrending order must be between -1 and 10");
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
124
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
125 if (nxData != nyData)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
126 mexErrMsgTxt("The two input data vector should be the same length.");
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
127
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
128 nData = nxData;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
129
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
130 /*mexPrintf("Input data: %d samples\n", nData);*/
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
131 /*mexPrintf("Segment length: %d\n", segLen);*/
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
132 /*mexPrintf("Overlap: %f\n", olap);*/
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
133
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
134 /* Compute DFT */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
135 xdft(&Mr, &Mi, &XX, &YY, &M2, &nSegs, xdata, ydata, nData, segLen, Cr, Ci, olap, order);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
136
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
137 /* Set output matrices */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
138 plhs[0] = mxCreateDoubleMatrix(1, 1, mxCOMPLEX);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
139 plhs[1] = mxCreateDoubleMatrix(1, 1, mxREAL);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
140 plhs[2] = mxCreateDoubleMatrix(1, 1, mxREAL);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
141 plhs[3] = mxCreateDoubleMatrix(1, 1, mxREAL);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
142 plhs[4] = mxCreateDoubleMatrix(1, 1, mxREAL);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
143
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
144 /* Get pointers to output matrices */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
145 ptr = mxGetPr(plhs[0]);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
146 ptr[0] = Mr;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
147 ptr = mxGetPi(plhs[0]);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
148 ptr[0] = Mi;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
149 ptr = mxGetPr(plhs[1]);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
150 ptr[0] = XX;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
151 ptr = mxGetPr(plhs[2]);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
152 ptr[0] = YY;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
153 ptr = mxGetPr(plhs[3]);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
154 ptr[0] = M2;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
155 ptr = mxGetPr(plhs[4]);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
156 ptr[0] = nSegs;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
157
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
158
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
159 }
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
160 else /* we have an error */ {
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
161 print_usage(VERSION);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
162 mexErrMsgTxt("### incorrect usage");
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
163 }
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
164 }
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
165
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
166 /*
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
167 * Output usage to MATLAB terminal
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
168 *
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
169 */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
170 void print_usage(char *version) {
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
171 mexPrintf("ltpda_dft version %s\n", version);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
172 mexPrintf(" usage: function [P, navs] = ltpda_dft(x, seglen, DFTcoeffs, olap, order); \n");
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
173 }
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
174
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
175 /*
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
176 * Short routine to compute the DFT at a single frequency
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
177 *
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
178 */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
179 void dft(double *Pr, double *Vr, long int *Navs,
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
180 double *xdata, long int nData, long int segLen, double *Cr, double *Ci, double olap, int order) {
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
181 long int istart;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
182 double shift, start;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
183 double *px, *cr, *ci;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
184 double rxsum, ixsum;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
185 double Xr, Mr, M2, Qr;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
186 double p, *x, *a;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
187 long int jj, ii;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
188
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
189
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
190 /* Compute the number of averages we want here */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
191 double ovfact = 1. / (1. - olap / 100.);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
192 double davg = ((double) ((nData - segLen)) * ovfact) / segLen + 1;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
193 long int navg = myround(davg);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
194
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
195 /* Compute steps between segments */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
196 if (navg == 1)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
197 shift = 1;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
198 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
199 shift = (double) (nData - segLen) / (double) (navg - 1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
200
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
201 if (shift < 1)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
202 shift = 1;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
203
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
204 /* mexPrintf("Seglen: %d\t | Shift: %f\t | navs: %d\n", segLen, shift, navg);*/
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
205
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
206 /* allocate vectors */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
207 x = (double*)mxCalloc(segLen, sizeof(double)); /* detrending output */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
208 a = (double*)mxCalloc(order+1, sizeof(double)); /* detrending coefficients */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
209
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
210 /* Loop over segments */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
211 start = 0.0;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
212 Xr = 0.0;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
213 Qr = 0.0;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
214 Mr = 0.0;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
215 M2 = 0.0;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
216
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
217 for (ii = 0; ii < navg; ii++) {
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
218 /* compute start index */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
219 istart = myround(start);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
220 start += shift;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
221
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
222 /* pointer to start of this segment */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
223 px = &(xdata[istart]);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
224
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
225 /* pointer to DFT coeffs */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
226 cr = &(Cr[0]);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
227 ci = &(Ci[0]);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
228
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
229 /* Detrend segment */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
230 switch (order) {
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
231 case -1:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
232 /* no detrending */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
233 memcpy(x, px, segLen*sizeof(double));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
234 break;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
235 case 0:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
236 /* mean removal */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
237 polyreg0(px, segLen, x, a);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
238 break;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
239 case 1:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
240 /* linear detrending */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
241 polyreg1(px, segLen, x, a);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
242 break;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
243 case 2:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
244 /* 2nd order detrending */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
245 polyreg2(px, segLen, x, a);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
246 break;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
247 case 3:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
248 /* 3rd order detrending */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
249 polyreg3(px, segLen, x, a);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
250 break;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
251 case 4:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
252 /* 4th order detrending */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
253 polyreg4(px, segLen, x, a);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
254 break;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
255 case 5:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
256 /* 5th order detrending */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
257 polyreg5(px, segLen, x, a);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
258 break;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
259 case 6:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
260 /* 6th order detrending */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
261 polyreg6(px, segLen, x, a);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
262 break;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
263 case 7:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
264 /* 7th order detrending */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
265 polyreg7(px, segLen, x, a);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
266 break;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
267 case 8:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
268 /* 8th order detrending */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
269 polyreg8(px, segLen, x, a);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
270 break;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
271 case 9:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
272 /* 9th order detrending */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
273 polyreg9(px, segLen, x, a);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
274 break;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
275 case 10:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
276 /* 10th order detrending */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
277 polyreg10(px, segLen, x, a);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
278 break;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
279 }
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
280
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
281 /* Go over all samples in this segment */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
282 rxsum = ixsum = 0.0;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
283 for (jj=0; jj<segLen; jj++) {
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
284 p = x[jj];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
285 rxsum += (*cr) * p; /* cos term */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
286 ixsum += (*ci) * p; /* sin term */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
287
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
288 /* increment pointers */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
289 cr++;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
290 ci++;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
291 }
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
292 /*mexPrintf(" xsum=(%g +i %g), ysum=(%g + i%g)\n", rxsum, ixsum, rysum, iysum);*/
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
293
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
294 /* Average the cross-power
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
295 * Rsum += rxsum*rxsum + ixsum*ixsum;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
296 */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
297
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
298 /* Welford's algorithm to update mean and variance */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
299 if (ii == 0) {
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
300 Mr = (rxsum*rxsum + ixsum*ixsum);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
301 } else {
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
302 Xr = (rxsum*rxsum + ixsum*ixsum);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
303 Qr = Xr - Mr;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
304 Mr += Qr/ii;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
305 M2 += Qr * (Xr - Mr);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
306 }
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
307
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
308 }
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
309
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
310 /* mexPrintf(" start: %f \t istart: %d | %d \n", start, istart, nData-istart);*/
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
311 /*mexPrintf(" Rsum=%g, MR=%g \n", Rsum,MR); */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
312
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
313 /* clean up */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
314 mxFree(x);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
315 mxFree(a);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
316
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
317 /* Outputs */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
318 *Pr = Mr;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
319 if(navg == 1){
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
320 *Vr = Mr*Mr;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
321 } else {
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
322 *Vr = M2/(navg-1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
323 }
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
324 *Navs = navg;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
325 }
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
326
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
327 /*
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
328 * Short routine to compute the cross-DFT at a single frequency
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
329 *
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
330 */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
331 void xdft(double *Pxyr, double *Pxyi, double *Pxx, double *Pyy, double *Vr, long int *Navs,
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
332 double *xdata, double *ydata, long int nData, long int segLen, double *Cr, double *Ci, double olap, int order) {
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
333 long int istart;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
334 double shift, start;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
335 double *px, *py, *cr, *ci;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
336 double rxsum, ixsum, rysum, iysum;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
337 double XYr, XYi, QXYr, QXYi, QXYrn, QXYin;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
338 double MXYr, MXYi, MXY2;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
339 double XX, YY, QXX, QYY;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
340 double MXX, MYY, MXX2, MYY2;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
341 double p, *x, *y, *a;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
342 double ct, st;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
343 long int jj, ii;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
344
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
345 /* Compute the number of averages we want here */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
346 double ovfact = 1. / (1. - olap / 100.);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
347 double davg = ((double) ((nData - segLen)) * ovfact) / segLen + 1;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
348 long int navg = myround( davg );
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
349
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
350 /* Compute steps between segments */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
351 if (navg == 1)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
352 shift = 1;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
353 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
354 shift = (double) (nData - segLen) / (double) (navg - 1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
355
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
356 if (shift < 1)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
357 shift = 1;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
358
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
359 /* mexPrintf("Seglen: %d\t | Shift: %f\t | navs: %d\n", segLen, shift, navg); */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
360
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
361 /* allocate vectors */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
362 y = (double*)mxCalloc(segLen, sizeof(double)); /* detrending output */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
363 x = (double*)mxCalloc(segLen, sizeof(double)); /* detrending output */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
364 a = (double*)mxCalloc(order+1, sizeof(double)); /* detrending coefficients */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
365
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
366 /* Loop over segments */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
367 start = 0.0;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
368 MXYr = 0.0;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
369 MXYi = 0.0;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
370 MXY2 = 0.0;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
371 MXX = 0.0;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
372 MYY = 0.0;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
373 MXX2 = 0.0;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
374 MYY2 = 0.0;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
375
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
376 for (ii = 0; ii < navg; ii++) {
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
377 /* compute start index */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
378 istart = myround(start);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
379 start += shift;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
380
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
381 /* pointer to start of this segment */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
382 px = &(xdata[istart]);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
383 py = &(ydata[istart]);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
384
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
385 /* pointer to DFT coeffs */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
386 cr = &(Cr[0]);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
387 ci = &(Ci[0]);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
388
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
389 /* Detrend segment */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
390 switch (order) {
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
391 case -1:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
392 /* no detrending */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
393 memcpy(x, px, segLen*sizeof(double));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
394 memcpy(y, py, segLen*sizeof(double));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
395 break;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
396 case 0:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
397 /* mean removal */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
398 polyreg0(px, segLen, x, a);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
399 polyreg0(py, segLen, y, a);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
400 break;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
401 case 1:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
402 /* linear detrending */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
403 polyreg1(px, segLen, x, a);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
404 polyreg1(py, segLen, y, a);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
405 break;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
406 case 2:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
407 /* 2nd order detrending */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
408 polyreg2(px, segLen, x, a);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
409 polyreg2(py, segLen, y, a);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
410 break;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
411 case 3:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
412 /* 3rd order detrending */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
413 polyreg3(px, segLen, x, a);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
414 polyreg3(py, segLen, y, a);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
415 break;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
416 case 4:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
417 /* 4th order detrending */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
418 polyreg4(px, segLen, x, a);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
419 polyreg4(py, segLen, y, a);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
420 break;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
421 case 5:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
422 /* 5th order detrending */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
423 polyreg5(px, segLen, x, a);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
424 polyreg5(py, segLen, y, a);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
425 break;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
426 case 6:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
427 /* 6th order detrending */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
428 polyreg6(px, segLen, x, a);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
429 polyreg6(py, segLen, y, a);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
430 break;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
431 case 7:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
432 /* 7th order detrending */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
433 polyreg7(px, segLen, x, a);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
434 polyreg7(py, segLen, y, a);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
435 break;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
436 case 8:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
437 /* 8th order detrending */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
438 polyreg8(px, segLen, x, a);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
439 polyreg8(py, segLen, y, a);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
440 break;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
441 case 9:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
442 /* 9th order detrending */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
443 polyreg9(px, segLen, x, a);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
444 polyreg9(py, segLen, y, a);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
445 break;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
446 case 10:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
447 /* 10th order detrending */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
448 polyreg10(px, segLen, x, a);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
449 polyreg10(py, segLen, y, a);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
450 break;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
451 }
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
452
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
453 /* Go over all samples in this segment */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
454 rxsum = ixsum = 0.0;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
455 rysum = iysum = 0.0;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
456 for (jj=0; jj<segLen; jj++) {
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
457 ct = (*cr);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
458 st = (*ci);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
459 p = x[jj];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
460 rxsum += ct * p; /* cos term */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
461 ixsum += st * p; /* sin term */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
462 p = y[jj];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
463 rysum += ct * p; /* cos term */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
464 iysum += st * p; /* sin term */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
465
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
466 /* increment pointers */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
467 cr++;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
468 ci++;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
469 }
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
470 /*mexPrintf(" xsum=(%g +i %g), ysum=(%g + i%g)\n", rxsum, ixsum, rysum, iysum);*/
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
471
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
472 /* Average XX and YY power
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
473 * XXsum += rxsum*rxsum + ixsum*ixsum;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
474 * YYsum += rysum*rysum + iysum*iysum;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
475 * XYRsum += rysum*rxsum + iysum*ixsum;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
476 * XYIsum += iysum*rxsum - rysum*ixsum; */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
477
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
478 /* Welford's algorithm to update mean and variance for cross-power */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
479 if (ii == 0) {
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
480 /* for XY */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
481 MXYr = rysum*rxsum + iysum*ixsum;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
482 MXYi = iysum*rxsum - rysum*ixsum;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
483 /* for XX */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
484 MXX = rxsum*rxsum + ixsum*ixsum;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
485 /* for YY */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
486 MYY = rysum*rysum + iysum*iysum;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
487 } else {
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
488 /* for XY cross - power */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
489 XYr = rysum*rxsum + iysum*ixsum;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
490 XYi = iysum*rxsum - rysum*ixsum;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
491 QXYr = XYr - MXYr;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
492 QXYi = XYi - MXYi;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
493 MXYr += QXYr/ii;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
494 MXYi += QXYi/ii;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
495 /* new Qs, using new mean */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
496 QXYrn = XYr - MXYr;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
497 QXYin = XYi - MXYi;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
498 /* taking abs to get real variance */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
499 MXY2 += sqrt(pow(QXYr * QXYrn - QXYi * QXYin, 2) + pow(QXYr * QXYin + QXYi * QXYrn, 2));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
500 /* for XX */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
501 XX = rxsum*rxsum + ixsum*ixsum;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
502 QXX = XX - MXX;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
503 MXX += QXX/ii;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
504 MXX2 += QXX*(XX - MXX);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
505 /* for YY */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
506 YY = rysum*rysum + iysum*iysum;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
507 QYY = YY - MYY;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
508 MYY += QYY/ii;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
509 MYY2 += QYY*(YY - MYY);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
510 }
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
511
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
512 }
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
513
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
514 /* mexPrintf(" start: %f \t istart: %d | %d \n", start, istart, nData-istart);*/
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
515 /*mexPrintf(" Rsum=%g, Isum=%g\n", Rsum, Isum);*/
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
516
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
517 /* clean up */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
518 mxFree(y);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
519 mxFree(x);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
520 mxFree(a);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
521
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
522 /* Outputs */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
523 *Pxyr = MXYr;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
524 *Pxyi = MXYi;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
525 if(navg == 1){
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
526 *Vr = MXYr*MXYr; /* set to mean^2 here, but at the end returns Inf in the ao.dy field */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
527 } else {
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
528 *Vr = MXY2/(navg-1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
529 }
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
530 *Pxx = MXX;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
531 *Pyy = MYY; /* we don't return variance for XX and YY */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
532 *Navs = navg;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
533 }
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
534
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
535 /*
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
536 * Fast linear detrending routine
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
537 *
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
538 */
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
539 void remove_linear_drift(double *segm, double *data, int nfft) {
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
540 int i;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
541 long double sx, sy, stt, sty, a, b, xm;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
542
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
543 sx = (long double) nfft *(long double) (nfft - 1) / 2.0L;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
544 xm = (long double) (nfft - 1) / 2.0L;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
545 stt = ((long double) nfft * (long double) nfft * (long double) nfft - (long double) nfft) / 12.0L;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
546
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
547 sy=sty = 0;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
548 for (i = 0; i < nfft; i++) {
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
549 sy += data[i];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
550 sty += (i-xm) * data[i];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
551 }
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
552 b = sty / stt;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
553 a = (sy - sx * b) / nfft;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
554 for (i = 0; i < nfft; i++) {
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
555 segm[i] = data[i] - (a + b * i);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
556 }
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
557 }
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
558
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
559
|