Operators
[Basic]


Detailed Description

All the fixed point operators functions currently implemented in the DSP library.

Benchmark on the AT32UC targets


Multiplication

These functions multiply two fixed-point numbers.

Relative functions:


Division

These functions divide two fixed-point numbers. Relative functions:


Sine

These functions compute the sine of the argument 'angle'.
Note:
Angle is scaled to fit in the range [-1; 1], where -1 corresponds to -pi and 1 to pi.
Relative functions:


Cosine

These functions compute the cosine of the argument 'angle'. Angles are scale to fit in the range [-1; 1], where -1 corresponds to -pi and 1 to pi. Relative functions:


Arc sine

These functions compute the arc sine of the argument.
Note:
The output is scaled to fit in the range [-0.5; 0.5], where -0.5 corresponds to -pi/2 and 0.5 to pi/2.
Relative functions:


Arc cosine

These functions compute the arc cosine of the argument.
Note:
The output is scaled to fit in the range [0.; 1.], where 0. corresponds to 0. and 1. to pi.
Relative functions:


Absolute

These functions compute the absolute value of the argument. Relative functions:


Square root

These functions compute the square root of the argument. Relative functions:


Natural logarithm

These functions compute the natural logarithm of the argument. Relative functions:

Note:
The output will be limit in the range of the fixed point format used.

Binary logarithm or base 2 logarithm

These functions compute the binary logarithm of the argument.
Note:
The output will be limit in the range of the fixed point format used.
Relative functions:


Common logarithm or base 10 logarithm

These functions compute the common logarithm of the argument.
Note:
The output will be limit in the range of the fixed point format used.
Relative functions:


Exponential

These functions compute the exponential of the argument.
Note:
The output will be limit in the range of the fixed point format used.
Relative functions:


Power

These functions compute x^y.
Note:
The output will be limit in the range of the fixed point format used.
Relative functions:


Random

These functions generate a pseudo-radomized number Relative functions:



Functions

static dsp16_t dsp16_op_abs (dsp16_t number)
 16-bit fixed point version of the absolute function.
static dsp16_t dsp16_op_acos (dsp16_t number)
 16-bit fixed point version of the arc cosine function.
dsp16_t dsp16_op_asin (dsp16_t number)
 16-bit fixed point version of the arc sine function.
static dsp16_t dsp16_op_cos (dsp16_t angle)
 16-bit fixed point version of the cosine function.
static dsp16_t dsp16_op_div (dsp16_t num, dsp16_t den)
 16-bit fixed point version of the division function.
dsp16_t dsp16_op_exp (dsp16_t number)
 16-bit fixed point version of the exponential function.
dsp16_t dsp16_op_ln (dsp16_t number)
 16-bit fixed point version of the natural logarithm function.
dsp16_t dsp16_op_log10 (dsp16_t number)
 16-bit fixed point version of the common logarithm function.
dsp16_t dsp16_op_log2 (dsp16_t number)
 16-bit fixed point version of the binary logarithm function.
static dsp16_t dsp16_op_mul (dsp16_t num1, dsp16_t num2)
 16-bit fixed point version of the multiplication function.
dsp16_t dsp16_op_pow (dsp16_t x, dsp16_t y)
 16-bit fixed point version of the power function.
dsp16_t dsp16_op_rand ()
 16-bit fixed point version of the random operator.
dsp16_t dsp16_op_sin (dsp16_t angle)
 16-bit fixed point version of the sine function.
dsp16_t dsp16_op_sqrt (dsp16_t number)
 16-bit fixed point version of the square root function.
static dsp32_t dsp32_op_abs (dsp32_t number)
 32-bit fixed point version of the absolute function.
static dsp32_t dsp32_op_acos (dsp32_t number)
 32-bit fixed point version of the arc cosine function.
dsp32_t dsp32_op_asin (dsp32_t number)
 32-bit fixed point version of the arc sine function.
static dsp32_t dsp32_op_cos (dsp32_t angle)
 32-bit fixed point version of the cosine function.
static dsp32_t dsp32_op_div (dsp32_t num, dsp32_t den)
 32-bit fixed point version of the division function.
dsp32_t dsp32_op_exp (dsp32_t number)
 32-bit fixed point version of the exponential function.
dsp32_t dsp32_op_ln (dsp32_t number)
 32-bit fixed point version of the natural logarithm function.
dsp32_t dsp32_op_log10 (dsp32_t number)
 32-bit fixed point version of the common logarithm function.
dsp32_t dsp32_op_log2 (dsp32_t number)
 32-bit fixed point version of the binary logarithm function.
static dsp32_t dsp32_op_mul (dsp32_t num1, dsp32_t num2)
 32-bit fixed point version of the multiplication function.
dsp32_t dsp32_op_pow (dsp32_t x, dsp32_t y)
 32-bit fixed point version of the power function.
dsp32_t dsp32_op_rand ()
 32-bit fixed point version of the random operator.
dsp32_t dsp32_op_sin (dsp32_t angle)
 32-bit fixed point version of the sine function.
dsp32_t dsp32_op_sqrt (dsp32_t number)
 32-bit fixed point version of the square root function.
