PIPS
corr.c
Go to the documentation of this file.
1 /* corr.c - sample cross correlation of two length-N signals */
2 
3 #include "tools.h"
4 
5 void corr(int N, float x[N], float y[N], int M, float R[M]) /* computes \‍(R[k]\‍), \‍(k = 0, 1,\dotsc, M\‍) */
6  /* \‍(x,y\‍) are \‍(N\‍)-dimensional */
7  /* \‍(R\‍) is \‍((M+1)\‍)-dimensional */
8 {
9  int k, n;
10 
11  for (k=0; k<M; k++)
12  for (R[k]=0, n=0; n<N-k; n++)
13  R[k] += x[n+k] * y[n] / N;
14 }
15 
16 #include <stdlib.h>
17 #include <stdio.h>
18 #include "tools.h"
19 int main(int argc, char **argv) {
20  int n = atoi(argv[1]);
21  int k = 5;
22  //int k = atoi(argv[3]);
23  float (*in)[n] = (float (*)[n])malloc(sizeof(float)*(1+n));
24  float (*in2)[n] = (float (*)[n])malloc(sizeof(float)*(1+n));
25  float (*out)[k] = (float (*)[n])malloc(sizeof(float)*(k));
26  init_args(argc, argv);
27  init_data_float(*in,n);
28  init_data_float(*in2,n);
29 
30  if (argc>20) k=10;
31  struct timeval s,e;
32  gettimeofday(&s,NULL);
33  corr(n,*in,*in2,k,*out);
34  gettimeofday(&e,NULL);
35  double diff = (double)(e.tv_sec-s.tv_sec)*1000.0 +
36  (double)(e.tv_usec-s.tv_usec)/1000.0;
37  printf("%0.6f\n", diff);
38  return 0;
39 }
static FILE * out
Definition: alias_check.c:128
int main(int argc, char **argv)
Definition: corr.c:19
void corr(int N, float x[N], float y[N], int M, float R[M])
corr.c - sample cross correlation of two length-N signals
Definition: corr.c:5
void * malloc(YYSIZE_T)
int printf()
static char * x
Definition: split_file.c:159
void init_args(int argc, char **argv)
Definition: tools.c:151
int init_data_float(float *ptr, const unsigned int n)
Definition: tools.c:125