1 | int comp_fir_basic(int input[], int h[], int z[], int N,int n) |
---|
2 | { |
---|
3 | int i,j,k; |
---|
4 | int y ; |
---|
5 | y = 0; |
---|
6 | /* calc FIR */ |
---|
7 | for(k=0;k<3;k=k+1){ |
---|
8 | |
---|
9 | /* store input at the beginning of the delay line */ |
---|
10 | z[0] = input[k]; |
---|
11 | for (i = 0; i < 3; i=i+1) { |
---|
12 | y = y +h[i] * z[i]; |
---|
13 | } |
---|
14 | |
---|
15 | /* shift delay line */ |
---|
16 | for (j = 2; j >=0; j=j-1) { |
---|
17 | z[j + 1] = z[j]; |
---|
18 | } |
---|
19 | } |
---|
20 | return y; |
---|
21 | } |
---|
22 | |
---|
23 | |
---|
24 | int comp_fir16(int in[], int c[], int out[], int size) { |
---|
25 | int i,j,res,tmp; |
---|
26 | int x[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; |
---|
27 | int adx =0; |
---|
28 | res =0; |
---|
29 | for (j=0;j<size;j++) { |
---|
30 | x[adx]=in[j]; |
---|
31 | for(i=0;i<16;i=i+1){ |
---|
32 | tmp = (x[adx]*c[i])*(2^16); |
---|
33 | res = res + tmp; |
---|
34 | adx=(adx+1)%16; |
---|
35 | } |
---|
36 | adx=(adx+1)%16; |
---|
37 | out[j]=res; |
---|
38 | } |
---|
39 | return x[0]; |
---|
40 | } |
---|
41 | |
---|
42 | int comp_ifFor (int a, int b, int pas) { |
---|
43 | int i, result; |
---|
44 | result = 0; |
---|
45 | for (i = 0; i < a; i=i+pas) { |
---|
46 | if (i != b) { |
---|
47 | result = result + i; |
---|
48 | } |
---|
49 | else { |
---|
50 | result = 0; |
---|
51 | } |
---|
52 | } |
---|
53 | return result; |
---|
54 | } |
---|
55 | |
---|
56 | int comp_total (int tabParam[], int a, int b) { |
---|
57 | int i, j, k; |
---|
58 | int tabLocal1[10] = {0,0,0,0,0,0,0,0,0,0}; |
---|
59 | int tabLocal2[10] = {0,0,0,0,0,0,0,0,0,0};; |
---|
60 | if (a < b) { |
---|
61 | for (i = 0; i <= a; i++) { |
---|
62 | tabLocal1[i] = tabParam[a-i]; |
---|
63 | } |
---|
64 | } |
---|
65 | else { |
---|
66 | for (k = 0; k < a; k++) { |
---|
67 | for (j = b; j > 0; j--) { |
---|
68 | tabParam[k] = tabLocal1[k]+tabLocal2[j]; |
---|
69 | } |
---|
70 | } |
---|
71 | } |
---|
72 | return 0; |
---|
73 | } |
---|
74 | |
---|
75 | int comp_tri (int t[], int n) { |
---|
76 | int i,j,tmp; |
---|
77 | tmp = 0; |
---|
78 | |
---|
79 | for(i = 0 ; (i < n); i=i+1) |
---|
80 | { |
---|
81 | for(j = 1 ; j < n- i ; j=j+1) |
---|
82 | { |
---|
83 | if(t[j] < t[j-1]) |
---|
84 | { |
---|
85 | tmp = t[j-1]; |
---|
86 | t[j-1] = t[j]; |
---|
87 | t[j] = tmp; |
---|
88 | } |
---|
89 | } |
---|
90 | } |
---|
91 | return tmp; |
---|
92 | } |
---|
93 | int comp_forif2 (int u[], int v[], int a, int b){ |
---|
94 | int i,j,k,l,res; |
---|
95 | k=0; |
---|
96 | l=0; |
---|
97 | for (i=0;i<a;i=i+1) { |
---|
98 | k = k+u[i]; |
---|
99 | } |
---|
100 | for (j=0;j<b;j=j+1) { |
---|
101 | l = l+v[j]; |
---|
102 | } |
---|
103 | if (k%2 == 0 && l%2 == 0) { |
---|
104 | res = 0; |
---|
105 | } |
---|
106 | else if (k%2 == 0) { |
---|
107 | res = 1; |
---|
108 | } |
---|
109 | else if (l%2 == 0) { |
---|
110 | res = 2; |
---|
111 | } |
---|
112 | else { |
---|
113 | res = 3; |
---|
114 | } |
---|
115 | return 0; |
---|
116 | } |
---|
117 | int comp_forif (){ |
---|
118 | int i,j,k; |
---|
119 | j=0;k=0; |
---|
120 | for (i=0;i<10;i=i+1) { |
---|
121 | j=j+1;j=j+1; |
---|
122 | if (i % 2 == 0) {k=k+1;} |
---|
123 | } |
---|
124 | return j; |
---|
125 | } |
---|
126 | |
---|
127 | int main(){ |
---|
128 | int a; |
---|
129 | int t[16] = {10,9,8,7,6,0,5,4,3,2,0,0,0,0,0,0}; |
---|
130 | a = comp_fir_basic(t,t,t,10,10); |
---|
131 | a = comp_fir16(t,t,t,16); |
---|
132 | a = comp_ifFor(4,1,1); |
---|
133 | a = comp_total(t,9,3); |
---|
134 | a = comp_tri(t,10); |
---|
135 | a = comp_forif2(t,t,10,10); |
---|
136 | a = comp_forif(); |
---|
137 | return a; |
---|
138 | } |
---|