nmpp
fftexp.h
1#include "fft.h"
2//#include "fftext.h"
3//#include "nmtl/tcmplx_spec.h"
4#include "nmtl/tcmplx.h"
5#include <math.h>
6
7#ifndef PI
8#define PI 3.14159265359
9#endif
10
11
12template<int power> void expFFT(int arg, float* re, float* im)
13{
14 float rad=-2.0*PI/power*arg;
15 *re=cosf((float)rad);
16 *im=sinf((float)rad);
17}
18
19template<int power> void expIFFT(int arg, float* re, float* im)
20{
21 float rad=2.0*PI/power*arg;
22 *re=cosf(rad);
23 *im=sinf(rad);
24}
25
26
27template<int power> void expFFT(int arg, int amplitude, nm32sc* z)
28{
29 float re;
30 float im;
31 expFFT<power>(arg,&re,&im);
32 z->re=floor(amplitude*re+0.5);
33 z->im=floor(amplitude*im+0.5);
34}
35
36template<int power> void expFFT127(int arg, int amplitude, nm32sc* z)
37{
38 float re;
39 float im;
40 expFFT<power>(arg,&re,&im);
41 z->re=floor(amplitude*re+0.5);
42 z->im=floor(amplitude*im+0.5);
43 z->re= z->re > 127 ? 127:z->re;
44 z->im= z->im > 127 ? 127:z->im;
45}
46
47template<int power> void expIFFT127(int arg, int amplitude, nm32sc* z)
48{
49 float re;
50 float im;
51 expIFFT<power>(arg,&re,&im);
52 z->re=floor(amplitude*re+0.5);
53 z->im=floor(amplitude*im+0.5);
54 z->re= z->re > 127 ? 127:z->re;
55 z->im= z->im > 127 ? 127:z->im;
56}
57
58template<int power> void expFFT127(int arg, int amplitude, cmplx<int>* z)
59{
60 float re;
61 float im;
62 expFFT<power>(arg,&re,&im);
63 z->re=floor(amplitude*re+0.5);
64 z->im=floor(amplitude*im+0.5);
65 z->re= z->re > 127 ? 127:z->re;
66 z->im= z->im > 127 ? 127:z->im;
67}
68
69template<int power> void expIFFT127(int arg, int amplitude, cmplx<int>* z)
70{
71 float re;
72 float im;
73 expIFFT<power>(arg,&re,&im);
74 z->re=floor(amplitude*re+0.5);
75 z->im=floor(amplitude*im+0.5);
76 z->re= z->re > 127 ? 127:z->re;
77 z->im= z->im > 127 ? 127:z->im;
78}
79
80template<int power> cmplx<int> expFFT127(int arg, int amplitude=128)
81{
82 cmplx<int> z;
83 float re;
84 float im;
85 expFFT<power>(arg,&re,&im);
86 z.re=floor(amplitude*re+0.5);
87 z.im=floor(amplitude*im+0.5);
88 z.re= z.re > 127 ? 127:z.re;
89 z.im= z.im > 127 ? 127:z.im;
90 return z;
91}
92
93
94template<int power> cmplx<int> expFFT(int arg, int amplitude)
95{
96 float re;
97 float im;
98 expFFT<power>(arg,&re,&im);
99 cmplx<int> z;
100 z.re=floor(amplitude*re+0.5);
101 z.im=floor(amplitude*im+0.5);
102 return z;
103}
104
105template<int power> cmplx<long long> lexpFFT(int arg, int amplitude)
106{
107 float re;
108 float im;
109 expFFT<power>(arg, &re, &im);
110 cmplx<long long> z;
111 z.re = floor(amplitude*re + 0.5);
112 z.im = floor(amplitude*im + 0.5);
113 return z;
114}
115
116
117template<int power> cmplx<int> expIFFT(int arg, int amplitude)
118{
119 float re;
120 float im;
121 expIFFT<power>(arg,&re,&im);
122 cmplx<int> z;
123 z.re=floor(amplitude*re+0.5);
124 z.im=floor(amplitude*im+0.5);
125 return z;
126}
127
128
129
130template<int power> cmplx<double> expFFT(int arg)
131{
132 cmplx<double> z;
133 double im=-2.0*PI/power*arg;
134 z.re=cos(im);
135 z.im=sin(im);
136 return z;
137}
138template<int power> cmplx<double> expIFFT(int arg)
139{
140 cmplx<double> z;
141 double im=2.0*PI/power*arg;
142 z.re=cos(im);
143 z.im=sin(im);
144 return z;
145}
146
147void load_wfifo(nm64s* wfifoData, int wfifoStep, int size);
148void load_wfifo(cmplx<int>* wcoef, int wstep, int size);
149void load_wfifo(nm32sc* wcoef, int wstep, int size);
150
151void vsum_data(nm8s* data, nm32sc* afifo, int vr);
152void vsum_data(nm16s* data, nm32sc* afifo, int vr);
153void vsum_data(nm8s* data, cmplx<int>* afifo, int vr);
long long nm64s
Definition: nmtype.h:375
short nm16s
Definition: nmtype.h:243
char nm8s
Definition: nmtype.h:167
Definition: nmtype.h:1301