Exemple #1
0
void make_tone_gen_descriptor(tone_gen_descriptor_t *s,
                              int f1,
                              int l1,
                              int f2,
                              int l2,
                              int d1,
                              int d2,
                              int d3,
                              int d4,
                              int repeat)
{
    memset(s, 0, sizeof(*s));
    if (f1 >= 1)
    {
        s->phase_rate[0] = dds_phase_ratef((float) f1);
        s->gain[0] = dds_scaling_dbm0f((float) l1);
    }
    s->modulate = (f2 < 0);
    if (f2)
    {
        s->phase_rate[1] = dds_phase_ratef((float) abs(f2));
        s->gain[1] = (s->modulate)  ?  (float) l2/100.0f  :  dds_scaling_dbm0f((float) l2);
    }

    s->duration[0] = d1*8;
    s->duration[1] = d2*8;
    s->duration[2] = d3*8;
    s->duration[3] = d4*8;

    s->repeat = repeat;
}
Exemple #2
0
void make_tone_gen_descriptor(tone_gen_descriptor_t *s,
                              int f1,
                              int l1,
                              int f2,
                              int l2,
                              int d1,
                              int d2,
                              int d3,
                              int d4,
                              int repeat)
{
    memset(s, 0, sizeof(*s));
    if (f1)
    {
        s->tone[0].phase_rate = dds_phase_ratef((float) f1);
        if (f2 < 0)
            s->tone[0].phase_rate = -s->tone[0].phase_rate;
        s->tone[0].gain = dds_scaling_dbm0f((float) l1);
    }
    if (f2)
    {
        s->tone[1].phase_rate = dds_phase_ratef((float) abs(f2));
        s->tone[1].gain = (f2 < 0)  ?  (float) l2/100.0f  :  dds_scaling_dbm0f((float) l2);
    }

    s->duration[0] = d1*SAMPLE_RATE/1000;
    s->duration[1] = d2*SAMPLE_RATE/1000;
    s->duration[2] = d3*SAMPLE_RATE/1000;
    s->duration[3] = d4*SAMPLE_RATE/1000;

    s->repeat = repeat;
}
Exemple #3
0
SPAN_DECLARE(tone_gen_descriptor_t *) tone_gen_descriptor_init(tone_gen_descriptor_t *s,
        int f1,
        int l1,
        int f2,
        int l2,
        int d1,
        int d2,
        int d3,
        int d4,
        int repeat)
{
    if (s == NULL)
    {
        if ((s = (tone_gen_descriptor_t *) span_alloc(sizeof(*s))) == NULL)
        {
            return NULL;
        }
    }
    memset(s, 0, sizeof(*s));

    if (f1)
    {
#if defined(SPANDSP_USE_FIXED_POINT)
        s->tone[0].phase_rate = dds_phase_rate((float) f1);
        if (f2 < 0)
            s->tone[0].phase_rate = -s->tone[0].phase_rate;
        s->tone[0].gain = dds_scaling_dbm0((float) l1);
#else
        s->tone[0].phase_rate = dds_phase_ratef((float) f1);
        if (f2 < 0)
            s->tone[0].phase_rate = -s->tone[0].phase_rate;
        s->tone[0].gain = dds_scaling_dbm0f((float) l1);
#endif
    }
    if (f2)
    {
#if defined(SPANDSP_USE_FIXED_POINT)
        s->tone[1].phase_rate = dds_phase_rate((float) abs(f2));
        s->tone[1].gain = (f2 < 0)  ?  (float) 32767.0f*l2/100.0f  :  dds_scaling_dbm0((float) l2);
#else
        s->tone[1].phase_rate = dds_phase_ratef((float) abs(f2));
        s->tone[1].gain = (f2 < 0)  ?  (float) l2/100.0f  :  dds_scaling_dbm0f((float) l2);
#endif
    }

    s->duration[0] = d1*SAMPLE_RATE/1000;
    s->duration[1] = d2*SAMPLE_RATE/1000;
    s->duration[2] = d3*SAMPLE_RATE/1000;
    s->duration[3] = d4*SAMPLE_RATE/1000;

    s->repeat = repeat;

    return s;
}
Exemple #4
0
super_tone_tx_step_t *super_tone_tx_make_step(super_tone_tx_step_t *s,
        float f1,
        float l1,
        float f2,
        float l2,
        int length,
        int cycles)
{
    if (s == NULL)
    {
        s = (super_tone_tx_step_t *) malloc(sizeof(super_tone_tx_step_t));
        if (s == NULL)
            return NULL;
    }
    if (f1 >= 1.0)
    {
        s->phase_rate[0] = dds_phase_ratef(f1);
        s->gain[0] = dds_scaling_dbm0f(l1);
    }
    else
    {
        s->phase_rate[0] = 0;
        s->gain[0] = 0;
    }
    if (f2 >= 1.0)
    {
        s->phase_rate[1] = dds_phase_ratef(f2);
        s->gain[1] = dds_scaling_dbm0f(l2);
    }
    else
    {
        s->phase_rate[1] = 0;
        s->gain[1] = 0;
    }
    s->tone = (f1 > 0.0);
    s->length = length*8;
    s->cycles = cycles;
    s->next = NULL;
    s->nest = NULL;
    return  s;
}
Exemple #5
0
SPAN_DECLARE(void) dtmf_tx_set_level(dtmf_tx_state_t *s, int level, int twist)
{
    s->low_level = dds_scaling_dbm0f((float) level);
    s->high_level = dds_scaling_dbm0f((float) (level + twist));
}
static int periodogram_tests(void)
{
    int i;
    int j;
    int k;
    int len;
    complexf_t coeffs[PG_WINDOW/2];
    complexf_t camp[BLOCK_LEN];
    complexf_t last_result;
    complexf_t result;
    complexf_t phase_offset;
    float freq_error;
    float pg_scale;
    float level;
    float scale1;
    float scale2;
    int32_t phase_rate1;
    int32_t phase_rate2;
    uint32_t phase_acc1;
    uint32_t phase_acc2;
    awgn_state_t noise_source_re;
    awgn_state_t noise_source_im;

    phase_rate1 = DEC_RATIO*dds_phase_ratef(FREQ1 - 5.0f);
    phase_rate2 = DEC_RATIO*dds_phase_ratef(FREQ2);
    phase_acc1 = 0;
    phase_acc2 = 0;
    len = periodogram_generate_coeffs(coeffs, FREQ1, DEC_SAMPLE_RATE, PG_WINDOW);
    if (len != PG_WINDOW/2)
    {
        printf("Test failed\n");
        return -1;
    }
    pg_scale = periodogram_generate_phase_offset(&phase_offset, FREQ1, DEC_SAMPLE_RATE, PG_WINDOW);
    scale1 = dds_scaling_dbm0f(-6.0f);
    scale2 = dds_scaling_dbm0f(-6.0f);

    for (k = -50;  k < 0;  k++)
    {
        printf("Setting noise to %ddBm0\n", k);
        awgn_init_dbm0(&noise_source_re, 1234567, (float) k);
        awgn_init_dbm0(&noise_source_im, 7654321, (float) k);
        last_result = complex_setf(0.0f, 0.0f);
        for (i = 0;  i < 100;  i++)
        {
            for (j = 0;  j < PG_WINDOW;  j++)
            {
                result = dds_complexf(&phase_acc1, phase_rate1);
                camp[j].re = result.re*scale1;
                camp[j].im = result.im*scale1;
                result = dds_complexf(&phase_acc2, phase_rate2);
                camp[j].re += result.re*scale2;
                camp[j].im += result.im*scale2;
                camp[j].re += awgn(&noise_source_re);
                camp[j].im += awgn(&noise_source_im);
            }
            result = periodogram(coeffs, camp, PG_WINDOW);
            level = sqrtf(result.re*result.re + result.im*result.im);
            freq_error = periodogram_freq_error(&phase_offset, pg_scale, &last_result, &result);
            last_result = result;
            if (i == 0)
                continue;

            printf("Signal level = %.5f, freq error = %.5f\n", level, freq_error);
            if (level < scale1*0.8f  ||  level > scale1*1.2f)
            {
                printf("Test failed - %ddBm0 of noise, signal is %f (%f)\n", k, level, scale1);
                return -1;
            }
            if (freq_error < -10.0f  ||  freq_error > 10.0f)
            {
                printf("Test failed - %ddBm0 of noise, %fHz error\n", k, freq_error);
                return -1;
            }
        }
    }
    return 0;
}