Add filter switch to FSK modulator

pull/1/head
Andreas Eversberg 3 years ago
parent 6dcc8baad4
commit 445af0c0a2
  1. 2
      src/bnetz/dialer.c
  2. 2
      src/bnetz/dsp.c
  3. 27
      src/libfsk/fsk.c
  4. 4
      src/libfsk/fsk.h
  5. 2
      src/nmt/dsp.c
  6. 4
      src/r2000/dsp.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;
}

@ -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;
}

@ -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;

@ -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);

@ -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;
}

@ -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;
}

Loading…
Cancel
Save