mod: fix long IQ --dc decoding (reset)

pull/49/head
Zilog80 2022-09-10 03:08:33 +02:00
rodzic 5e2425b3a0
commit 145cf3e410
2 zmienionych plików z 41 dodań i 27 usunięć

Wyświetl plik

@ -125,14 +125,14 @@ static int dft_window(dft_t *dft, int w) {
dft->win[n] = 1.0;
break;
case 1: // Hann
dft->win[n] = 0.5 * ( 1.0 - cos(2*M_PI*n/(float)(dft->N2-1)) );
dft->win[n] = 0.5 * ( 1.0 - cos(_2PI*n/(float)(dft->N2-1)) );
break ;
case 2: // Hamming
dft->win[n] = 25/46.0 - (1.0 - 25/46.0)*cos(2*M_PI*n / (float)(dft->N2-1));
dft->win[n] = 25/46.0 - (1.0 - 25/46.0)*cos(_2PI*n / (float)(dft->N2-1));
break ;
case 3: // Blackmann
dft->win[n] = 7938/18608.0
- 9240/18608.0*cos(2*M_PI*n / (float)(dft->N2-1))
- 9240/18608.0*cos(_2PI*n / (float)(dft->N2-1))
+ 1430/18608.0*cos(4*M_PI*n / (float)(dft->N2-1));
break ;
}
@ -310,7 +310,7 @@ static int findstr(char *buff, char *str, int pos) {
return i;
}
float read_wav_header(pcm_t *pcm, FILE *fp) {
int read_wav_header(pcm_t *pcm, FILE *fp) {
char txt[4+1] = "\0\0\0\0";
unsigned char dat[4];
int byte, p=0;
@ -567,7 +567,7 @@ static int lowpass_init(float f, int taps, float **pws) {
ws = (float*)calloc( 2*taps+1, sizeof(float)); if (ws == NULL) return -1;
for (n = 0; n < taps; n++) {
w[n] = 7938/18608.0 - 9240/18608.0*cos(2*M_PI*n/(taps-1)) + 1430/18608.0*cos(4*M_PI*n/(taps-1)); // Blackmann
w[n] = 7938/18608.0 - 9240/18608.0*cos(_2PI*n/(taps-1)) + 1430/18608.0*cos(4*M_PI*n/(taps-1)); // Blackmann
h[n] = 2*f*sinc(2*f*(n-(taps-1)/2));
ws[n] = w[n]*h[n];
norm += ws[n]; // 1-norm
@ -600,7 +600,7 @@ static int lowpass_update(float f, int taps, float *ws) {
w = (double*)calloc( taps+1, sizeof(double)); if (w == NULL) return -1;
for (n = 0; n < taps; n++) {
w[n] = 7938/18608.0 - 9240/18608.0*cos(2*M_PI*n/(taps-1)) + 1430/18608.0*cos(4*M_PI*n/(taps-1)); // Blackmann
w[n] = 7938/18608.0 - 9240/18608.0*cos(_2PI*n/(taps-1)) + 1430/18608.0*cos(4*M_PI*n/(taps-1)); // Blackmann
h[n] = 2*f*sinc(2*f*(n-(taps-1)/2));
ws[n] = w[n]*h[n];
norm += ws[n]; // 1-norm
@ -675,7 +675,7 @@ int f32buf_sample(dsp_t *dsp, int inv) {
if (dsp->opt_nolut) {
double _s_base = (double)(dsp->sample_in*dsp->decM+j); // dsp->sample_dec
double f0 = dsp->xlt_fq*_s_base - dsp->Df*_s_base/(double)dsp->sr_base;
z = dsp->decMbuf[j] * cexp(f0*2*M_PI*I);
z = dsp->decMbuf[j] * cexp(f0*_2PI*I);
}
else {
z = dsp->decMbuf[j] * dsp->ex[dsp->sample_dec % dsp->lut_len];
@ -694,7 +694,7 @@ int f32buf_sample(dsp_t *dsp, int inv) {
if (dsp->opt_dc && !dsp->opt_nolut)
{
z *= cexp(-t*2*M_PI*dsp->Df*I);
z *= cexp(-t*_2PI*dsp->Df*I);
}
@ -717,8 +717,8 @@ int f32buf_sample(dsp_t *dsp, int inv) {
if (dsp->opt_iq >= 2) {
double xbit = 0.0;
//float complex xi = cexp(+I*M_PI*dsp->h/dsp->sps);
double f1 = -dsp->h*dsp->sr/(2.0*dsp->sps);
double f2 = -f1;
//double f1 = -dsp->h*dsp->sr/(2.0*dsp->sps);
//double f2 = -f1;
float complex X0 = 0;
float complex X = 0;
@ -730,13 +730,13 @@ int f32buf_sample(dsp_t *dsp, int inv) {
z0 = dsp->rot_iqbuf[(dsp->sample_in-n + dsp->N_IQBUF) % dsp->N_IQBUF];
// f1
X0 = z0 * cexp(-tn*2*M_PI*f1*I); // alt
X = z * cexp(-t *2*M_PI*f1*I); // neu
X0 = z0 * cexp(-tn*dsp->iw1); // alt
X = z * cexp(-t *dsp->iw1); // neu
dsp->F1sum += X - X0;
// f2
X0 = z0 * cexp(-tn*2*M_PI*f2*I); // alt
X = z * cexp(-t *2*M_PI*f2*I); // neu
X0 = z0 * cexp(-tn*dsp->iw2); // alt
X = z * cexp(-t *dsp->iw2); // neu
dsp->F2sum += X - X0;
xbit = cabs(dsp->F2sum) - cabs(dsp->F1sum);
@ -746,8 +746,8 @@ int f32buf_sample(dsp_t *dsp, int inv) {
else if (0 && dsp->opt_iq == 4) {
double xbit = 0.0;
//float complex xi = cexp(+I*M_PI*dsp->h/dsp->sps);
double f1 = -dsp->h*dsp->sr/(2*dsp->sps);
double f2 = -f1;
//double f1 = -dsp->h*dsp->sr/(2*dsp->sps);
//double f2 = -f1;
float complex X1 = 0;
float complex X2 = 0;
@ -758,8 +758,8 @@ int f32buf_sample(dsp_t *dsp, int inv) {
n--;
t = -n / (double)dsp->sr;
z = dsp->rot_iqbuf[(dsp->sample_in - n + dsp->N_IQBUF) % dsp->N_IQBUF]; // +1
X1 += z*cexp(-t*2*M_PI*f1*I);
X2 += z*cexp(-t*2*M_PI*f2*I);
X1 += z*cexp(-t*dsp->iw1);
X2 += z*cexp(-t*dsp->iw2);
}
xbit = cabs(X2) - cabs(X1);
@ -1145,7 +1145,7 @@ int init_buffers(dsp_t *dsp) {
int i, pos;
float b0, b1, b2, b, t;
float normMatch;
double sigma = sqrt(log(2)) / (2*M_PI*dsp->BT);
double sigma = sqrt(log(2)) / (_2PI*dsp->BT);
int p2 = 1;
int K, L, M;
@ -1226,7 +1226,7 @@ int init_buffers(dsp_t *dsp) {
if (dsp->ex == NULL) return -1;
for (n = 0; n < dsp->lut_len; n++) {
t = f0*(double)n;
dsp->ex[n] = cexp(t*2*M_PI*I);
dsp->ex[n] = cexp(t*_2PI*I);
}
}
@ -1397,6 +1397,14 @@ int init_buffers(dsp_t *dsp) {
dsp->fm_buffer = (float *)calloc( M+1, sizeof(float)); if (dsp->fm_buffer == NULL) return -1; // dsp->bufs[]
if (dsp->opt_iq)
{
double f1 = -dsp->h*dsp->sr/(2.0*dsp->sps);
double f2 = -f1;
dsp->iw1 = _2PI*I*f1;
dsp->iw2 = _2PI*I*f2;
}
return K;
}
@ -1488,8 +1496,8 @@ int find_header(dsp_t *dsp, float thres, int hdmax, int bitofs, int opt_dc) {
double diffDf = dsp->dDf*0.6; //0.4
if (1 && dsp->opt_iq >= 2) {
// update rot_iqbuf, F1sum, F2sum
double f1 = -dsp->h*dsp->sr/(2*dsp->sps);
double f2 = -f1;
//double f1 = -dsp->h*dsp->sr/(2*dsp->sps);
//double f2 = -f1;
float complex X1 = 0;
float complex X2 = 0;
float complex _z = 0;
@ -1498,12 +1506,12 @@ int find_header(dsp_t *dsp, float thres, int hdmax, int bitofs, int opt_dc) {
{
// update rot_iqbuf
double _tn = (dsp->sample_in - _n) / (double)dsp->sr;
dsp->rot_iqbuf[(dsp->sample_in - _n + dsp->N_IQBUF) % dsp->N_IQBUF] *= cexp(-_tn*2*M_PI*diffDf*I);
dsp->rot_iqbuf[(dsp->sample_in - _n + dsp->N_IQBUF) % dsp->N_IQBUF] *= cexp(-_tn*_2PI*diffDf*I);
//
//update/reset F1sum, F2sum
_z = dsp->rot_iqbuf[(dsp->sample_in - _n + dsp->N_IQBUF) % dsp->N_IQBUF];
X1 += _z*cexp(-_tn*2*M_PI*f1*I);
X2 += _z*cexp(-_tn*2*M_PI*f2*I);
X1 += _z*cexp(-_tn*dsp->iw1);
X2 += _z*cexp(-_tn*dsp->iw2);
_n--;
}
dsp->F1sum = X1;
@ -1549,7 +1557,7 @@ int find_header(dsp_t *dsp, float thres, int hdmax, int bitofs, int opt_dc) {
#else
// external FSK demod: read float32 soft symbols
float read_wav_header(pcm_t *pcm, FILE *fp) {}
int read_wav_header(pcm_t *pcm, FILE *fp) {}
int f32buf_sample(dsp_t *dsp, int inv) {}
int read_slbit(dsp_t *dsp, int *bit, int inv, int ofs, int pos, float l, int spike) {}
int read_softbit(dsp_t *dsp, hsbit_t *shb, int inv, int ofs, int pos, float l, int spike) {}

Wyświetl plik

@ -6,6 +6,8 @@
#ifndef M_PI
#define M_PI (3.1415926535897932384626433832795)
#endif
#define _2PI (6.2831853071795864769252867665590)
#define LP_IQ 1
#define LP_FM 2
@ -83,6 +85,10 @@ typedef struct {
float complex *rot_iqbuf;
float complex F1sum;
float complex F2sum;
//
double complex iw1;
double complex iw2;
//
char *rawbits;
@ -169,7 +175,7 @@ typedef struct {
} hdb_t;
float read_wav_header(pcm_t *, FILE *);
int read_wav_header(pcm_t *, FILE *);
int f32buf_sample(dsp_t *, int);
int read_slbit(dsp_t *, int*, int, int, int, float, int);
int read_softbit(dsp_t *, hsbit_t *, int, int, int, float, int);