aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAndreas Eversberg <jolly@eversberg.eu>2019-09-09 19:22:43 +0200
committerAndreas Eversberg <jolly@eversberg.eu>2019-11-29 15:58:32 +0100
commit445af0c0a2174b9718c4258b89dec8f9a1012321 (patch)
tree5570ddba2ec21c0b3d788381e05d201ceabae14c /src
parent6dcc8baad448d000ef355abc6d9abf7a3490a800 (diff)
Add filter switch to FSK modulator
Diffstat (limited to 'src')
-rw-r--r--src/bnetz/dialer.c2
-rw-r--r--src/bnetz/dsp.c2
-rw-r--r--src/libfsk/fsk.c27
-rw-r--r--src/libfsk/fsk.h4
-rw-r--r--src/nmt/dsp.c2
-rw-r--r--src/r2000/dsp.c4
6 files changed, 32 insertions, 9 deletions
diff --git a/src/bnetz/dialer.c b/src/bnetz/dialer.c
index e44ddf5..31ef86e 100644
--- a/src/bnetz/dialer.c
+++ b/src/bnetz/dialer.c
@@ -340,7 +340,7 @@ int main(int argc, char *argv[])
sprintf(funkwahl, "wwww%c%s%se%c%s%se", start_digit, station_id, dialing + 1, start_digit, station_id, dialing + 1);
/* init fsk */
- if (fsk_mod_init(&fsk_mod, NULL, fsk_send_bit, samplerate, BIT_RATE, F0, F1, 1.0, 0) < 0) {
+ if (fsk_mod_init(&fsk_mod, NULL, fsk_send_bit, samplerate, BIT_RATE, F0, F1, 1.0, 0, 0) < 0) {
PDEBUG(DDSP, DEBUG_ERROR, "FSK init failed!\n");
goto exit;
}
diff --git a/src/bnetz/dsp.c b/src/bnetz/dsp.c
index e2928ba..7315d26 100644
--- a/src/bnetz/dsp.c
+++ b/src/bnetz/dsp.c
@@ -96,7 +96,7 @@ int dsp_init_sender(bnetz_t *bnetz, double squelch_db)
PDEBUG(DDSP, DEBUG_DEBUG, "Using FSK level of %.3f (%.3f KHz deviation @ 2000 Hz)\n", TX_PEAK_FSK, 4.0);
/* init fsk */
- if (fsk_mod_init(&bnetz->fsk_mod, bnetz, fsk_send_bit, bnetz->sender.samplerate, BIT_RATE, F0, F1, TX_PEAK_FSK, 0) < 0) {
+ if (fsk_mod_init(&bnetz->fsk_mod, bnetz, fsk_send_bit, bnetz->sender.samplerate, BIT_RATE, F0, F1, TX_PEAK_FSK, 0, 0) < 0) {
PDEBUG_CHAN(DDSP, DEBUG_ERROR, "FSK init failed!\n");
return -EINVAL;
}
diff --git a/src/libfsk/fsk.c b/src/libfsk/fsk.c
index 7f1ed6e..7026953 100644
--- a/src/libfsk/fsk.c
+++ b/src/libfsk/fsk.c
@@ -39,7 +39,7 @@
* level = level to modulate the frequencies
* coherent = use coherent modulation (FFSK)
*/
-int fsk_mod_init(fsk_mod_t *fsk, void *inst, int (*send_bit)(void *inst), int samplerate, double bitrate, double f0, double f1, double level, int coherent)
+int fsk_mod_init(fsk_mod_t *fsk, void *inst, int (*send_bit)(void *inst), int samplerate, double bitrate, double f0, double f1, double level, int coherent, int filter)
{
int i;
int rc;
@@ -76,9 +76,9 @@ int fsk_mod_init(fsk_mod_t *fsk, void *inst, int (*send_bit)(void *inst), int sa
PDEBUG(DDSP, DEBUG_DEBUG, "Bitduration of %.4f bits per sample @ %d.\n", fsk->bits_per_sample, samplerate);
fsk->phaseshift65536[0] = f0 / (double)samplerate * 65536.0;
- PDEBUG(DDSP, DEBUG_DEBUG, "phaseshift65536[0] = %.4f\n", fsk->phaseshift65536[0]);
+ PDEBUG(DDSP, DEBUG_DEBUG, "F0 = %.0f Hz (phaseshift65536[0] = %.4f)\n", f0, fsk->phaseshift65536[0]);
fsk->phaseshift65536[1] = f1 / (double)samplerate * 65536.0;
- PDEBUG(DDSP, DEBUG_DEBUG, "phaseshift65536[1] = %.4f\n", fsk->phaseshift65536[1]);
+ PDEBUG(DDSP, DEBUG_DEBUG, "F1 = %.0f Hz (phaseshift65536[1] = %.4f)\n", f1, fsk->phaseshift65536[1]);
/* use coherent modulation, i.e. each bit has an integer number of
* half waves and starts/ends at zero crossing
@@ -86,6 +86,7 @@ int fsk_mod_init(fsk_mod_t *fsk, void *inst, int (*send_bit)(void *inst), int sa
if (coherent) {
double waves;
+ PDEBUG(DDSP, DEBUG_DEBUG, "enable coherent FSK modulation mode\n");
fsk->coherent = 1;
waves = (f0 / bitrate);
if (fabs(round(waves * 2) - (waves * 2)) > 0.001) {
@@ -101,6 +102,20 @@ int fsk_mod_init(fsk_mod_t *fsk, void *inst, int (*send_bit)(void *inst), int sa
fsk->cycles_per_bit65536[1] = waves * 65536.0;
}
+ /* if filter is enabled, add a band pass filter to smoot the spectrum of the tones
+ * the bandwidth is twice the difference between f0 and f1
+ */
+ if (filter) {
+ double low = (f0 + f1) / 2.0 - fabs(f0 - f1);
+ double high = (f0 + f1) / 2.0 + fabs(f0 - f1);
+
+ PDEBUG(DDSP, DEBUG_DEBUG, "enable filter to smooth FSK transmission. (frequency rage %.0f .. %.0f)\n", low, high);
+ fsk->filter = 1;
+ /* use fourth order (2 iter) filter, since it is as fast as second order (1 iter) filter */
+ iir_highpass_init(&fsk->lp[0], low, samplerate, 2);
+ iir_lowpass_init(&fsk->lp[1], high, samplerate, 2);
+ }
+
return 0;
error:
@@ -180,6 +195,12 @@ next_bit:
goto next_bit;
}
+ /* post filter */
+ if (fsk->filter) {
+ iir_process(&fsk->lp[0], sample, length);
+ iir_process(&fsk->lp[1], sample, length);
+ }
+
done:
fsk->tx_phase65536 = phase;
diff --git a/src/libfsk/fsk.h b/src/libfsk/fsk.h
index 395e915..4ea8b88 100644
--- a/src/libfsk/fsk.h
+++ b/src/libfsk/fsk.h
@@ -15,6 +15,8 @@ typedef struct fsk_mod {
int low_bit, high_bit; /* a low or high deviation means which bit? */
int tx_bit; /* current transmitting bit (-1 if not set) */
double tx_bitpos; /* current transmit position in bit */
+ int filter; /* set, if filters are used */
+ iir_filter_t lp[2]; /* filter to smoot transmission spectrum */
} fsk_mod_t;
typedef struct fsk_demod {
@@ -30,7 +32,7 @@ typedef struct fsk_demod {
double rx_bitadjust; /* how much does a bit change cause the sample clock to be adjusted in phase */
} fsk_demod_t;
-int fsk_mod_init(fsk_mod_t *fsk, void *inst, int (*send_bit)(void *inst), int samplerate, double bitrate, double f0, double f1, double level, int coherent);
+int fsk_mod_init(fsk_mod_t *fsk, void *inst, int (*send_bit)(void *inst), int samplerate, double bitrate, double f0, double f1, double level, int coherent, int filter);
void fsk_mod_cleanup(fsk_mod_t *fsk);
int fsk_mod_send(fsk_mod_t *fsk, sample_t *sample, int length, int add);
void fsk_mod_tx_reset(fsk_mod_t *fsk);
diff --git a/src/nmt/dsp.c b/src/nmt/dsp.c
index 1dcd606..d8e1077 100644
--- a/src/nmt/dsp.c
+++ b/src/nmt/dsp.c
@@ -120,7 +120,7 @@ int dsp_init_sender(nmt_t *nmt, double deviation_factor)
PDEBUG(DDSP, DEBUG_DEBUG, "Using Supervisory level of %.3f (%.3f KHz deviation @ 4015 Hz)\n", TX_PEAK_SUPER * deviation_factor, 0.3 * deviation_factor);
/* init fsk */
- if (fsk_mod_init(&nmt->fsk_mod, nmt, fsk_send_bit, nmt->sender.samplerate, BIT_RATE, F0, F1, TX_PEAK_FSK, 1) < 0) {
+ if (fsk_mod_init(&nmt->fsk_mod, nmt, fsk_send_bit, nmt->sender.samplerate, BIT_RATE, F0, F1, TX_PEAK_FSK, 1, 0) < 0) {
PDEBUG_CHAN(DDSP, DEBUG_ERROR, "FSK init failed!\n");
return -EINVAL;
}
diff --git a/src/r2000/dsp.c b/src/r2000/dsp.c
index d52e8eb..771089c 100644
--- a/src/r2000/dsp.c
+++ b/src/r2000/dsp.c
@@ -85,7 +85,7 @@ int dsp_init_sender(r2000_t *r2000)
PDEBUG(DDSP, DEBUG_DEBUG, "Using FSK level of %.3f\n", TX_PEAK_FSK);
/* init fsk */
- if (fsk_mod_init(&r2000->fsk_mod, r2000, fsk_send_bit, r2000->sender.samplerate, FSK_BIT_RATE, FSK_F0, FSK_F1, TX_PEAK_FSK, 1) < 0) {
+ if (fsk_mod_init(&r2000->fsk_mod, r2000, fsk_send_bit, r2000->sender.samplerate, FSK_BIT_RATE, FSK_F0, FSK_F1, TX_PEAK_FSK, 1, 0) < 0) {
PDEBUG_CHAN(DDSP, DEBUG_ERROR, "FSK init failed!\n");
return -EINVAL;
}
@@ -99,7 +99,7 @@ int dsp_init_sender(r2000_t *r2000)
r2000->rx_max = 144;
/* init supervisorty fsk */
- if (fsk_mod_init(&r2000->super_fsk_mod, r2000, super_send_bit, r2000->sender.samplerate, SUPER_BIT_RATE, SUPER_F0, SUPER_F1, TX_PEAK_SUPER, 0) < 0) {
+ if (fsk_mod_init(&r2000->super_fsk_mod, r2000, super_send_bit, r2000->sender.samplerate, SUPER_BIT_RATE, SUPER_F0, SUPER_F1, TX_PEAK_SUPER, 0, 0) < 0) {
PDEBUG_CHAN(DDSP, DEBUG_ERROR, "FSK init failed!\n");
return -EINVAL;
}