void dsp_op_srand (int new_seed)
 Initialize the pseudo-random number generator.


Function Documentation

static dsp16_t dsp16_op_abs ( dsp16_t  number  )  [inline, static]

16-bit fixed point version of the absolute function.

Parameters:
number The number to compute
Returns:
The absolute value of the number.

Definition at line 267 of file dsp_operators.h.

Referenced by dsp16_filt_lpfirdesign(), dsp16_op_asin(), dsp16_op_exp(), dsp16_op_pow(), and dsp16_win_gauss().

00267 { return (number < 0)?-number:number; }

static dsp16_t dsp16_op_acos ( dsp16_t  number  )  [inline, static]

16-bit fixed point version of the arc cosine function.

Parameters:
number The number to compute
Returns:
The arc cosine of 'number' is returned.
Note:
If you are using a number greater than 1 (or lower than -1) for the 'number', the function will limit the output to the range [0.; 1.].

Definition at line 240 of file dsp_operators.h.

References dsp16_op_asin(), and DSP16_Q.

00240 { return (DSP16_Q(0.5)-1) - dsp16_op_asin(number); }

dsp16_t dsp16_op_asin ( dsp16_t  number  ) 

16-bit fixed point version of the arc sine function.

Parameters:
number The number to compute
Returns:
The arc sine of 'number' is returned.
Note:
If you are using a number greater than 1 (or lower than -1) for the 'number', the function will limit the output to the range [-0.5; 0.5].

Definition at line 61 of file op_fix_asin.c.

References A, B, C, D, dsp16_op_abs(), dsp16_op_asin(), dsp16_op_sqrt(), DSP16_Q, and DSP16_QB.

Referenced by dsp16_op_acos(), and dsp16_op_asin().

00062 {
00063   S32 num_sqr, res;
00064   dsp16_t num_abs;
00065 
00066   num_abs = dsp16_op_abs(num);
00067   
00068 #if DSP16_QB < 15
00069   // Limits
00070   if (((S32) num) >= ((S32) DSP16_Q(1.)))
00071     return DSP16_Q(0.5);
00072   if (((S32) num) <= ((S32) DSP16_Q(-1.)))
00073     return DSP16_Q(-0.5);
00074 #endif
00075 
00076   // If |num| > 0.5
00077   if (num_abs > DSP16_Q(0.5))
00078   {
00079     num_abs = dsp16_op_sqrt((DSP16_Q(1.)-num_abs) >> 1);
00080     num_abs = DSP16_Q(0.5) - (dsp16_op_asin(num_abs) << 1);
00081     return (num < 0)?-num_abs:num_abs;
00082   }
00083   else
00084   {
00085     num_sqr = (((S32) num)*((S32) num)) >> DSP16_QB;
00086     res = (num_sqr*DSP16_Q(D)) >> DSP16_QB;
00087     res = (num_sqr*(res + DSP16_Q(C))) >> DSP16_QB;
00088     res = (num_sqr*(res + DSP16_Q(B))) >> DSP16_QB;
00089     num = (((S32) num)*(res + DSP16_Q(A))) >> (DSP16_QB + 1);
00090 
00091     return num;
00092   }
00093 }

static dsp16_t dsp16_op_cos ( dsp16_t  angle  )  [inline, static]

16-bit fixed point version of the cosine function.

Parameters:
angle The angle to compute
Returns:
The cosine of 'angle' is returned.
Note:
If you are using a number greater than 1 (or lower than -1) for the angle, the function will take the modulo 1 of this angle.

Definition at line 178 of file dsp_operators.h.

References dsp16_op_sin(), and DSP16_Q.

Referenced by dsp16_gen_cos(), dsp16_win_black(), dsp16_win_hamm(), and dsp16_win_hann().

00178 { return dsp16_op_sin(angle + DSP16_Q(0.5)); }

static dsp16_t dsp16_op_div ( dsp16_t  num,
dsp16_t  den 
) [inline, static]

16-bit fixed point version of the division function.

Parameters:
num The numerator of the division.
den The denominator of the division.
Returns:
The result of the division.

Definition at line 118 of file dsp_operators.h.

References DSP16_QB.

Referenced by dsp16_filt_lpfirdesign().

00118 { return (dsp16_t) ((((S32) num) << DSP16_QB)/((S32) den)); }

dsp16_t dsp16_op_exp ( dsp16_t  number  ) 

16-bit fixed point version of the exponential function.

Parameters:
number The number to compute
Returns:
The exponential of 'number' is returned.

Definition at line 105 of file op_fix_exp.c.

References A, B, C, CST_INV_SQUARE_ROOT_2, CST_LN_2, CST_SQUARE_ROOT_2, DSP16_EXP_LIMIT_VAL, dsp16_op_abs(), DSP16_Q, DSP16_QA, DSP16_QB, DSP_Q, and DSP_Q_MAX.

Referenced by dsp16_op_kaiser_i0(), dsp16_op_pow(), and dsp16_win_gauss().

