blob: d751a5507edc92c5e945e7253e50851f8c4caa9b [file] [log] [blame]
hayati ayguen29eb8472020-11-11 23:09:58 +01001/*
2This software is part of pffft/pfdsp, a set of simple DSP routines.
3
4Copyright (c) 2014, Andras Retzler <randras@sdr.hu>
5Copyright (c) 2020 Hayati Ayguen <h_ayguen@web.de>
6
7All rights reserved.
8
9Redistribution and use in source and binary forms, with or without
10modification, are permitted provided that the following conditions are met:
11 * Redistributions of source code must retain the above copyright
12 notice, this list of conditions and the following disclaimer.
13 * Redistributions in binary form must reproduce the above copyright
14 notice, this list of conditions and the following disclaimer in the
15 documentation and/or other materials provided with the distribution.
16 * Neither the name of the copyright holder nor the
17 names of its contributors may be used to endorse or promote products
18 derived from this software without specific prior written permission.
19
20THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
21ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23DISCLAIMED. IN NO EVENT SHALL ANDRAS RETZLER BE LIABLE FOR ANY
24DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
27ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30*/
31
32/* include own header first, to see missing includes */
33#include "pf_carrier.h"
34#include "fmv.h"
35
36#include <limits.h>
37#include <assert.h>
38
39
40PF_TARGET_CLONES
41void generate_dc_f(float* output, int size)
42{
43 for(int i=0;i<2*size;)
44 {
45 /* exp(i*0) = 1+i*0 */
46 output[i++]=(127.0F / 128.0F);
47 output[i++]=0.0F;
48 }
49}
50
51PF_TARGET_CLONES
52void generate_dc_s16(short* output, int size)
53{
54 for(int i=0;i<2*size;)
55 {
56 /* exp(i*0) = 1+i*0 */
57 output[i++]=SHRT_MAX;
58 output[i++]=0;
59 }
60}
61
62PF_TARGET_CLONES
63void generate_pos_fs4_f(float* output, int size)
64{
65 /* size must be multiple of 4 */
66 assert(!(size&3));
67 for(int i=0;i<2*size;)
68 {
69 /* exp(i*0) = 1+i*0 */
70 output[i++]=(127.0F / 128.0F);
71 output[i++]=0.0F;
72 /* exp(i* +pi/2) = 0+i*1 */
73 output[i++]=0.0F;
74 output[i++]=(127.0F / 128.0F);
75 /* exp(i* +pi) = -1+i*0 */
76 output[i++]=(-127.0F / 128.0F);
77 output[i++]=0.0F;
78 /* exp(i* -pi/2) = 0+i*-1 */
79 output[i++]=0.0F;
80 output[i++]=(-127.0F / 128.0F);
81 }
82}
83
84PF_TARGET_CLONES
85void generate_pos_fs4_s16(short* output, int size)
86{
87 /* size must be multiple of 4 */
88 assert(!(size&3));
89 for(int i=0;i<2*size;)
90 {
91 /* exp(i*0) = 1+i*0 */
92 output[i++]=SHRT_MAX;
93 output[i++]=0;
94 /* exp(i* +pi/2) = 0+i*1 */
95 output[i++]=0;
96 output[i++]=SHRT_MAX;
97 /* exp(i* +pi) = -1+i*0 */
98 output[i++]=-SHRT_MAX;
99 output[i++]=0;
100 /* exp(i* -pi/2) = 0+i*-1 */
101 output[i++]=0;
102 output[i++]=-SHRT_MAX;
103 }
104}
105
106PF_TARGET_CLONES
107void generate_neg_fs4_f(float* output, int size)
108{
109 /* size must be multiple of 4 */
110 assert(!(size&3));
111 for(int i=0;i<2*size;)
112 {
113 /* exp(i*0) = 1+i*0 */
114 output[i++]=(127.0F / 128.0F);
115 output[i++]=0.0F;
116 /* exp(i* -pi/2) = 0+i*-1 */
117 output[i++]=0.0F;
118 output[i++]=(-127.0F / 128.0F);
119 /* exp(i* +pi) = -1+i*0 */
120 output[i++]=(-127.0F / 128.0F);
121 output[i++]=0.0F;
122 /* exp(i* +pi/2) = 0+i*1 */
123 output[i++]=0.0F;
124 output[i++]=(127.0F / 128.0F);
125 }
126}
127
128PF_TARGET_CLONES
129void generate_neg_fs4_s16(short* output, int size)
130{
131 /* size must be multiple of 4 */
132 assert(!(size&3));
133 for(int i=0;i<2*size;)
134 {
135 /* exp(i*0) = 1+i*0 */
136 output[i++]=SHRT_MAX;
137 output[i++]=0;
138 /* exp(i* -pi/2) = 0+i*-1 */
139 output[i++]=0;
140 output[i++]=-SHRT_MAX;
141 /* exp(i* +pi) = -1+i*0 */
142 output[i++]=-SHRT_MAX;
143 output[i++]=0;
144 /* exp(i* +pi/2) = 0+i*1 */
145 output[i++]=0;
146 output[i++]=SHRT_MAX;
147 }
148}
149
150/****************************************************/
151
152PF_TARGET_CLONES
153void generate_dc_pos_fs4_s16(short* output, int size)
154{
155 const int m = SHRT_MAX / 2;
156 /* size must be multiple of 4 */
157 assert(!(size&3));
158 for(int i=0;i<2*size;)
159 {
160 /* exp(i*0) = 1+1+i*0 */
161 output[i++]=m+m;
162 output[i++]=0;
163 /* exp(i* +pi/2) = 1+0+i*1 */
164 output[i++]=m+0;
165 output[i++]=m;
166 /* exp(i* +pi) = 1-1+i*0 */
167 output[i++]=m-m;
168 output[i++]=0;
169 /* exp(i* -pi/2) = 1+0+i*-1 */
170 output[i++]=m;
171 output[i++]=-m;
172 }
173}
174
175PF_TARGET_CLONES
176void generate_dc_neg_fs4_s16(short* output, int size)
177{
178 const int m = SHRT_MAX / 2;
179 /* size must be multiple of 4 */
180 assert(!(size&3));
181 for(int i=0;i<2*size;)
182 {
183 /* exp(i*0) = 1+1+i*0 */
184 output[i++]=m+m;
185 output[i++]=0;
186 /* exp(i* -pi/2) = 1+0+i*-1 */
187 output[i++]=m+0;
188 output[i++]=-m;
189 /* exp(i* +pi) = 1-1+i*0 */
190 output[i++]=m-m;
191 output[i++]=0;
192 /* exp(i* +pi/2) = 1+0+i*1 */
193 output[i++]=m+0;
194 output[i++]=m;
195 }
196}
197
198PF_TARGET_CLONES
199void generate_pos_neg_fs4_s16(short* output, int size)
200{
201 const int m = SHRT_MAX / 2;
202 /* size must be multiple of 4 */
203 assert(!(size&3));
204 for(int i=0;i<2*size;)
205 {
206 /* pos(0) + neg(0) = exp(i* 0 ) + exp(i* 0 ) = 1 +i* 0 + 1 +i* 0 */
207 output[i++]=m;
208 output[i++]=-m;
209
210 /* pos(1) + neg(1) = exp(i* +pi/2) + exp(i* -pi/2) = 0 +i* 1 + 0 +i* -1 */
211 output[i++]=-m;
212 output[i++]=m;
213
214 /* pos(2) + neg(2) = exp(i* +pi ) + exp(i* +pi ) = -1 +i* 0 + -1 +i* 0 */
215 output[i++]=-m;
216 output[i++]=m;
217
218 /* pos(3) + neg(3) = exp(i* -pi/2) + exp(i* +pi/2) = 0 +i* -1 + 0 +i* 1 */
219 output[i++]=m;
220 output[i++]=-m;
221 }
222}
223
224PF_TARGET_CLONES
225void generate_dc_pos_neg_fs4_s16(short* output, int size)
226{
227 const int m = SHRT_MAX / 2;
228 /* size must be multiple of 4 */
229 assert(!(size&3));
230 for(int i=0;i<2*size;)
231 {
232 /* dc + pos(0) + neg(0) = dc + exp(i* 0 ) + exp(i* 0 ) = 1 +i* 0 + 1 +i* 0 */
233 output[i++]=m+m;
234 output[i++]=-m;
235
236 /* dc + pos(1) + neg(1) = dc + exp(i* +pi/2) + exp(i* -pi/2) = 0 +i* 1 + 0 +i* -1 */
237 output[i++]=0;
238 output[i++]=m;
239
240 /* dc + pos(2) + neg(2) = dc + exp(i* +pi ) + exp(i* +pi ) = -1 +i* 0 + -1 +i* 0 */
241 output[i++]=0;
242 output[i++]=m;
243
244 /* dc + pos(3) + neg(3) = dc + exp(i* -pi/2) + exp(i* +pi/2) = 0 +i* -1 + 0 +i* 1 */
245 output[i++]=m+m;
246 output[i++]=-m;
247 }
248}
249
250
251PF_TARGET_CLONES
252void generate_pos_neg_fs2_s16(short* output, int size)
253{
254 const int m = SHRT_MAX / 2;
255 /* size must be multiple of 4 */
256 assert(!(size&3));
257 for(int i=0;i<2*size;)
258 {
259 /* dc + exp(i* 0 ) = +1 */
260 output[i++]=m;
261 output[i++]=0;
262 /* dc + exp(i* pi) = -1 */
263 output[i++]=-m;
264 output[i++]=0;
265 /* dc + exp(i* 0 ) = +1 */
266 output[i++]=m;
267 output[i++]=0;
268 /* dc + exp(i* pi) = -1 */
269 output[i++]=-m;
270 output[i++]=0;
271 }
272}
273
274PF_TARGET_CLONES
275void generate_dc_pos_neg_fs2_s16(short* output, int size)
276{
277 const int m = SHRT_MAX / 2;
278 /* size must be multiple of 4 */
279 assert(!(size&3));
280 for(int i=0;i<2*size;)
281 {
282 /* with dc = i*1 */
283 /* dc + exp(i* 0 ) = i*1 +1 */
284 output[i++]=m;
285 output[i++]=m;
286 /* dc + exp(i* pi) = i*1 -1 */
287 output[i++]=-m;
288 output[i++]=m;
289 /* dc + exp(i* 0 ) = i*1 +1 */
290 output[i++]=m;
291 output[i++]=m;
292 /* dc + exp(i* pi) = i*1 -1 */
293 output[i++]=-m;
294 output[i++]=m;
295 }
296}
297
298