1 /*! \mainpage
2  * SPUC - Signal processing using C++ - A DSP library
3  * <p>Copyright (C) 1993-2005 Tony Kirke.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2, or (at your option)
8  * any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17 
18  <H1>Signal Processing using C++ (SPUC)</H1>
19  <P><B>Motivation:Why use C++ for DSP Simulation/Modeling?</B>
20 	 <P>Todays IC and system designers typically use either C or costly
21 	 2<SUP>nd</SUP> party tools to simulate/model Digital Signal Processing
22 	 algorithms. While the latter are well suited for modeling "hardwired" DSP blocks
23 	 with rather simplistic dataflows, they are very inefficient for modeling the control logic that is often required in todays DSP applications (such as ADSL or V.34 modems).
24 	 while C is well suited to control logic type structures (if,else, case, etc.), it is not highly desireable for manipulation of complex
25 	 or user defined data types (such as fixed width integers).
26 	 </P>
27 	 <P><I>C++ bridges this gap and is the underlying language of choice
28 	 for the cumbersome GUI based tools.</I></P>
29 	 <HR>
30 
31 	 <P><B>Objective</B></P>
32 	 <P>The objective of SPUC is to provide the Communications Systems Designer or DSP Algorithm designer with simple, efficient and reusable DSP building block objects. Thus allowing a transition from System design to implementation in either programmable DSP chips or hardwired DSP logic. While Matlab is perhaps the most useful available tool for this purpose, it can be quite slow for simulation and it favors a matrix/block based approach rather than the sample by sample simulations that are often most useful for communications systems design. Also Matlab is generally awkward or inefficient when dealing with several interactive feedback loops where C/C++ is perhaps the most useful environment. For bit-accurate simulations (for VLSI design) C/C++ generally outperforms and is easier to manipulate than Matlab or other GUI-based tools.</P>
33 	 <P>This Class Library</P>
34 	 <ul> <li> 1) basic building blocks such as complex data types, Fixed-bit width integer classes, pure-delay blocks, etc.
35 	 <li> 2) Basic DSP building blocks such as FIR, IIR, Allpass, Running Average, Lagrange interpolation filters, NCO, Cordic rotator.
36 	 <li> 3) Several communications functions such as timing, phase and frequency discriminators for BPSK/QPSK signals.
37 	 <li> 4) Other miscellaneous DSP/Communications related functions/classes.
38 	 <li> 5) Ability to design several types of FIR and IIR filters
39 	 <li> 6) Various adaptive equalizer classes
40 	 <li> 7) This library now includes code from IT 3.7.0.
41 	 Code was modified to work together with SPUC and replace Vector and Matrix classes from TNT.
42      <li> 8) Capitalized and uppercase class names are classes not originally in SPUC
43 	 </ul>
44 
45 
46 	 The classes are designed so that they can be used in a simple straight forward manner. For example, a FIR would be initialized with its tap weights and then simply a member function would be called every time a sample is input or an output is required.
47 	 <p>For downloading files go to<p>
48 	 <P><A HREF="http://sourceforge.net/projects/spuc/"><B>Project Page at Sourceforge</B></A>
49 
50 	 <P>Before discussing why C++ is better than C for DSP programming. Let's look at some of the pros and cons
51 	 for C++ vs. the alternatives.
52 
53 	 <P><B>Pros</B>
54 	 <ul><li>  The common alternatives are very costly (Alta's SPW, Synopsys Cossap etc.)
55 	 <li>    Long learning times/training not required for C++ programmers.
56 	 <li>   For complex simulations, C++ is more efficient and yields shorter run times.
57 	 <li>   Ideal for modeling a combination of control logic and hardwired DSP blocks.
58 	 <li>   Code entry can be faster than GUI based tools.
59 	 <li>  Looks closer to Verilog/VHDL than alternative tools.
60 	 <li>  C/C++ has a large user base.
61 	 <li>  Lots of freely available C/C++ code.
62 	 <li>  Infinitely customizable.
63 	 <li>  Portable to different platforms.
64 	 <li>  Can take advantage of Windows GUIs if desired.
65 	 </ul>
66 
67 	 <P><B>Cons</B>
68 	 <ul><li>    No standardization!
69 	 <li>    Lack of documentation.
70 	 <li>    Not user friendly/ No GUI.
71 	 <li>    Potential portability problems.
72 	 <li>    No technical support.
73 	 </ul>
74 
75 
76 	 <BR> Please see links such as those below for why to use C++ over C in general.
77 	 <BR><A HREF="http://www.cantrip.org/cpp.html">Nathan Myers C++ Articles</A>
78 	 <BR><A HREF="http://math.nist.gov/pozo/c++class/">C++ Programming for Scientists Course (PDF) from NIST</A>
79 	 <BR><A HREF="http://math.nist.gov/pozo/">Various C++ Math classes from Roldan Pozo at NIST</A>
80 	 <P><B>Advantages of C++ over C</B>
81 	 <UL>
82 	 <LI>Object Oriented Language</LI>
83 	 <LI>Abstract Data typing</LI>
84 	 <LI>Inheritance</LI>
85 	 <LI>Polymorphism</LI>
86 	 <LI>Comments do not extend over more than one line</LI>
87 	 <LI>Variables can be declared anywhere.</LI>
88 	 <LI>Dynamic memory allocation is simpler.</LI>
89 	 <LI>Function Overloading</LI>
90 	 </UL>
91 
92 	 <P><B>C++ allows templates and operator overloading.</B>
93 	 <BR>For example, we can define a complex data type based on templates. Then this class can be used whether we need floating point (double), integer, or user defined fixed bit width data types.This not only requires less code to document/debug, but also through operator overloading we can make the code much easier to read and potentially make the look and feel very close to a Hardware Description Language (HDL)such as Verilog or VHDL. Also this style makes it much easier to change your programs data types (from floating point -> integer -> fixed bit width for example), without having to change every line of code.
94 	 <P><B>C++ allows for much better interfaces between classes or DSP blocks.</B>
95 	 <BR>Because C++ supports initialization through constructors
96 	 and there can be a variety of member functions, data can be handled in
97 	 a much smoother manner than C. With data hiding, the code becomes much
98 	 simpler to read, allowing a high level look at the code.
99 
100 	 <P><B>Inheritance</B>
101 	 <BR>Inheritance helps you to re-use code.You can derive new types or classes from an old one and make changes only where you need them. This promotes code re-use.
102 	 <P><B>Classes</B>
103 	 </center>
104 	 <UL><LI>Hide complexity.</LI>
105 	 <LI>Create a more convenient object oriented interfaces</LI>
106 	 <LI>Can create more than one instance of a structure.</LI>
107 	 <LI>Similar to C structure but can include functions.</LI>
108 	 <LI>Data abstraction and hiding allows changes to be localized to one section.</LI>
109 	 <LI>Private, Protected, Public members</LI></UL>
110 
111 	 <P><B>For Hardware Modeling</B>
112 	 <BR>C++ can be made to replicate hardware much easier than C.
113 	 Functions and variables can be localised to each block (hiding complexity) in the same way that Verilog /VHDL does.
114 	 Easier to have a hierarchical structure.
115 	 Classes can be instantiated in same manner as in a HDL (C makes this difficult).
116 	 New chip designs can inherit subblocks or a large section from an old design. Only the new or changed blocks need to be coded. Also the interfaces to the chip can remain the same if desired. When classes are designed in this manner it is quite easy to see the difference between objects.
117 
118 
119 */
120 //!  SPUC - Signal processing using C++ - A DSP library
121 //! includes code from other sources including IT++ 3.7.0
122 //! \namespace SPUC
123 namespace SPUC {
124 //! \file
125 //! \brief Various Defined Constants and Macros
126 //! \author Tony Kirke,  Copyright(c) 2001
127 #ifndef MYINCLUDE
128 #define MYINCLUDE
129 #define MAXINT	32767
130 #define MXLONG 4294967295
131 #define BIG	72057594037927936.		// Maximum precision of DOUBLE */
132 #define HUGED	1.701411733192644270e38 	// Largest DOUBLE */
133 #define LOGHUGE 39				// 10^39 --> Largest power */
134 #define LN2	0.69314718055994530941
135 #define ILN2	1.4426950408889634 // 1/LN2
136 #define LN10	2.30258509299404568401
137 #define E	2.7182818284590452353602874
138 #define SQRT2	1.41421356237309504880
139 #define HALFSQRT2	.70710678118654752440
140 #ifndef PI
141 #define PI	3.141592653589793238462643
142 #endif
143 //#define pi PI
144 #define QUARTPI 0.78539816339744830962
145 #define HALFPI	1.57079632679489661923
146 #define TWOPI	6.28318530717958647692
147 #define RADPDEG 0.01745329251994329576
148 #define RTD  57.295781  // radian to decimal conversion factor
149 
150 // macros
151 
152 #define SQR(x)	((x) * (x))
153 #define SGN(x)	((x) < 0 ? -1 : 1)
154 #define XSWAP(a,b) a ^= b, b ^= a, a ^= b
155 #define SWAP(a,b,c) c = a, a = b, b = c
156 #ifndef MAX
157 #define MAX(x,y)	((x) >= (y) ? (x) : (y))
158 #endif
159 #ifndef MIN
160 #define MIN(x,y)	((x) <= (y) ? (x) : (y))
161 #endif
162 #ifndef ABS
163 #define ABS(x) ( (x < 0) ? (-x) : (x))
164 #endif
165 //#define abs(x)		((x)<0? -(x):(x))	// Integer Absolute value */
166 //#define fabs(x) 	((x)<0.? -(x):(x))	// Floating absolute value */
167 #define MODULO(x,y)	((x)%(y))		//  Integer modulo */
168 #define LOGE(x) 	(log(x))		// Natural log */
169 #define LN(x)		(log(x))		// Natural log */
170 #define MASK_LOW(n)	((1<<n) - 1)
171 #define MASK_BIT(n) (1<<n)
172 #define MASK_NEG_HI(n)	(-1<<(32-n))
173 #define CLIP(A,B,C) (A>B) ? B : ((A<C) ? C : A)
174 typedef long natural;
175 #endif
176 // End of spuc.h
177 }
178