Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

how to do quantize in C code?

Status
Not open for further replies.

boeysue

Full Member level 3
Joined
Dec 23, 2004
Messages
187
Helped
3
Reputation
6
Reaction score
0
Trophy points
1,296
Activity points
1,523
ceill cplusplus

How to do rounding /wrapping/ceilling..for any arbitary format...for signed number?
If there are any document for equation for C code?Thanks for that..
 

quantize float

There seems no fixed point function there??or where is the function?
 

c code floor round function efficiency

maybe this will help

#define adbits
double input[1023]
max_x = max(input)
min_x = min(x)
for i =1:1023
y(i) = (x(i)-min_x)/(max_x - min_x) *2^adbts
 

quantize floats

Use the scaling?But if not use scaling?how to do with rounding /wrapping??

Added after 3 minutes:

My demond is how to make a code to match the quantize in matlab.??
Because there is wrap/and ......./roundmode/ in matlab...
 

c++ quantize float to integer

I guess what you do is to use AND/OR operators on thier hexadecimal equivalents.
See here for the IEEE standard, and **broken link removed** for some examples on floating-point constants. This may also be of some help.
C++ has manipulators for fixed-point representation, but I havent seen any for C.
 

float round

Actually I just want to know the general equation of quantizer?
ex:
Fix_a= a*power(2,wordlen+1);
Fix_a+=1;
Fix_a>>=1;

somthing like that...If there are any simply document to explain it for arbitrary Q.format?such as [15 16],[15 14],[15 13],......

thanks for that.
 

float quantize c

I do integer/float/rounding stuff in C all the time, but somehow I'm not understanding your question. Are you new to C programming (and need help with type conversions), or are you looking for some more advanced function? Can you give us a specific example of what you want to do?
 

Quantization is the process of rounding off, but in the bit level. So I guess what the threadstarted wants is to convert floating point to fixed point. It is often used to execution time since floating point operations are expensive.

Here's something to start you thinking.
1. Rounding down is truncation after LSB.
2. Rounding off is the addition of 1/2 LSB, followed by truncation after LSB.
3. Rounding up is the addition of LSB, followed by truncation after LSB.

So the main issue is the truncation of LSB, which like I said, should be done in hexadecimal format using AND operators for maximum efficiency. Of course, if efficiency is not an issue, you could simply do multiplication, then do an integer truncation and track the rightful number of decimal places. Note that shift operators don't work with floats due to the IEEE float representation.

**broken link removed** some fixed-point arithmetic macros which could help.
 

mmm.....My question is the following:
1.What is the difference between ceil/floor/round using truncation?
2.How to write the "wrap overflowmode"??

The web is interesting ,but there is no such more information I want....
 

1. Some info from the 1999 C standard:

The ceil functions compute the smallest integer value not less than x.

#include <math.h>
double ceil(double x);
float ceilf(float x);
long double ceill(long double x);


The floor functions compute the largest integer value not greater than x.

#include <math.h>
double floor(double x);
float floorf(float x);
long double floorl(long double x);


The round functions round their argument to the nearest integer value in floating-point format, rounding halfway cases away from zero, regardless of the current rounding direction.

#include <math.h>
double round(double x);
float roundf(float x);
long double roundl(long double x);


2. Wrap overflow? Usually that's an annoying problem that occurs when you run out of bits. Do you want it to occur, or do you want to prevent it from occurring?
 

Wrap overflow? Usually that's an annoying problem that occurs when you run out of bits. Do you want it to occur, or do you want to prevent it from occurring?

Wrap overflow is better than saturation for difference between two numbers.I just want to it occur when overflow.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top