Skip to content

Commit e5bd45d

Browse files
authored
Merge pull request drowe67#309 from DJ2LS/ls-fmin-fmax
New function: freedv_set_fmin_fmax
2 parents 5d4bb60 + d614ce8 commit e5bd45d

File tree

4 files changed

+46
-2
lines changed

4 files changed

+46
-2
lines changed

src/freedv_api.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1372,6 +1372,33 @@ int freedv_get_bits_per_modem_frame (struct freedv *f) {return f->bits_per
13721372
int freedv_get_rx_status (struct freedv *f) {return f->rx_status;}
13731373
void freedv_get_fsk_S_and_N (struct freedv *f, float *S, float *N) { *S = f->fsk_S[0]; *N = f->fsk_N[0]; }
13741374

1375+
1376+
/*---------------------------------------------------------------------------*\
1377+
1378+
FUNCTIONS...: freedv_set_tuning_range
1379+
AUTHOR......: Simon Lang - DJ2LS
1380+
DATE CREATED: 18 feb 2022
1381+
DEFAULT.....: fmin: -50.0Hz fmax: 50.0Hz
1382+
DESCRIPTION.:
1383+
1384+
|<---fmin - | rx centre frequency | + fmax--->|
1385+
1386+
Useful for handling frequency offsets,
1387+
e.g. caused by an imprecise VFO, the trade off is more CPU power is required.
1388+
1389+
\*---------------------------------------------------------------------------*/
1390+
int freedv_set_tuning_range(struct freedv *freedv, float val_fmin, float val_fmax) {
1391+
1392+
if (is_ofdm_data_mode(freedv) && (strcmp(freedv->ofdm->data_mode, "burst") == 0)) {
1393+
freedv->ofdm->fmin = val_fmin;
1394+
freedv->ofdm->fmax = val_fmax;
1395+
return 1;
1396+
} else {
1397+
return 0;
1398+
}
1399+
}
1400+
1401+
13751402
int freedv_get_n_max_speech_samples(struct freedv *f) {
13761403
/* When "passing through" demod samples to the speech output
13771404
(e.g. no sync and squelch off) f->nin bounces around with

src/freedv_api.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ void freedv_set_phase_est_bandwidth_mode(struct freedv *f, int val);
240240
void freedv_set_eq (struct freedv *f, int val);
241241
void freedv_set_frames_per_burst (struct freedv *f, int framesperburst);
242242
void freedv_passthrough_gain (struct freedv *f, float g);
243+
int freedv_set_tuning_range (struct freedv *freedv, float val_fmin, float val_fmax);
243244

244245
// Get parameters -------------------------------------------------------------------------
245246

src/ofdm.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,8 @@ struct OFDM *ofdm_create(const struct OFDM_CONFIG *config) {
219219
ofdm->clip_en = false;
220220
ofdm->foff_limiter = false;
221221
ofdm->data_mode = "";
222+
ofdm->fmin = -50.0; /* frequency minimum for ofdm acquisition range */
223+
ofdm->fmax = 50.0; /* frequency maximum for ofdm acquisition range */
222224
memset(ofdm->tx_uw, 0, ofdm->nuwbits);
223225
} else {
224226
/* Use the users values */
@@ -252,6 +254,8 @@ struct OFDM *ofdm_create(const struct OFDM_CONFIG *config) {
252254
ofdm->clip_en = config->clip_en;
253255
memcpy(ofdm->tx_uw, config->tx_uw, ofdm->nuwbits);
254256
ofdm->data_mode = config->data_mode;
257+
ofdm->fmin = config->fmin; /* frequency minimum for ofdm acquisition range */
258+
ofdm->fmax = config->fmax; /* frequency maximum for ofdm acquisition range */
255259

256260
}
257261

@@ -297,6 +301,9 @@ struct OFDM *ofdm_create(const struct OFDM_CONFIG *config) {
297301
ofdm->config.clip_en = ofdm->clip_en;
298302
memcpy(ofdm->config.tx_uw, ofdm->tx_uw, ofdm->nuwbits);
299303
ofdm->config.data_mode = ofdm->data_mode;
304+
ofdm->config.fmin = ofdm->fmin;
305+
ofdm->config.fmax = ofdm->fmax;
306+
300307

301308
/* Calculate sizes from config param */
302309

@@ -421,6 +428,10 @@ struct OFDM *ofdm_create(const struct OFDM_CONFIG *config) {
421428
ofdm->nin = ofdm->samplesperframe;
422429
ofdm->mean_amp = 0.0f;
423430
ofdm->foff_metric = 0.0f;
431+
432+
ofdm->fmin = -50.0f;
433+
ofdm->fmax = 50.0f;
434+
424435
/*
425436
* Unique Word symbol placement. Note we need to group the UW
426437
* bits so they fit into symbols. The LDPC decoder works on
@@ -1158,9 +1169,9 @@ static void burst_acquisition_detector(struct OFDM *ofdm,
11581169

11591170
float fmin, fmax, fstep;
11601171
int tstep;
1161-
1172+
11621173
// initial search over coarse grid
1163-
tstep = 4; fstep = 5; fmin = -50.0; fmax = 50.0;
1174+
tstep = 4; fstep = 5; fmin = ofdm->fmin; fmax = ofdm->fmax;
11641175
*timing_mx = est_timing_and_freq(ofdm, ct_est, foff_est,
11651176
&rx[n], 2*ofdm->samplesperframe,
11661177
known_sequence, ofdm->samplesperframe,

src/ofdm_internal.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ struct OFDM_CONFIG {
106106
bool clip_en;
107107
char mode[16]; /* OFDM mode in string form */
108108
char *data_mode;
109+
float fmin;
110+
float fmax;
109111
};
110112

111113
struct OFDM {
@@ -165,6 +167,9 @@ struct OFDM {
165167
float tx_nlower; /* TX lowest carrier freq */
166168
float rx_nlower; /* RX lowest carrier freq */
167169
float doc; /* division of radian circle */
170+
171+
float fmin;
172+
float fmax;
168173

169174
// Pointers
170175

0 commit comments

Comments
 (0)