module: ofdm_channel_cost259_model
description: generate a tapped-delay-line model where the amplitudes a's are rayleigh faded distributed with given time-delays and variances by the model (A=0, B=1, C=2)
parameters: int model
inputs: double in_i, double in_q
outputs: double out_i, double out_q
static_variables: Vector vec_a_i, Vector vec_a_q, int k, int i, int num_taps, int m, Vector vec_delays, Vector vec_vars
classes: Rand rand1("gauss"), Rand rand2("gauss"), List list_a_i(), List list_a_q() List list_vars() List list_delays()
        Filter filt_i1("1","1"), Filter filt_i2("1","1"), Filter filt_q1("1","1"), Filter filt_q2("1","1")
init:  
    if (model == 0) //model A
    {
        list_delays.load("delay_Ts_a.dat");
        list_vars.load("model_a_vars.dat");
    }
    else if (model == 1) //model B
    {
        list_delays.load("delay_Ts_b.dat");
        list_vars.load("model_b_vars.dat");
    }
    else if (model == 2) //model C
    {
        list_delays.load("delay_Ts_c.dat");
        list_vars.load("model_c_vars.dat");
    }
    else
    {
            printf("error in 'ofdm_channel_cost259_model' module\n");
            printf("    model != 0, 1 or 2\n");
            printf("    -> in this case, model = %d\n",model);
            exit(1);
    }
    list_vars.reset();
    list_delays.reset();
    num_taps = list_vars.length; 
    vec_vars.set_length(num_taps);
    vec_delays.set_length(num_taps);
    for (i=0; i<num_taps; i++)
    {
        vec_delays.set_elem(i, list_delays.read());
        vec_vars.set_elem(i, list_vars.read());
    }
    k = (int) vec_delays.get_elem(num_taps-1) + 1; 
    vec_a_i.set_length(k);
    vec_a_q.set_length(k);
    m = 0;
    for (i=0; i<k; i++)
    {
        if (i == vec_delays.get_elem(m))
        {
            vec_a_i.set_elem(i, sqrt(vec_vars.get_elem(m)/2.0) * rand1.inp());        
            vec_a_q.set_elem(i, sqrt(vec_vars.get_elem(m)/2.0) * rand2.inp());
            printf("i =%d\n", i);
            m ++;
        }
        else
        {
            vec_a_i.set_elem(i,0);
            vec_a_q.set_elem(i,0);
        }
        list_a_i.inp(vec_a_i.get_elem(i));
        list_a_q.inp(vec_a_q.get_elem(i));
    }
    list_a_i.save("a_i.dat");
    list_a_q.save("a_q.dat");
    filt_i1.set(list_a_i,"1");
    filt_i2.set(list_a_q,"1");
    filt_q1.set(list_a_i,"1");
    filt_q2.set(list_a_q,"1");
code:
    filt_i1.inp(in_i);
    filt_i2.inp(in_q);
    filt_q1.inp(in_q);
    filt_q2.inp(in_i);
    out_i = filt_i1.out - filt_i2.out;
    out_q = filt_q1.out + filt_q2.out;
