Bonjour,
j'ai trouvé un programme sur internet qui m'intéresse et je voudrais letraduire en c. Es-ce possible?
le voici:
CIC.h
cic.cpp
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
55
56
57
58
59
60
61 // // Copyright(c) 1993-1996 Tony Kirke // author="Tony Kirke" * /* * SPUC - Signal processing using C++ - A DSP library * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #ifndef CIC #define CIC namespace SPUC { /*! \addtogroup fir FIR filters */ /*! \brief class for CIC digital filter \ingroup fir interpolation */ //! //! Implementation for cascaded integrator comb filters //! This implementation provides for both decimation and //! interpolation filtering. Registers are signed long and //! the default number of stages is 3. //! \image html cic.gif //! \image latex cic.eps class cic { protected: signed long* nacc; //! Accumulators signed long* diff; //! Differentiators signed long* prev; //! Previous values char stages; //! Number of stages public: //! Constructor cic(char n=3); //! Reset void reset() { for (int i=0;i<stages;i++) nacc[i] = diff[i] = prev[i] = 0; } //! For CIC interpolation, non-zero dump implies new input signed long interpolate(signed long in=0, signed char dump=0); //! For CIC decimation, non-zero dump implies output required signed long decimate(signed long in, signed char dump); //! To change the number of stages dynamically void num_stages(char n); }; } // namespace SPUC #endif
Merci de votre aide.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77 // // Copyright(c) 1993-1996 Tony Kirke // author="Tony Kirke" * /* * SPUC - Signal processing using C++ - A DSP library * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ // See cic.h for description #include <cic.h> namespace SPUC { cic::cic(char n) : stages(n) { int i; nacc = new signed long[n]; diff = new signed long[n]; prev = new signed long[n]; for (i=0;i<stages;i++) nacc[i] = diff[i] = prev[i] = 0; } void cic::num_stages(char n) { int i; stages = n; delete nacc; delete diff; delete prev; nacc = new signed long[n]; diff = new signed long[n]; prev = new signed long[n]; for (i=0;i<stages;i++) nacc[i] = diff[i] = prev[i] = 0; } signed long cic::interpolate(signed long in, signed char dump) { char i; if (dump) { diff[0] = in - prev[0]; prev[0] = in; for (i=1;i<stages;i++) { diff[i] = diff[i-1] - prev[i]; prev[i] = diff[i-1]; } nacc[0] += diff[stages-1]; } for (i=0;i<(stages-1);i++) nacc[i+1] += nacc[i]; return(nacc[stages-1]); } signed long cic::decimate(signed long in, signed char dump) { char i; nacc[0] += in; for (i=0;i<(stages-1);i++) nacc[i+1] += nacc[i]; if (dump) { diff[0] = nacc[stages-1] - prev[0]; prev[0] = nacc[stages-1]; for (i=1;i<stages;i++) { diff[i] = diff[i-1] - prev[i]; prev[i] = diff[i-1]; } } return(diff[stages-1]); } } // namespace SPUC
Partager