Copyright (c) 1993-2005 Tony Kirke
Motivation:Why use C++ for DSP Simulation/Modeling?
Todays IC and system designers typically use either C or costly 2nd party tools to simulate/model Digital Signal Processing algorithms. While the latter are well suited for modeling "hardwired" DSP blocks 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). while C is well suited to control logic type structures (if,else, case, etc.), it is not highly desireable for manipulation of complex or user defined data types (such as fixed width integers).
C++ bridges this gap and is the underlying language of choice for the cumbersome GUI based tools.
The objective of DSP Templates is to provide 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.
This Class Library
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.
Before discussing why C++ is better than C for DSP programming. Let's look at some of the pros and cons for C++ vs. the alternatives.
Please see links such as those below for why to use C++ over C in general.
Advantages of C++ over C
C++ allows templates and operator overloading.
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.
C++ allows for much better interfaces between classes or DSP blocks.
Because C++ supports initialization through constructors and there can be a variety of member functions, data can be handled in a much smoother manner than C. With data hiding, the code becomes much simpler to read, allowing a high level look at the code.
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.
For Hardware Modeling
C++ can be made to replicate hardware much easier than C. Functions and variables can be localised to each block (hiding complexity) in the same way that Verilog /VHDL does. Easier to have a hierarchical structure. Classes can be instantiated in same manner as in a HDL (C makes this difficult). 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.