spandsp  0.0.6
dds.h
Go to the documentation of this file.
1 /*
2  * SpanDSP - a series of DSP components for telephony
3  *
4  * dds.h
5  *
6  * Written by Steve Underwood <steveu@coppice.org>
7  *
8  * Copyright (C) 2003 Steve Underwood
9  *
10  * All rights reserved.
11  *
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU Lesser General Public License version 2.1,
14  * as published by the Free Software Foundation.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Lesser General Public License for more details.
20  *
21  * You should have received a copy of the GNU Lesser General Public
22  * License along with this program; if not, write to the Free Software
23  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24  */
25 
26 /*! \file */
27 
28 #if !defined(_SPANDSP_DDS_H_)
29 #define _SPANDSP_DDS_H_
30 
31 #define DDS_PHASE_RATE(frequency) (int32_t) ((frequency)*65536.0f*65536.0f/SAMPLE_RATE)
32 #define DDS_PHASE(angle) (int32_t) ((uint32_t) (((angle < 0.0f) ? (360.0f + angle) : angle)*65536.0f*65536.0f/360.0f))
33 
34 #if defined(__cplusplus)
35 extern "C"
36 {
37 #endif
38 
39 /*! \brief Convert a 32 bit phase angle to an angle in radians, between 0 and 2*PI
40  \param phase The angle to convert.
41  \return The angle in radians.
42 */
43 SPAN_DECLARE(float) dds_phase_to_radians(uint32_t phase);
44 
45 /*! \brief Find the phase rate value to achieve a particular frequency.
46  \param frequency The desired frequency, in Hz.
47  \return The phase rate which while achieve the desired frequency.
48 */
49 SPAN_DECLARE(int32_t) dds_phase_rate(float frequency);
50 
51 /*! \brief Find the frequency, in Hz, equivalent to a phase rate.
52  \param phase_rate The phase rate.
53  \return The equivalent frequency, in Hz.
54 */
55 SPAN_DECLARE(float) dds_frequency(int32_t phase_rate);
56 
57 /*! \brief Find the scaling factor needed to achieve a specified level in dBm0.
58  \param level The desired signal level, in dBm0.
59  \return The scaling factor.
60 */
61 SPAN_DECLARE(int16_t) dds_scaling_dbm0(float level);
62 
63 /*! \brief Find the scaling factor needed to achieve a specified level in dBmov.
64  \param level The desired signal level, in dBmov.
65  \return The scaling factor.
66 */
67 SPAN_DECLARE(int16_t) dds_scaling_dbov(float level);
68 
69 /*! \brief Find the amplitude for a particular phase.
70  \param phase The desired phase 32 bit phase.
71  \return The signal amplitude.
72 */
73 SPAN_DECLARE(int16_t) dds_lookup(uint32_t phase);
74 
75 /*! \brief Find the amplitude for a particular phase offset from an accumulated phase.
76  \param phase_acc The accumulated phase.
77  \param phase_offset The phase offset.
78  \return The signal amplitude.
79 */
80 SPAN_DECLARE(int16_t) dds_offset(uint32_t phase_acc, int32_t phase_offset);
81 
82 /*! \brief Advance the phase, without returning any new signal sample.
83  \param phase_acc A pointer to a phase accumulator value.
84  \param phase_rate The phase increment to be applied.
85 */
86 SPAN_DECLARE(void) dds_advance(uint32_t *phase_acc, int32_t phase_rate);
87 
88 /*! \brief Generate an integer tone sample.
89  \param phase_acc A pointer to a phase accumulator value.
90  \param phase_rate The phase increment to be applied.
91  \return The signal amplitude, between -32767 and 32767.
92 */
93 SPAN_DECLARE(int16_t) dds(uint32_t *phase_acc, int32_t phase_rate);
94 
95 /*! \brief Lookup the integer value of a specified phase.
96  \param phase The phase accumulator value to be looked up.
97  \return The signal amplitude, between -32767 and 32767.
98 */
99 SPAN_DECLARE(int16_t) dds_lookup(uint32_t phase);
100 
101 /*! \brief Generate an integer tone sample, with modulation.
102  \param phase_acc A pointer to a phase accumulator value.
103  \param phase_rate The phase increment to be applied.
104  \param scale The scaling factor.
105  \param phase The phase offset.
106  \return The signal amplitude, between -32767 and 32767.
107 */
108 SPAN_DECLARE(int16_t) dds_mod(uint32_t *phase_acc, int32_t phase_rate, int16_t scale, int32_t phase);
109 
110 /*! \brief Lookup the complex integer value of a specified phase.
111  \param phase The phase accumulator value to be looked up.
112  \return The complex signal amplitude, between (-32767, -32767) and (32767, 32767).
113 */
114 SPAN_DECLARE(complexi_t) dds_lookup_complexi(uint32_t phase);
115 
116 /*! \brief Generate a complex integer tone sample.
117  \param phase_acc A pointer to a phase accumulator value.
118  \param phase_rate The phase increment to be applied.
119  \return The complex signal amplitude, between (-32767, -32767) and (32767, 32767).
120 */
121 SPAN_DECLARE(complexi_t) dds_complexi(uint32_t *phase_acc, int32_t phase_rate);
122 
123 /*! \brief Generate a complex integer tone sample, with modulation.
124  \param phase_acc A pointer to a phase accumulator value.
125  \param phase_rate The phase increment to be applied.
126  \param scale The scaling factor.
127  \param phase The phase offset.
128  \return The complex signal amplitude, between (-32767, -32767) and (32767, 32767).
129 */
130 SPAN_DECLARE(complexi_t) dds_complexi_mod(uint32_t *phase_acc, int32_t phase_rate, int16_t scale, int32_t phase);
131 
132 /*! \brief Generate a complex 16 bit integer tone sample.
133  \param phase_acc A pointer to a phase accumulator value.
134  \param phase_rate The phase increment to be applied.
135  \return The complex signal amplitude, between (-32767, -32767) and (32767, 32767).
136 */
137 SPAN_DECLARE(complexi16_t) dds_lookup_complexi16(uint32_t phase);
138 
139 /*! \brief Generate a complex 16 bit integer tone sample.
140  \param phase_acc A pointer to a phase accumulator value.
141  \param phase_rate The phase increment to be applied.
142  \return The complex signal amplitude, between (-32767, -32767) and (32767, 32767).
143 */
144 SPAN_DECLARE(complexi16_t) dds_complexi16(uint32_t *phase_acc, int32_t phase_rate);
145 
146 /*! \brief Generate a complex 16bit integer tone sample, with modulation.
147  \param phase_acc A pointer to a phase accumulator value.
148  \param phase_rate The phase increment to be applied.
149  \param scale The scaling factor.
150  \param phase The phase offset.
151  \return The complex signal amplitude, between (-32767, -32767) and (32767, 32767).
152 */
153 SPAN_DECLARE(complexi16_t) dds_complexi16_mod(uint32_t *phase_acc, int32_t phase_rate, int16_t scale, int32_t phase);
154 
155 /*! \brief Generate a complex 32 bit integer tone sample, with modulation.
156  \param phase_acc A pointer to a phase accumulator value.
157  \param phase_rate The phase increment to be applied.
158  \param scale The scaling factor.
159  \param phase The phase offset.
160  \return The complex signal amplitude, between (-32767, -32767) and (32767, 32767).
161 */
162 SPAN_DECLARE(complexi32_t) dds_complexi32_mod(uint32_t *phase_acc, int32_t phase_rate, int16_t scale, int32_t phase);
163 
164 /*! \brief Generate a complex 32 bit integer tone sample.
165  \param phase_acc A pointer to a phase accumulator value.
166  \param phase_rate The phase increment to be applied.
167  \return The complex signal amplitude, between (-32767, -32767) and (32767, 32767).
168 */
169 SPAN_DECLARE(complexi32_t) dds_lookup_complexi32(uint32_t phase);
170 
171 /*! \brief Generate a complex 32 bit integer tone sample.
172  \param phase_acc A pointer to a phase accumulator value.
173  \param phase_rate The phase increment to be applied.
174  \return The complex signal amplitude, between (-32767, -32767) and (32767, 32767).
175 */
176 SPAN_DECLARE(complexi32_t) dds_complexi32(uint32_t *phase_acc, int32_t phase_rate);
177 
178 /*! \brief Generate a complex 32 bit integer tone sample, with modulation.
179  \param phase_acc A pointer to a phase accumulator value.
180  \param phase_rate The phase increment to be applied.
181  \param scale The scaling factor.
182  \param phase The phase offset.
183  \return The complex signal amplitude, between (-32767, -32767) and (32767, 32767).
184 */
185 SPAN_DECLARE(complexi32_t) dds_complexi32_mod(uint32_t *phase_acc, int32_t phase_rate, int16_t scale, int32_t phase);
186 
187 /*! \brief Find the phase rate equivalent to a frequency, in Hz.
188  \param frequency The frequency, in Hz.
189  \return The equivalent phase rate.
190 */
191 SPAN_DECLARE(int32_t) dds_phase_ratef(float frequency);
192 
193 /*! \brief Find the frequency, in Hz, equivalent to a phase rate.
194  \param phase_rate The phase rate.
195  \return The equivalent frequency, in Hz.
196 */
197 SPAN_DECLARE(float) dds_frequencyf(int32_t phase_rate);
198 
199 /*! \brief Find the scaling factor equivalent to a dBm0 value.
200  \param level The signal level in dBm0.
201  \return The equivalent scaling factor.
202 */
203 SPAN_DECLARE(float) dds_scaling_dbm0f(float level);
204 
205 /*! \brief Find the scaling factor equivalent to a dBmov value.
206  \param level The signal level in dBmov.
207  \return The equivalent scaling factor.
208 */
209 SPAN_DECLARE(float) dds_scaling_dbovf(float level);
210 
211 /*! \brief Advance the phase, without returning any new signal sample.
212  \param phase_acc A pointer to a phase accumulator value.
213  \param phase_rate The phase increment to be applied.
214 */
215 SPAN_DECLARE(void) dds_advancef(uint32_t *phase_acc, int32_t phase_rate);
216 
217 /*! \brief Generate a floating point tone sample.
218  \param phase_acc A pointer to a phase accumulator value.
219  \param phase_rate The phase increment to be applied.
220  \return The signal amplitude, between -1.0 and 1.0.
221 */
222 SPAN_DECLARE(float) ddsf(uint32_t *phase_acc, int32_t phase_rate);
223 
224 /*! \brief Lookup the floating point value of a specified phase.
225  \param phase The phase accumulator value to be looked up.
226  \return The signal amplitude, between -1.0 and 1.0.
227 */
228 SPAN_DECLARE(float) dds_lookupf(uint32_t phase);
229 
230 /*! \brief Generate a floating point tone sample, with modulation.
231  \param phase_acc A pointer to a phase accumulator value.
232  \param phase_rate The phase increment to be applied.
233  \param scale The scaling factor.
234  \param phase The phase offset.
235  \return The signal amplitude, between -1.0 and 1.0.
236 */
237 SPAN_DECLARE(float) dds_modf(uint32_t *phase_acc, int32_t phase_rate, float scale, int32_t phase);
238 
239 /*! \brief Generate a complex floating point tone sample.
240  \param phase_acc A pointer to a phase accumulator value.
241  \param phase_rate The phase increment to be applied.
242  \return The complex signal amplitude, between (-1.0, -1.0) and (1.0, 1.0).
243 */
244 SPAN_DECLARE(complexf_t) dds_complexf(uint32_t *phase_acc, int32_t phase_rate);
245 
246 /*! \brief Lookup the complex value of a specified phase.
247  \param phase The phase accumulator value to be looked up.
248  \return The complex signal amplitude, between (-1.0, -1.0) and (1.0, 1.0).
249 */
250 SPAN_DECLARE(complexf_t) dds_lookup_complexf(uint32_t phase_acc);
251 
252 /*! \brief Generate a complex floating point tone sample, with modulation.
253  \param phase_acc A pointer to a phase accumulator value.
254  \param phase_rate The phase increment to be applied.
255  \param scale The scaling factor.
256  \param phase The phase offset.
257  \return The complex signal amplitude, between (-1.0, -1.0) and (1.0, 1.0).
258 */
259 SPAN_DECLARE(complexf_t) dds_complex_modf(uint32_t *phase_acc, int32_t phase_rate, float scale, int32_t phase);
260 
261 #if defined(__cplusplus)
262 }
263 #endif
264 
265 #endif
266 /*- End of file ------------------------------------------------------------*/
complexi32_t dds_complexi32_mod(uint32_t *phase_acc, int32_t phase_rate, int16_t scale, int32_t phase)
Generate a complex 32 bit integer tone sample, with modulation.
Definition: dds_int.c:458
Definition: complex.h:88
void dds_advance(uint32_t *phase_acc, int32_t phase_rate)
Advance the phase, without returning any new signal sample.
Definition: dds_int.c:362
float dds_scaling_dbm0f(float level)
Find the scaling factor equivalent to a dBm0 value.
Definition: dds_float.c:2121
float dds_phase_to_radians(uint32_t phase)
Convert a 32 bit phase angle to an angle in radians, between 0 and 2*PI.
Definition: dds_float.c:2103
complexf_t dds_complexf(uint32_t *phase_acc, int32_t phase_rate)
Generate a complex floating point tone sample.
Definition: dds_float.c:2165
float dds_scaling_dbovf(float level)
Find the scaling factor equivalent to a dBmov value.
Definition: dds_float.c:2127
int16_t dds(uint32_t *phase_acc, int32_t phase_rate)
Generate an integer tone sample.
Definition: dds_int.c:368
float dds_modf(uint32_t *phase_acc, int32_t phase_rate, float scale, int32_t phase)
Generate a floating point tone sample, with modulation.
Definition: dds_float.c:2155
int32_t dds_phase_ratef(float frequency)
Find the phase rate equivalent to a frequency, in Hz.
Definition: dds_float.c:2109
int16_t dds_scaling_dbm0(float level)
Find the scaling factor needed to achieve a specified level in dBm0.
Definition: dds_int.c:328
int32_t dds_phase_rate(float frequency)
Find the phase rate value to achieve a particular frequency.
Definition: dds_int.c:316
complexi_t dds_complexi(uint32_t *phase_acc, int32_t phase_rate)
Generate a complex integer tone sample.
Definition: dds_int.c:394
complexi16_t dds_complexi16_mod(uint32_t *phase_acc, int32_t phase_rate, int16_t scale, int32_t phase)
Generate a complex 16bit integer tone sample, with modulation.
Definition: dds_int.c:431
complexi16_t dds_lookup_complexi16(uint32_t phase)
Generate a complex 16 bit integer tone sample.
Definition: dds_int.c:415
complexi32_t dds_complexi32(uint32_t *phase_acc, int32_t phase_rate)
Generate a complex 32 bit integer tone sample.
Definition: dds_int.c:448
void dds_advancef(uint32_t *phase_acc, int32_t phase_rate)
Advance the phase, without returning any new signal sample.
Definition: dds_float.c:2133
complexi16_t dds_complexi16(uint32_t *phase_acc, int32_t phase_rate)
Generate a complex 16 bit integer tone sample.
Definition: dds_int.c:421
int16_t dds_scaling_dbov(float level)
Find the scaling factor needed to achieve a specified level in dBmov.
Definition: dds_int.c:334
int16_t dds_mod(uint32_t *phase_acc, int32_t phase_rate, int16_t scale, int32_t phase)
Generate an integer tone sample, with modulation.
Definition: dds_int.c:378
Definition: complex.h:77
float dds_frequencyf(int32_t phase_rate)
Find the frequency, in Hz, equivalent to a phase rate.
Definition: dds_float.c:2115
complexf_t dds_lookup_complexf(uint32_t phase_acc)
Lookup the complex value of a specified phase.
Definition: dds_float.c:2176
Definition: complex.h:42
complexi_t dds_lookup_complexi(uint32_t phase)
Lookup the complex integer value of a specified phase.
Definition: dds_int.c:388
int16_t dds_offset(uint32_t phase_acc, int32_t phase_offset)
Find the amplitude for a particular phase offset from an accumulated phase.
Definition: dds_int.c:356
float dds_lookupf(uint32_t phase)
Lookup the floating point value of a specified phase.
Definition: dds_float.c:2149
int16_t dds_lookup(uint32_t phase)
Find the amplitude for a particular phase.
Definition: dds_int.c:340
complexi32_t dds_lookup_complexi32(uint32_t phase)
Generate a complex 32 bit integer tone sample.
Definition: dds_int.c:442
complexi_t dds_complexi_mod(uint32_t *phase_acc, int32_t phase_rate, int16_t scale, int32_t phase)
Generate a complex integer tone sample, with modulation.
Definition: dds_int.c:404
complexf_t dds_complex_modf(uint32_t *phase_acc, int32_t phase_rate, float scale, int32_t phase)
Generate a complex floating point tone sample, with modulation.
Definition: dds_float.c:2183
float ddsf(uint32_t *phase_acc, int32_t phase_rate)
Generate a floating point tone sample.
Definition: dds_float.c:2139
Definition: complex.h:99
float dds_frequency(int32_t phase_rate)
Find the frequency, in Hz, equivalent to a phase rate.
Definition: dds_int.c:322