-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask2.c
More file actions
54 lines (43 loc) · 1.57 KB
/
Copy pathtask2.c
File metadata and controls
54 lines (43 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include "1436508610_103__compact_coeff.h"
#include "1436508628_101__compact_R.h"
#include <stdio.h>
float Timing_Synchronization(int *Samples,int *Coeff);
float modulo=0;
const float DetThr=1e+15;
float mod_out;
int i,j,sample[256];
int main()
{
for(j=0;j<256;j++) sample[j]=0; // intialization, not necessary on a simulator, may be needed on a board// Parsing one by one all input samples. Every time we add a sample in slot 1, // we shift all samples of one unit and we remove the sample in slot 256, then we run the FIR again
for(i=0;i<3394;i++) {
for(j=255;j>0;j--) sample[j]=sample[j-1];sample[0]=R[i];
mod_out=Timing_Synchronization(sample,coef);
if (mod_out>=DetThr)
{
// BOOOOOOOONG!!!!! Synchronization Achieved!!! // Hint -> Place a Breakpoint here for performance measurements!
return(i); //whenever the peak is found the system quits. // (in the simulation data the peak is located at i=715)
};
}
}
float Timing_Synchronization(int *Samples,int *Coeff)
{
int k;
//int n=255;
float re1=0; //real part of the first vector
float im1=0; //imaginary part of the first vector
float im2=0;
float re2=0;
float accRe=0;//accumalated real
float accIm=0;//accumalated imaginary
for (k=0; k<256; k++)
{
re1=(float)(Samples[k]>>16);//get top 16 bits
im1=(float)((Samples[k]<<16)>>16); //get lower 16
re2=(float)(Coeff[k]>>16);//get top 16 bits
im2=(float)((Coeff[k]<<16)>>16);
accRe+= (re1*re2)- (im1*im2);
accIm+=(re1*im2)+(re2*im1);
}
modulo=(accRe*accRe)+(accIm*accIm);
return modulo;
}