Shop

Make it to the Right and Larger Audience

Placeholder

Floating to Fixed Point C Conversion Tool


$50.00

IP : zip, 8.75 KB


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:

  1. common.h defines some common variables
  2. fixp.cpp real number fixed point cpp
  3. fixp.h real number fixed point h file
  4. fixpcomp.cpp complex number fixed point cpp
  5. fixpcomp.h complex number fixed point h file
  6. tst1.c test file for real number case
  7. tst2.c test file for complex number case
  8. makefile makefile
  9. 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!

Reviews

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

Got something to discuss?


26/03/2016

Interesting. I have been using matlab fixedpoint blockbox for my graduate project. This C++ library sounds a very good solution.

 

Contact Us

Thanks for helping us better serve the community. You can make a suggestion, report a bug, a misconduct, or any other issue. We'll get back to you using your private message ASAP.

Sending

©2019  ValPont.com

Forgot your details?