00106 {
00107   int k;
00108   S32 x, res;
00109 
00110   if (num > DSP16_EXP_LIMIT_VAL)
00111     return DSP_Q_MAX(DSP16_QA, DSP16_QB);
00112 
00113   // k = floor(res/((log(2)*0.5)));
00114   x = (S32) DSP_Q(32-DSP16_QB, DSP16_QB, 2./CST_LN_2) >> 1;
00115   k = ((((S32) num)*x)) >> (2*DSP16_QB - 1);
00116 
00117   // x = res - (k*log(2)*0.5);
00118   x = DSP16_Q(CST_LN_2*0.5);
00119   x = ((S32) num) - x*((S32) k);
00120 
00121   // res = 1 + x + x*x/2 + x*x*x/6 + x*x*x*x/24;
00122   res = (x*((S32) DSP16_Q(C))) >> DSP16_QB;
00123   res = (x*(res + ((S32) DSP16_Q(B)))) >> DSP16_QB;
00124   res = (x*(res + ((S32) DSP16_Q(A)))) >> DSP16_QB;
00125   res += ((S32) DSP16_Q(1.));
00126 
00127   if (k > 0)
00128   {
00129     if (k&1)
00130       res = ((res << (k >> 1))*DSP16_Q(CST_SQUARE_ROOT_2)) >> DSP16_QB;
00131     else
00132       res <<= (k >> 1);
00133   }
00134   else
00135   {
00136     if (k&1)
00137       res = ((res >> (dsp16_op_abs(k) >> 1))*DSP16_Q(CST_INV_SQUARE_ROOT_2)) >> DSP16_QB;
00138     else
00139       res >>= (dsp16_op_abs(k) >> 1);
00140   }
00141 
00142   return res;
00143 }

dsp16_t dsp16_op_ln ( dsp16_t  number  ) 

16-bit fixed point version of the natural logarithm function.

Parameters:
number The number to compute
Returns:
The natural logarithm of 'number' is returned.
Note:
If you are using a number lower than 0 for the number, the function will return DSP_Q_MIN(DSP16_QA, DSP16_QB).

Definition at line 48 of file op_fix_ln.c.

References dsp16_op_ln_raw(), DSP16_QA, DSP16_QB, and DSP_Q_MIN.

00049 {
00050   S32 res;
00051   extern S32 dsp16_op_ln_raw(dsp16_t num);
00052 
00053   res = dsp16_op_ln_raw(number);
00054 
00055   if (res < ((S32) DSP_Q_MIN(DSP16_QA, DSP16_QB)))
00056     return DSP_Q_MIN(DSP16_QA, DSP16_QB);
00057 
00058   return (dsp16_t) res;
00059 }

dsp16_t dsp16_op_log10 ( dsp16_t  number  ) 

16-bit fixed point version of the common logarithm function.

Parameters:
number The number to compute
Returns:
The common logarithm of 'number' is returned.
Note:
If you are using a number lower than 0 for the number, the function will return DSP_Q_MIN(DSP16_QA, DSP16_QB).

Definition at line 52 of file op_fix_log10.c.

References CST_LN_10, dsp16_op_ln_raw(), DSP16_QA, DSP16_QB, DSP_Q, and DSP_Q_MIN.

00053 {
00054   S32 res;
00055   const S32 cst_ln2 = (S32) DSP_Q(32-DSP16_QB, DSP16_QB, 1./CST_LN_10);
00056   extern S32 dsp16_op_ln_raw(dsp16_t num);
00057 
00058   res = dsp16_op_ln_raw(number);
00059 
00060   if (res == DSP_Q_MIN(DSP16_QA, DSP16_QB) || res < ((S32) 0x80000000)/cst_ln2)
00061     return DSP_Q_MIN(DSP16_QA, DSP16_QB);
00062 
00063   res = (res*cst_ln2) >> DSP16_QB;
00064 
00065   if (res < ((S32) DSP_Q_MIN(DSP16_QA, DSP16_QB)))
00066     return (dsp16_t) DSP_Q_MIN(DSP16_QA, DSP16_QB);
00067 
00068   return (dsp16_t) res;
00069 }

dsp16_t dsp16_op_log2 ( dsp16_t  number  ) 

16-bit fixed point version of the binary logarithm function.

Parameters:
number The number to compute
Returns:
The binary logarithm of 'number' is returned.
Note:
If you are using a number lower than 0 for the number, the function will return DSP_Q_MIN(DSP16_QA, DSP16_QB).

Definition at line 52 of file op_fix_log2.c.

References CST_LN_2, dsp16_op_ln_raw(), DSP16_QA, DSP16_QB, DSP_Q, and DSP_Q_MIN.

00053 {
00054   S32 res;
00055   const S32 cst_ln2 = (S32) DSP_Q(32-DSP16_QB, DSP16_QB, 1./CST_LN_2);
00056   extern S32 dsp16_op_ln_raw(dsp16_t num);
00057 
00058   res = dsp16_op_ln_raw(number);
00059 
00060   if (res < ((S32) 0x80000000)/cst_ln2)
00061     return DSP_Q_MIN(DSP16_QA, DSP16_QB);
00062 
00063   res = (res*cst_ln2) >> DSP16_QB;
00064 
00065   if (res < ((S32) DSP_Q_MIN(DSP16_QA, DSP16_QB)))
00066     return (dsp16_t) DSP_Q_MIN(DSP16_QA, DSP16_QB);
00067 
00068   return (dsp16_t) res;
00069 }

