Christophe Favergeon | 0c9cd47 | 2021-07-20 10:51:46 +0200 | [diff] [blame] | 1 | import cmsisdsp as dsp |
| 2 | import numpy as np |
Christophe Favergeon | e7de243 | 2021-09-07 13:28:35 +0200 | [diff] [blame] | 3 | import cmsisdsp.fixedpoint as f |
Christophe Favergeon | 0c9cd47 | 2021-07-20 10:51:46 +0200 | [diff] [blame] | 4 | |
| 5 | # Test vlog q31 and q15 |
| 6 | x = np.array([0.9,0.5,2**-16]) |
| 7 | |
| 8 | r=dsp.arm_vlog_q15(f.toQ15(x)) |
| 9 | |
| 10 | print(f.Q15toF32(r)*16.0) |
| 11 | |
| 12 | print(np.log(x)) |
| 13 | |
| 14 | print("") |
| 15 | # Test sin_cos |
| 16 | t=20 |
| 17 | |
| 18 | sinRef=np.sin(t * np.pi / 180) |
| 19 | cosRef=np.cos(t * np.pi / 180) |
| 20 | print(sinRef) |
| 21 | print(cosRef) |
| 22 | |
| 23 | s,c=dsp.arm_sin_cos_f32(t) |
| 24 | print(s) |
| 25 | print(c) |
| 26 | |
| 27 | s,c=dsp.arm_sin_cos_q31(f.toQ31(t/180.0)) |
| 28 | print(f.Q31toF32(s)) |
| 29 | print(f.Q31toF32(c)) |
| 30 | |
| 31 | print("") |
| 32 | # Test sqrt |
| 33 | a=0.6 |
| 34 | print(np.sqrt(a)) |
| 35 | |
| 36 | err,r=dsp.arm_sqrt_f32(a) |
| 37 | print(err,r) |
| 38 | |
| 39 | err,r=dsp.arm_sqrt_q31(f.toQ31(a)) |
| 40 | print(err,f.Q31toF32(r)) |
| 41 | |
| 42 | err,r=dsp.arm_sqrt_q15(f.toQ15(a)) |
| 43 | print(err,f.Q15toF32(r)) |
| 44 | |
| 45 | err,r=dsp.arm_sqrt_f32(-a) |
| 46 | print(err,r) |
| 47 | |
| 48 | err,r=dsp.arm_sqrt_q31(f.toQ31(-a)) |
| 49 | print(err,f.Q31toF32(r)) |
| 50 | |
| 51 | err,r=dsp.arm_sqrt_q15(f.toQ15(-a)) |
| 52 | print(err,f.Q15toF32(r)) |
| 53 | |