comparison spandsp-0.0.3/spandsp-0.0.3/src/spandsp/fsk.h @ 5:f762bf195c4b

import spandsp-0.0.3
author Peter Meerwald <pmeerw@cosy.sbg.ac.at>
date Fri, 25 Jun 2010 16:00:21 +0200
parents
children
comparison
equal deleted inserted replaced
4:26cd8f1ef0b1 5:f762bf195c4b
1 /*
2 * SpanDSP - a series of DSP components for telephony
3 *
4 * fsk.h - FSK modem transmit and receive parts
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 General Public License version 2, as
14 * 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 General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 *
25 * $Id: fsk.h,v 1.17 2006/10/24 13:45:28 steveu Exp $
26 */
27
28 /*! \file */
29
30 /*! \page fsk_page FSK modems
31 \section fsk_page_sec_1 What does it do?
32 Most of the oldest telephony modems use incorent FSK modulation. This module can
33 be used to implement both the trasmit and receive sides of a number of these
34 modems. There are integrated definitions for:
35
36 - V.21
37 - V.23
38 - Bell 103
39 - Bell 202
40 - Weitbrecht (Used for TDD - Telecoms Device for the Deaf)
41
42 The audio output or input is a stream of 16 bit samples, at 8000 samples/second.
43 The transmit and receive sides can be used independantly.
44
45 \section fsk_page_sec_2 The transmitter
46
47 The FSK transmitter uses a DDS generator to synthesise the waveform. This
48 naturally produces phase coherent transitions, as the phase update rate is
49 switched, producing a clean spectrum. The symbols are not generally an integer
50 number of samples long. However, the symbol time for the fastest data rate
51 generally used (1200bps) is more than 7 samples long. The jitter resulting from
52 switching at the nearest sample is, therefore, acceptable. No interpolation is
53 used.
54
55 \section fsk_page_sec_3 The receiver
56
57 The FSK receiver uses a quadrature correlation technique to demodulate the
58 signal. Two DDS quadrature oscillators are used. The incoming signal is
59 correlated with the oscillator signals over a period of one symbol. The
60 oscillator giving the highest net correlation from its I and Q outputs is the
61 one that matches the frequency being transmitted during the correlation
62 interval. Because the transmission is totally asynchronous, the demodulation
63 process must run sample by sample to find the symbol transitions. The
64 correlation is performed on a sliding window basis, so the computational load of
65 demodulating sample by sample is not great.
66
67 Two modes of symbol synchronisation are provided:
68
69 - In synchronous mode, symbol transitions are smoothed, to track their true
70 position in the prescence of high timing jitter. This provides the most
71 reliable symbol recovery in poor signal to noise conditions. However, it
72 takes a little time to settle, so it not really suitable for data streams
73 which must start up instantaneously (e.g. the TDD systems used by hearing
74 impaired people).
75
76 - In asynchronous mode each transition is taken at face value, with no temporal
77 smoothing. There is no settling time for this mode, but when the signal to
78 noise ratio is very poor it does not perform as well as the synchronous mode.
79 */
80
81 #if !defined(_FSK_H_)
82 #define _FSK_H_
83
84 /*!
85 FSK modem specification. This defines the frequencies, signal levels and
86 baud rate (== bit rate for simple FSK) for a single channel of an FSK modem.
87 */
88 typedef struct
89 {
90 const char *name;
91 int freq_zero;
92 int freq_one;
93 int tx_level;
94 int min_level;
95 int baud_rate;
96 } fsk_spec_t;
97
98 /* Predefined FSK modem channels */
99 enum
100 {
101 FSK_V21CH1 = 0,
102 FSK_V21CH2,
103 FSK_V23CH1,
104 FSK_V23CH2,
105 FSK_BELL103CH1,
106 FSK_BELL103CH2,
107 FSK_BELL202,
108 FSK_WEITBRECHT, /* Used for TDD (Telecom Device for the Deaf) */
109 };
110
111 extern fsk_spec_t preset_fsk_specs[];
112
113 /*!
114 FSK modem transmit descriptor. This defines the state of a single working
115 instance of an FSK modem transmitter.
116 */
117 typedef struct
118 {
119 int baud_rate;
120 get_bit_func_t get_bit;
121 void *user_data;
122
123 int32_t phase_rates[2];
124 int scaling;
125 int32_t current_phase_rate;
126 uint32_t phase_acc;
127 int baud_frac;
128 int baud_inc;
129 int shutdown;
130 } fsk_tx_state_t;
131
132 /* The longest window will probably be 106 for 75 baud */
133 #define FSK_MAX_WINDOW_LEN 128
134
135 /*!
136 FSK modem receive descriptor. This defines the state of a single working
137 instance of an FSK modem receiver.
138 */
139 typedef struct
140 {
141 int baud_rate;
142 int sync_mode;
143 put_bit_func_t put_bit;
144 void *user_data;
145
146 int min_power;
147 power_meter_t power;
148 int carrier_present;
149 int16_t last_sample;
150
151 int32_t phase_rate[2];
152 uint32_t phase_acc[2];
153
154 int correlation_span;
155
156 int32_t window_i[2][FSK_MAX_WINDOW_LEN];
157 int32_t window_q[2][FSK_MAX_WINDOW_LEN];
158 int32_t dot_i[2];
159 int32_t dot_q[2];
160 int buf_ptr;
161
162 int baud_inc;
163 int baud_pll;
164 int lastbit;
165 int scaling_shift;
166 } fsk_rx_state_t;
167
168 #ifdef __cplusplus
169 extern "C" {
170 #endif
171
172 /*! Initialise an FSK modem transmit context.
173 \brief Initialise an FSK modem transmit context.
174 \param s The modem context.
175 \param spec The specification of the modem tones and rate.
176 \param get_bit The callback routine used to get the data to be transmitted.
177 \param user_data An opaque pointer.
178 \return A pointer to the modem context, or NULL if there was a problem. */
179 fsk_tx_state_t *fsk_tx_init(fsk_tx_state_t *s,
180 fsk_spec_t *spec,
181 get_bit_func_t get_bit,
182 void *user_data);
183
184 /*! Adjust an FSK modem transmit context's power output.
185 \brief Adjust an FSK modem transmit context's power output.
186 \param s The modem context.
187 \param power The power level, in dBm0 */
188 void fsk_tx_power(fsk_tx_state_t *s, float power);
189
190 void fsk_tx_set_get_bit(fsk_tx_state_t *s, get_bit_func_t get_bit, void *user_data);
191
192 /*! Generate a block of FSK modem audio samples.
193 \brief Generate a block of FSK modem audio samples.
194 \param s The modem context.
195 \param amp The audio sample buffer.
196 \param len The number of samples to be generated.
197 \return The number of samples actually generated.
198 */
199 int fsk_tx(fsk_tx_state_t *s, int16_t *amp, int len);
200
201 /*! Get the current received signal power.
202 \param s The modem context.
203 \return The signal power, in dBm0. */
204 float fsk_rx_signal_power(fsk_rx_state_t *s);
205
206 /*! Adjust an FSK modem receive context's carrier detect power threshold.
207 \brief Adjust an FSK modem receive context's carrier detect power threshold.
208 \param s The modem context.
209 \param power The power level, in dBm0 */
210 void fsk_rx_signal_cutoff(fsk_rx_state_t *s, float cutoff);
211
212 /*! Initialise an FSK modem receive context.
213 \brief Initialise an FSK modem receive context.
214 \param s The modem context.
215 \param spec The specification of the modem tones and rate.
216 \param sync_mode TRUE for synchronous modem. FALSE for asynchronous mode.
217 \param put_bit The callback routine used to put the received data.
218 \param user_data An opaque pointer.
219 \return A pointer to the modem context, or NULL if there was a problem. */
220 fsk_rx_state_t *fsk_rx_init(fsk_rx_state_t *s,
221 fsk_spec_t *spec,
222 int sync_mode,
223 put_bit_func_t put_bit,
224 void *user_data);
225
226 /*! Process a block of received FSK modem audio samples.
227 \brief Process a block of received FSK modem audio samples.
228 \param s The modem context.
229 \param amp The audio sample buffer.
230 \param len The number of samples in the buffer.
231 \return The number of samples unprocessed.
232 */
233 int fsk_rx(fsk_rx_state_t *s, const int16_t *amp, int len);
234
235 void fsk_rx_set_put_bit(fsk_rx_state_t *s, put_bit_func_t put_bit, void *user_data);
236
237 #ifdef __cplusplus
238 }
239 #endif
240
241 #endif
242 /*- End of file ------------------------------------------------------------*/

Repositories maintained by Peter Meerwald, pmeerw@pmeerw.net.