static dsp16_t dsp16_op_mul ( dsp16_t  num1,
dsp16_t  num2 
) [inline, static]

16-bit fixed point version of the multiplication function.

Parameters:
num1 The first member of the multiplication.
num2 The second member of the multiplication.
Returns:
The result of the multiplication.

Definition at line 91 of file dsp_operators.h.

References DSP16_QB.

Referenced by dsp16_filt_lpfirdesign().

00091 { return (dsp16_t) ((((S32) num1)*((S32) num2)) >> DSP16_QB); }

dsp16_t dsp16_op_pow ( dsp16_t  x,
dsp16_t  y 
)

16-bit fixed point version of the power function.

Parameters:
x The number from which the power has to be applied.
y The power.
Returns:
The x power y is returned.

DSP_Q_MIN if the argument x is negative: this would result in a complex number.

Definition at line 52 of file op_fix_pow.c.

References CST_LN_2, dsp16_op_abs(), dsp16_op_exp(), dsp16_op_ln_raw(), DSP16_Q, DSP16_QA, DSP16_QB, DSP_Q, DSP_Q_MAX, and DSP_Q_MIN.

00053 {
00054   S32 res, temp;
00055   int k;
00056   extern S32 dsp16_op_ln_raw(dsp16_t num);
00057 
00058   if (x < DSP16_Q(0.))
00059     return (dsp16_t) DSP_Q_MIN(DSP16_QA, DSP16_QB);
00060 
00061   res = dsp16_op_ln_raw(x) >> (DSP16_QB >> 1);
00062 
00063   res = (res*((S32) y)) >> ((DSP16_QB&1)?(DSP16_QB >> 1)+1:(DSP16_QB >> 1));
00064 
00065   // In order to prevent overflows ...
00066   if (res < ((S32) DSP_Q_MIN(DSP16_QA, DSP16_QB)))
00067   {
00068     // k = floor(res/log(2));
00069     temp = res >> (DSP16_QB - 2);
00070     k = (S32) DSP_Q(32-DSP16_QB, DSP16_QB, 1./CST_LN_2) >> 2;
00071     k = ((temp*k) >> (DSP16_QB)) + 1;
00072 
00073     // temp = res - (k*log(2));
00074     temp = DSP16_Q(CST_LN_2);
00075     // temp is in the range ]-ln(2), 0]
00076     temp = ((S32) res) - temp*((S32) k);
00077 
00078     res = dsp16_op_exp((dsp16_t) temp);
00079 
00080     res >>= dsp16_op_abs(k);
00081 
00082     return (dsp16_t) res;
00083   }
00084 
00085   if (res > ((S32) DSP_Q_MAX(DSP16_QA, DSP16_QB)))
00086     res = DSP_Q_MAX(DSP16_QA, DSP16_QB);
00087 
00088   return (dsp16_t) dsp16_op_exp(res);
00089 }

dsp16_t dsp16_op_rand (  ) 

16-bit fixed point version of the random operator.

