## Product Description

Floating point to fixed point conversion is commonly met in signal processing and wireless system design. Most of time, initial algorithm is in floating point. When it is time to implement using hardware like ASIC or FPGA or using software method but on fixed point DSP, we need to convert floating point algorithm to fixed point. Matlab/Simulink can be used to achieve this but the speed is a big concern when algorithm is complicated and tool cost is also another concern.

This C based fixed point library is ideal in this case. It is fast, has no additional cost (using just g++ to compile) , is easy to understand (if you know C++ well ðŸ™‚ ),Â to the point, and supports both real and complex number.

Here are some sample codes.

**fixp.h (963 lines)**

typedef enum { FIXPOINT, FLOATPOINT} FIXP_DATATYPE; typedef enum { SIGNED, UNSIGNED } FIXP_SIGN; typedef enum { FLOOR, ROUND, CEIL } FIXP_ROUND; typedef enum { WRAP, SATURATE} FIXP_OVERFLOW; struct FIXP_CONF { FIXP_DATATYPE datatype; UINT8 wordlength; INT8 fractionlength; FIXP_SIGN sign; FIXP_ROUND round; FIXP_OVERFLOW overflow; }; ... public: FIXP(); FIXP(FLOAT x); FIXP(FLOAT x, const FIXP_CONF& x_conf); operator FLOAT () const; friend FIXP operator - (const FIXP& x); FIXP operator ++ (); FIXP operator ++ (int); FIXP operator -- (); FIXP operator -- (int); template friend FIXP operator + (const FIXP& x, const T& y); template friend FIXP operator + (const T& x, const FIXP& y); friend FIXP operator + (const FIXP& x, const FIXP& y); ... //--------------operator = --------------------------------------- inline FIXP& FIXP::operator = (const FIXP& x) { fp_assign(x.fp_value); #ifdef FIXP_ANAYSIS org_value = x.org_value; fp_analysis(); #endif return *this; }

**Here is the file list:**

- common.h defines some common variables
- fixp.cpp real number fixed point cpp
- fixp.h real number fixed point h file
- fixpcomp.cpp complex number fixed point cpp
- fixpcomp.h complex number fixed point h file
- tst1.c test file for real number case
- tst2.c test file for complex number case
- makefile makefile
- design_notes notes and issues met of how to use C++ to write this lib

**Here is some result:**

$ ./tst1 d is 12.9375, 12.9729 end e is 2.5, 2.70659 end

It shows variable d’s floating result is 12.9729 but due to fixed point conversion, it becomes 12.9375.

It also includes a very valuable note about how to use C++. Some samples:

1. "=" overload must be member function and it needs to release old mem, create and init new mem and return *this. Complex a(0.1,0.2) is equavalent to Complex a = Complex(0.1,0.2) and in both cases, "=" is not invoked and only constructor is invoked. if in left=right left already exists, "=" and not constructor is used.

If you want to understand and start your system design with c-based fixed point conversion in real world, this is ideal for you!

Only logged in customers who have purchased this product may leave a review.

## Reviews