Subversion Repositories svnkaklik

Rev

Rev 524 | Rev 526 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download

// jednoduchy algoritmus krizove korelace
// copile gcc correlation.c -lm -o correlation

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int sample[100];
int signal[500];

double correlation[1000];

int obdelnik(int *pole, int delka_pole, int delka_pulsu, int spozdeni) //generuje testovaci lichobeznikovy puls  do zadaneho pole
{
int i;
int value=1;
  for (i=0; i <= delka_pole; i++) { 
    if (i < spozdeni && i < delka_pole) pole[i]=value;

    if ((i > spozdeni) && (i < (spozdeni+10))) pole[i] = value++;

    if (i < (spozdeni+delka_pulsu+10) && i > (spozdeni+10) && i < delka_pole) pole[i]= value;      

    if (i < (spozdeni+delka_pulsu+20) && i > (spozdeni+delka_pulsu+10) && i < delka_pole) pole[i] = value--;      

    if (i > (spozdeni+delka_pulsu+20) && i < delka_pole) pole[i]=value;
  }
}

int linear_chirp(int *pole, int delka_pole, int delka_pulsu, int spozdeni){

static const double pi = 3.141592653589793238462643383279502884197; // Archimedes constant pi
static const float f0 = 1;
static const float k = 1;

int t;

//  for(t=0;t < delka_pole;t++){ pole[t] = (int) ( 100*sin(2*pi*t*(f0+(k/2)*t)) ) ;
//  }
  for(t=0;t < delka_pole;t++){ pole[t] = (int) ( 100*sin(t/2) ) ;
  }
}

int main (void)
{
   int i,n,m,delay;
   double r;

   linear_chirp(sample,100,10,0);                       // vyrobi vzorek signalu
   obdelnik(signal,500,10,100);                 // vyrobi signal ve kterem se vzorek hleda

   for(n=0; n < 400;n++){                       //spocita korelaci pro mozna spozdeni
     r=0;
     for(m=0;m < 100;m++) r += sample[m]*signal[m+n];
     correlation[n]=r;
   }

   r=0;
   for(n=0; n < 400;n++){                       //najde nejvetsi shodu (pro nazornost v samostatnem cyklu)
     if (r < correlation[n]){
       delay = n;
       r = correlation[n];
     }
   }


   for(i=0;i<400;i++)
   {
     fprintf(stdout,"%3u ",i);                  // vypise cislo bunky v poli (spozdeni)
     fprintf(stdout,"%2d ",sample[i]);
//     fprintf(stdout,"%2d ",signal[i]);
//     fprintf(stdout,"%3.2f\n",correlation[i]);                // vypise hodnotu korelace nejvissi cislo je nejvetsi korelace.
   }
   fprintf(stdout,"\nvzorek v signalu zacina na miste: %3u \n",delay);

  exit(1);
}