Returns:
The cosine of 'angle' is returned.
Note:
The number generated can be any 16-bit value in the range [-1; 1[.

Definition at line 63 of file op_fix_rand.c.

References DSP16_QA, and seed.

Referenced by dsp16_gen_noise().

00064 {
00065   // Park and Miller Minimal Standard
00066   seed = 16807*seed;
00067   return (dsp16_t) (seed >> (DSP16_QA-1)) & (((U16) -1) >> (DSP16_QA-1));
00068 }

dsp16_t dsp16_op_sin ( dsp16_t  angle  ) 

16-bit fixed point version of the sine function.

Parameters:
angle The angle to compute
Returns:
The sine of 'angle' is returned.
Note:
If you are using a number greater than 1 (or lower than -1) for the angle, the function will take the modulo 1 of this angle.

Definition at line 59 of file op_fix_sin.c.

References DSP16_MODULO_1_MASK, dsp16_op_kernel_cosfix(), dsp16_op_kernel_sinfix(), DSP16_Q, and DSP16_QB.

Referenced by dsp16_gen_sin(), and dsp16_op_cos().

00060 {
00061 #if DSP16_QA > 1
00062   U16 n = ((angle + DSP16_Q(0.25)) & DSP16_MODULO_1_MASK) >> (DSP16_QB-1);
00063 #else
00064   U16 n = ((U16) (angle + DSP16_Q(0.25))) >> (DSP16_QB-1);
00065 #endif
00066 
00067     // Translate input down to +/- pi/4
00068   angle -= n*DSP16_Q(0.5);
00069 
00070 #if DSP16_QA > 1
00071     // angle modulo 1 (signed values)
00072   angle <<= (16 - (DSP16_QB+1));
00073   angle >>= (16 - (DSP16_QB+1));
00074 #endif
00075 
00076   switch(n)
00077     {
00078   case 0:
00079       return dsp16_op_kernel_sinfix(angle);
00080   case 1:
00081       return dsp16_op_kernel_cosfix(angle);
00082   case 2:
00083       return -dsp16_op_kernel_sinfix(angle);
00084   default:
00085       return -dsp16_op_kernel_cosfix(angle);
00086     }
00087 }

dsp16_t dsp16_op_sqrt ( dsp16_t  number  ) 

16-bit fixed point version of the square root function.

Parameters:
number The number to compute
Returns:
The square root of 'number' is returned.
Note:
If you are using a number lower than 0 for the number, the function will return 0.

Definition at line 61 of file op_dsp16_fix_sqrt.c.

References CST_INV_SQUARE_ROOT_2, DSP16_Q, DSP16_QB, and DSP16_SQRT_NEWTON_ITERATION.

Referenced by dsp16_op_asin(), and dsp16_op_kaiser_i0().

00062 {
00063   int under_bit_val;
00064   dsp16_t num_temp, x;
00065   S32 a;
00066 
00067   // Limit
00068   if (num < 0)
00069     return 0;
00070 
00071   // Find an approximation of 1/sqrt(x);
00072   under_bit_val = 0;
00073   num_temp = num;
00074   while(num_temp)
00075   {
00076     num_temp >>= 1;
00077     under_bit_val++;
00078   }
00079   under_bit_val >>= 1;
00080 
00081   // x ~ 1/sqrt(num)
00082   x = 1 << (DSP16_QB - under_bit_val);
00083 
00084   // Perform a Newton Iteration
00085   MREPEAT(3, DSP16_SQRT_NEWTON_ITERATION, "");
00086 
00087 #if (DSP16_QB%2 == 1)
00088   // To support Q1.(2N+1) fixed point numbers
00089   num = (num*((S32) DSP16_Q(CST_INV_SQUARE_ROOT_2))) >> (DSP16_QB);
00090 #endif
00091   // Get sqrt(x) from 1/sqrt(x)
00092   a = (((S32) x)*((S32) num));
00093   // Adjust the result for fixed point format
00094   a >>= (DSP16_QB >> 1);
00095 
00096   return (dsp16_t) a;
00097 }

static dsp32_t dsp32_op_abs ( dsp32_t  number  )  [inline, static]

32-bit fixed point version of the absolute function.

Parameters:
number The number to compute
Returns:
The absolute value of the number.

Definition at line 273 of file dsp_operators.h.

Referenced by dsp32_op_asin(), dsp32_op_exp(), dsp32_op_pow(), and dsp32_win_gauss().

00273 { return (number < 0)?-number:number; }

static dsp32_t dsp32_op_acos ( dsp32_t  number  )  [inline, static]

32-bit fixed point version of the arc cosine function.

Parameters:
number The number to compute
Returns:
The arc cosine of 'number' is returned.
Note:
If you are using a number greater than 1 (or lower than -1) for the 'number', the function will limit the output to the range [0.; 1.].

Definition at line 248 of file dsp_operators.h.

References dsp32_op_asin(), and DSP32_Q.

00248 { return (DSP32_Q(0.5)-1) - dsp32_op_asin(number); }

dsp32_t dsp32_op_asin ( dsp32_t  number  ) 

32-bit fixed point version of the arc sine function.

Parameters:
number The number to compute
Returns:
The arc sine of 'number' is returned.
Note:
If you are using a number greater than 1 (or lower than -1) for the 'number', the function will limit the output to the range [-0.5; 0.5].

Definition at line 104 of file op_fix_asin.c.

References A, B, C, D, dsp32_op_abs(), dsp32_op_asin(), dsp32_op_sqrt(), DSP32_Q, DSP32_QB, E, and F.

Referenced by dsp32_op_acos(), and dsp32_op_asin().

00105 {
00106   S64 num_sqr, res;
00107   dsp32_t num_abs;
00108 
00109   num_abs = dsp32_op_abs(num);
00110 
00111 #if DSP32_QB < 31
00112   // Limits
00113   if (((S64) num) >= ((S64) DSP32_Q(1.)))
00114     return DSP32_Q(0.5);
00115   if (((S64) num) <= ((S64) DSP32_Q(-1.)))
00116     return DSP32_Q(-0.5);
00117 #endif
00118 
00119   // If |num| > 0.5
00120   if (num_abs > DSP32_Q(0.5))
00121   {
00122     num_abs = dsp32_op_sqrt((DSP32_Q(1.)-num_abs) >> 1);
00123     num_abs = DSP32_Q(0.5) - (dsp32_op_asin(num_abs) << 1);
00124     return (num < 0)?-num_abs:num_abs;
00125   }
00126   else
00127   {
00128     num_sqr = (((S64) num)*((S64) num)) >> DSP32_QB;
00129     res = (num_sqr*((S64) DSP32_Q(F))) >> DSP32_QB;
00130     res = (num_sqr*(res + ((S64) DSP32_Q(E)))) >> DSP32_QB;
00131     res = (num_sqr*(res + ((S64) DSP32_Q(D)))) >> DSP32_QB;
00132     res = (num_sqr*(res + ((S64) DSP32_Q(C)))) >> DSP32_QB;
00133     res = (num_sqr*(res + ((S64) DSP32_Q(B)))) >> DSP32_QB;
00134     num = (((S64) num)*(res + ((S64) DSP32_Q(A)))) >> (DSP32_QB + 1);
00135 
00136     return num;
00137   }
00138 }

static dsp32_t dsp32_op_cos ( dsp32_t  angle  )  [inline, static]

32-bit fixed point version of the cosine function.

Parameters:
angle The angle to compute
Returns:
The cosine of 'angle' is returned.
Note:
If you are using a number greater than 1 (or lower than -1) for the angle, the function will take the modulo 1 of this angle.

Definition at line 186 of file dsp_operators.h.

References dsp32_op_sin(), and DSP32_Q.

Referenced by dsp32_gen_cos(), dsp32_win_black(), dsp32_win_hamm(), and dsp32_win_hann().

00186 { return dsp32_op_sin(angle + DSP32_Q(0.5)); }

static dsp32_t dsp32_op_div ( dsp32_t  num,
dsp32_t  den 
) [inline, static]

32-bit fixed point version of the division function.

Parameters:
num The numerator of the division.
den The denominator of the division.
Returns:
The result of the division.

Definition at line 125 of file dsp_operators.h.

References DSP32_QB.

00125 { return (dsp32_t) ((((S64) num) << DSP32_QB)/((S64) den)); }

dsp32_t dsp32_op_exp ( dsp32_t  number  ) 

32-bit fixed point version of the exponential function.

Parameters:
number The number to compute
Returns:
The exponential of 'number' is returned.

Definition at line 151 of file op_fix_exp.c.

References A, B, C, CST_INV_SQUARE_ROOT_2, CST_LN_2, CST_SQUARE_ROOT_2, D, DSP32_EXP_LIMIT_VAL, dsp32_op_abs(), DSP32_Q, DSP32_QA, DSP32_QB, DSP_Q_MAX, and E.

Referenced by dsp32_op_kaiser_i0(), dsp32_op_pow(), and dsp32_win_gauss().

00152 {
00153   int k;
00154   S64 x, res;
00155 
00156   if (num > DSP32_EXP_LIMIT_VAL)
00157     return DSP_Q_MAX(DSP32_QA, DSP32_QB);
00158 
00159   // k = floor(res/((log(2)*0.5)));
00160   x = (S64) ((2LL/CST_LN_2)*(1LL << (DSP32_QB -1 )));
00161   k = ((((S64) num)*x)) >> (2*DSP32_QB - 1);
00162 
00163   // x = res - (k*log(2)*0.5);
00164   x = DSP32_Q(CST_LN_2*0.5);
00165   x = ((S64) num) - x*((S64) k);
00166 
00167   // res = 1 + x + x*x/2 + x*x*x/6 + x*x*x*x/24 + x*x*x*x*x/120;
00168   res = (x*((S32) DSP32_Q(E))) >> DSP32_QB;
00169   res = (x*(res + ((S64) DSP32_Q(D)))) >> DSP32_QB;
00170   res = (x*(res + ((S64) DSP32_Q(C)))) >> DSP32_QB;
00171   res = (x*(res + ((S64) DSP32_Q(B)))) >> DSP32_QB;
00172   res = (x*(res + ((S64) DSP32_Q(A)))) >> DSP32_QB;
00173   res += ((S64) DSP32_Q(1.));
00174 
00175   if (k > 0)
00176   {
00177     if (k&1)
00178       res = ((res << (k >> 1))*DSP32_Q(CST_SQUARE_ROOT_2)) >> DSP32_QB;
00179     else
00180       res <<= (k >> 1);
00181   }
00182   else
00183   {
00184     if (k&1)
00185       res = ((res >> (dsp32_op_abs(k) >> 1))*DSP32_Q(CST_INV_SQUARE_ROOT_2)) >> DSP32_QB;
00186     else
00187       res >>= (dsp32_op_abs(k) >> 1);
00188   }
00189 
00190   return res;
00191 }

dsp32_t dsp32_op_ln ( dsp32_t  number  ) 

32-bit fixed point version of the natural logarithm function.

Parameters:
number The number to compute
Returns:
The natural logarithm of 'number' is returned.
Note:
If you are using a number lower than 0 for the number, the function will return DSP_Q_MIN(DSP32_QA, DSP32_QB).

Definition at line 61 of file op_fix_ln.c.

References dsp32_op_ln_raw(), DSP32_QA, DSP32_QB, and DSP_Q_MIN.

00062 {
00063   S64 res;
00064   extern S64 dsp32_op_ln_raw(dsp32_t num);
00065 
00066   res = dsp32_op_ln_raw(number);
00067 
00068   if (res < ((S64) DSP_Q_MIN(DSP32_QA, DSP32_QB)))
00069     return DSP_Q_MIN(DSP32_QA, DSP32_QB);
00070 
00071   return (dsp32_t) res;
00072 }

dsp32_t dsp32_op_log10 ( dsp32_t  number  ) 

32-bit fixed point version of the common logarithm function.

Parameters:
number The number to compute
Returns:
The common logarithm of 'number' is returned.
Note:
If you are using a number lower than 0 for the number, the function will return DSP_Q_MIN(DSP32_QA, DSP32_QB).

Definition at line 77 of file op_fix_log10.c.

References CST_LN_10, dsp32_op_ln_raw(), DSP32_QA, DSP32_QB, and DSP_Q_MIN.

00078 {
00079   S64 res;
00080   const S64 cst_ln2 = (S64) ((1./CST_LN_10)*(1LL << DSP32_QB));
00081   extern S64 dsp32_op_ln_raw(dsp32_t num);
00082 
00083   res = dsp32_op_ln_raw(number);
00084 
00085   if (res == DSP_Q_MIN(DSP32_QA, DSP32_QB) || res < ((S64) -0x8000000000000000LL)/cst_ln2)
00086     return DSP_Q_MIN(DSP32_QA, DSP32_QB);
00087 
00088   res = (res*cst_ln2) >> DSP32_QB;
00089 
00090   if (res < ((S64) DSP_Q_MIN(DSP32_QA, DSP32_QB)))
00091     return (dsp32_t) DSP_Q_MIN(DSP32_QA, DSP32_QB);
00092 
00093   return (dsp32_t) res;
00094 }

dsp32_t dsp32_op_log2 ( dsp32_t  number  ) 

32-bit fixed point version of the binary logarithm function.

Parameters:
number The number to compute
Returns:
The binary logarithm of 'number' is returned.
Note:
If you are using a number lower than 0 for the number, the function will return DSP_Q_MIN(DSP32_QA, DSP32_QB).

Definition at line 77 of file op_fix_log2.c.

References CST_LN_2, dsp32_op_ln_raw(), DSP32_QA, DSP32_QB, and DSP_Q_MIN.

00078 {
00079   S64 res;
00080   const S64 cst_ln2 = (S64) ((1./CST_LN_2)*(1LL << DSP32_QB));
00081   extern S64 dsp32_op_ln_raw(dsp32_t num);
00082 
00083   res = dsp32_op_ln_raw(number);
00084 
00085   if (res < ((S64) -0x8000000000000000LL)/cst_ln2)
00086     return DSP_Q_MIN(DSP32_QA, DSP32_QB);
00087 
00088   res = (res*cst_ln2) >> DSP32_QB;
00089 
00090   if (res < ((S64) DSP_Q_MIN(DSP32_QA, DSP32_QB)))
00091     return (dsp32_t) DSP_Q_MIN(DSP32_QA, DSP32_QB);
00092 
00093   return (dsp32_t) res;
00094 }

static dsp32_t dsp32_op_mul ( dsp32_t  num1,
dsp32_t  num2 
) [inline, static]

32-bit fixed point version of the multiplication function.

Parameters:
num1 The first member of the multiplication.
num2 The second member of the multiplication.
Returns:
The result of the multiplication.

Definition at line 98 of file dsp_operators.h.

References DSP32_QB.

00098 { return (dsp32_t) ((((S64) num1)*((S64) num2)) >> DSP32_QB); }

dsp32_t dsp32_op_pow ( dsp32_t  x,
dsp32_t  y 
)

32-bit fixed point version of the power function.

Parameters:
x The number from which the power has to be applied.
y The power.
Returns:
The x power y is returned.

DSP_Q_MIN if the argument x is negative: this would result in a complex number.

Definition at line 97 of file op_fix_pow.c.

References CST_LN_2, dsp32_op_abs(), dsp32_op_exp(), dsp32_op_ln_raw(), DSP32_Q, DSP32_QA, DSP32_QB, DSP_Q_MAX, and DSP_Q_MIN.

00098 {
00099   S64 res, temp;
00100   int k;
00101   extern S64 dsp32_op_ln_raw(dsp32_t num);
00102 
00103   if (x < DSP32_Q(0.))
00104     return (dsp32_t) DSP_Q_MIN(DSP32_QA, DSP32_QB);
00105 
00106   res = dsp32_op_ln_raw(x) >> (DSP32_QB >> 1);
00107 
00108   res = (res*((S64) y)) >> ((DSP32_QB&1)?(DSP32_QB >> 1)+1:(DSP32_QB >> 1));
00109 
00110   // In order to prevent overflows ...
00111   if (res < ((S64) DSP_Q_MIN(DSP32_QA, DSP32_QB)))
00112   {
00113     // k = floor(res/log(2));
00114     temp = res >> (DSP32_QB - 2);
00115     k = (S64) ((1LL/CST_LN_2)*(1LL << (DSP32_QB - 2 )));
00116     k = ((temp*k) >> (DSP32_QB)) + 1;
00117 
00118     // temp = res - (k*log(2));
00119     temp = DSP32_Q(CST_LN_2);
00120     // temp is in the range ]-ln(2), 0]
00121     temp = ((S64) res) - temp*((S64) k);
00122 
00123     res = dsp32_op_exp((dsp32_t) temp);
00124 
00125     res >>= dsp32_op_abs(k);
00126 
00127     return (dsp32_t) res;
00128   }
00129 
00130   if (res > ((S64) DSP_Q_MAX(DSP32_QA, DSP32_QB)))
00131     res = DSP_Q_MAX(DSP32_QA, DSP32_QB);
00132 
00133   return (dsp32_t) dsp32_op_exp(res);
00134 }

dsp32_t dsp32_op_rand (  ) 

32-bit fixed point version of the random operator.

Returns:
The cosine of 'angle' is returned.
Note:
The number generated can be any 32-bit value in the range [-1; 1[.

Definition at line 77 of file op_fix_rand.c.

References DSP16_QA, DSP32_QA, and seed.

Referenced by dsp32_gen_noise().

00078 {
00079   // Park and Miller Minimal Standard
00080   seed = 16807*seed;
00081   return (dsp32_t) (seed >> (DSP32_QA-1)) & (((U32) -1) >> (DSP16_QA-1));
00082 }

dsp32_t dsp32_op_sin ( dsp32_t  angle  ) 

32-bit fixed point version of the sine function.

Parameters:
angle The angle to compute
Returns:
The sine of 'angle' is returned.
Note:
If you are using a number greater than 1 (or lower than -1) for the angle, the function will take the modulo 1 of this angle.

Definition at line 103 of file op_fix_sin.c.

References DSP32_MODULO_1_MASK, dsp32_op_kernel_cosfix(), dsp32_op_kernel_sinfix(), DSP32_Q, and DSP32_QB.

Referenced by dsp16_filt_lpfirdesign(), dsp32_gen_sin(), and dsp32_op_cos().

00104 {
00105 #if DSP32_QA > 1
00106   U32 n = ((angle + DSP32_Q(0.25)) & DSP32_MODULO_1_MASK) >> (DSP32_QB-1);
00107 #else
00108   U32 n = DSP32_Q(0.25);
00109   n += angle;
00110   n = n >> (DSP32_QB-1);
00111 #endif
00112 
00113   // Translate input down to +/- pi/4
00114   angle -= n*DSP32_Q(0.5);
00115 
00116 #if DSP32_QA > 1
00117   // angle modulo 1 (signed values)
00118   angle <<= (32 - (DSP32_QB + 1));
00119   angle >>= (32 - (DSP32_QB + 1));
00120 #endif
00121   
00122   switch(n)
00123     {
00124   case 0:
00125       return dsp32_op_kernel_sinfix(angle);
00126   case 1:
00127       return dsp32_op_kernel_cosfix(angle);
00128   case 2:
00129       return -dsp32_op_kernel_sinfix(angle);
00130   default:
00131       return -dsp32_op_kernel_cosfix(angle);
00132     }
00133 }

dsp32_t dsp32_op_sqrt ( dsp32_t  number  ) 

32-bit fixed point version of the square root function.

Parameters:
number The number to compute
Returns:
The square root of 'number' is returned.
Note:
If you are using a number lower than 0 for the number, the function will return 0.

Definition at line 61 of file op_dsp32_fix_sqrt.c.

References CST_INV_SQUARE_ROOT_2, DSP32_Q, DSP32_QB, and DSP32_SQRT_NEWTON_ITERATION.

Referenced by dsp16_win_kaiser(), dsp32_op_asin(), dsp32_op_kaiser_i0(), and dsp32_win_kaiser().

00062 {
00063   int under_bit_val;
00064   dsp32_t num_temp;
00065   S64 a, x, s64_num;
00066 
00067   // Limit
00068   if (num < 0)
00069     return 0;
00070 
00071   // Find an approximation of 1/sqrt(x);
00072   under_bit_val = 0;
00073   num_temp = num;
00074   while(num_temp)
00075   {
00076     num_temp >>= 1;
00077     under_bit_val++;
00078   }
00079   under_bit_val >>= 1;
00080 
00081   // x ~ 1/sqrt(num)
00082   x = 1 << (DSP32_QB - under_bit_val);
00083 
00084   s64_num = num;
00085   // Perform a Newton Iteration
00086   MREPEAT(6, DSP32_SQRT_NEWTON_ITERATION, "");
00087 
00088 #if (DSP32_QB%2 == 1)
00089   // To support Q1.(2N+1) fixed point numbers
00090   s64_num = (s64_num*((S64) DSP32_Q(CST_INV_SQUARE_ROOT_2))) >> (DSP32_QB);
00091 #endif
00092   // Get sqrt(x) from 1/sqrt(x)
00093   a = x*s64_num;
00094 
00095   // Adjust the result for fixed point format
00096   a >>= (DSP32_QB >> 1);
00097 
00098   return (dsp32_t) a;
00099 }

void dsp_op_srand ( int  new_seed  ) 

Initialize the pseudo-random number generator.

Parameters:
new_seed An integer value to be used as seed by the pseudo-random number generator algorithm.

Definition at line 51 of file op_fix_rand.c.

References seed.

00052 {
00053   if (new_seed == 0)
00054     new_seed = 1;
00055   seed = new_seed;
00056 }


Generated on Fri Feb 19 02:23:22 2010 for AVR32 UC3 - EVK1104 DSPLib Demo Documentation by  doxygen 1.5.5