24 #define SWAP(a,b) temp=(a);(a)=(b);(b)=temp 26 void four1(
double data[],
unsigned long nn,
int isign)
34 unsigned long n,mmax,m,j,istep,i;
35 double wtemp,wr,wpr,wpi,wi,theta;
44 SWAP(data[j],data[i]);
45 SWAP(data[j+1],data[i+1]);
48 while (m >= 2 && j > m)
60 theta=isign*(6.28318530717959/mmax);
62 wpr = -2.0*wtemp*wtemp;
67 for (m=1;m<=mmax;m+=2)
69 for (i=m;i<=n;i+=istep)
72 temp=wr*data[j]-wi*data[j+1];
73 tempi=wr*data[j+1]+wi*data[j];
75 data[j+1]=data[i+1]-tempi;
79 wr=(wtemp=wr)*wpr-wi*wpi+wr;
80 wi=wi*wpr+wtemp*wpi+wi;
97 void four1(
double data[],
unsigned long nn,
int isign);
98 unsigned long i,i1,i2,i3,i4,np3;
99 double c1=0.5,
c2,h1r,h1i,h2r,h2i;
100 double wr,wi,wpr,wpi,wtemp,theta;
102 theta=3.141592653589793/(double) (n);
114 wtemp=sin(0.5*theta);
115 wpr = -2.0*wtemp*wtemp;
122 for (i=2;i<=(n/2)+1;i++)
124 i4=1+(i3=np3-(i2=1+(i1=i+i-1)));
125 h1r=c1*(data[i1]+data[i3]);
126 h1i=c1*(data[i2]-data[i4]);
127 h2r = -
c2*(data[i2]+data[i4]);
128 h2i=
c2*(data[i1]-data[i3]);
129 data[i1]=h1r+wr*h2r-wi*h2i;
130 data[i2]=h1i+wr*h2i+wi*h2r;
131 data[i3]=h1r-wr*h2r+wi*h2i;
132 data[i4] = -h1i+wr*h2i+wi*h2r;
133 wr=(wtemp=wr)*wpr-wi*wpi+wr;
134 wi=wi*wpr+wtemp*wpi+wi;
138 data[1] = (h1r=data[1])+data[2];
139 data[2] = h1r-data[2];
144 data[1]=c1*((h1r=data[1])+data[2]);
145 data[2]=c1*(h1r-data[2]);
159 long double y0, yn, FAC;
160 long double rn1, dummy, dummy1;
162 NMin = npix + 2 * pts;
175 kost = pow( (
double)pts / (
double)M, (
double)2.0);
180 rn1 = (double) (1.0 / (
double)(npix - 1));
187 for(i = 1; i<= npix;i++)
188 tmp[i] = tmp[i ] - rn1 * (y0 * (
double)(npix - i) + yn * (
double)(i - 1));
192 for(i = npix+1; i<M;i++)
199 tmp[1] = tmp[1] / MO2;
202 for (i=1; i <= (int) (MO2 - 1);i++)
206 if ((FAC > 0) | (FAC <0))
209 a = (1 - kost * pow((
double)i, (
double)2)) / MO2;
217 tmp[k] = FAC * tmp[k];
218 tmp[k + 1] = FAC * tmp[k + 1];
227 dummy = pow(((
double)0.25 * (
double)pts),(
double)2);
228 dummy1= (0.25 * pts) * (0.25 * pts);
229 a = (1 - pow(((
double)0.25 * (
double)pts),(
double)2)) / MO2;
233 tmp[2] = FAC * tmp[2];
241 for (i=1;i<=npix;i++)
243 tmp[i] = (tmp[i] + rn1 * (y0 * (
double)(npix - i) + yn * (
double)(i - 1)));
250 int FilterData(
unsigned short *mat,
int horpix,
int verpix,
int filw,
int bp)
257 unsigned long eln = (
unsigned long)(2 * (horpix - bp + 1)) ;
260 fd = fopen(
"FilterUS_In.tmp",
"w");
263 for(x = 0; x < horpix ; x++)
265 if ((x <= horpix - bp ) & (x > 1))
267 fprintf(fd,
"%04u ", x);
269 for(y = 0; y < verpix; y++)
271 fprintf(fd,
"%05u ", mat[y *
IDX + x]);
273 fprintf(fd,
"\n", NULL);
276 fprintf(fd,
"\n", NULL);
282 avect = (
double *) calloc( eln,
sizeof(
double));
283 else if((filw > 512) & (filw <1024))
284 avect = (
double *) calloc( 2*eln,
sizeof(
double));
285 else if((filw >= 1024) & (filw <2048))
286 avect = (
double *) calloc( 4*eln,
sizeof(
double));
292 for(y = 0; y < verpix; y++)
295 for(x = 0; x < horpix; x++)
297 if ((x < horpix - bp) & (x > 1))
299 avect[n] = (double)mat[y * (horpix) + x];
307 for(x = 0; x < horpix; x++)
309 if ((x < horpix - bp) & (x > 1))
311 mat[y * horpix + x] = (
unsigned int)avect[x - 1] ;
321 fd = fopen(
"FilterUS_Out.tmp",
"w");
325 for(x = 0; x < horpix ; x++)
327 if ((x <= horpix - bp ) & (x > 1))
329 fprintf(fd,
"%04u ", x);
331 for(y = 0; y < verpix; y++)
333 fprintf(fd,
"%05u ", mat[y *
IDX + x]);
335 fprintf(fd,
"\n", NULL);
338 fprintf(fd,
"\n", NULL);
351 double deltapoint = 0;
352 double deltapoint1 = 0;
356 for (i = 1;i<npix - 1;i++)
358 deltapoint = fabs( (
double)( (tmp[i+1] - tmp[i])/60000*100) );
359 deltapoint1 = fabs( (
double)( (tmp[i+1] - tmp[i+2])/60000*100) );
360 if( (deltapoint > 1.6) && (deltapoint1 > 1.6))
369 int RemoveSpikes(
int mod,
unsigned short *mat,
int horpix,
int verpix,
int blindpix)
375 unsigned long eln = (
unsigned long)(2 * (horpix - blindpix + 1)) ;
378 fd = fopen(
"Spikes.tmp",
"w");
381 for(x = 0; x < horpix ; x++)
383 if ((x <= horpix - blindpix ) & (x > 1))
385 fprintf(fd,
"%04u ", x);
387 for(y = 0; y < verpix; y++)
389 fprintf(fd,
"%05u ", mat[y *
IDX + x]);
391 fprintf(fd,
"\n", NULL);
394 fprintf(fd,
"\n", NULL);
399 avect = (
double *) calloc( eln,
sizeof(
double));
405 for(y = 0; y < verpix; y++)
408 for(x = 0; x < horpix; x++)
410 if ((x < horpix - blindpix) & (x > 1))
412 avect[n] = (double)mat[y * (horpix) + x];
420 for(x = 0; x < horpix; x++)
422 if ((x < horpix - blindpix) & (x > 1))
424 mat[y * horpix + x] = (
unsigned int)avect[x - 1] ;
434 fd = fopen(
"NoSpikes.tmp",
"w");
438 for(x = 0; x < horpix ; x++)
440 if ((x <= horpix - blindpix ) & (x > 1))
442 fprintf(fd,
"%04u ", x);
444 for(y = 0; y < verpix; y++)
446 fprintf(fd,
"%05u ", mat[y *
IDX + x]);
448 fprintf(fd,
"\n", NULL);
451 fprintf(fd,
"\n", NULL);
int IDX
Number of sensible horizontal pixels.
int CheckSpikes(int mod, double *tmp, int npix)
void four1(double data[], unsigned long nn, int isign)
int FilterData(unsigned short *mat, int horpix, int verpix, int filw, int bp)
unsigned int data[576]
Conversion data buffer 64 samples * 8 channels * 2 bytes.
int MMessageDialog(const char *t, const char *msg, const char *btn1, const char *btn2,...)
void realft(double data[], unsigned long n, int isign)
int SmoothingF(double *tmp, int npix, int pts)
Smoothing of 1D array.
int RemoveSpikes(int mod, unsigned short *mat, int horpix, int verpix, int blindpix)
Removes Spikes on a measure.