Changeset 2390

Show
Ignore:
Timestamp:
12/19/06 21:06:37 (6 years ago)
Author:
jgaeddert
Message:

adding lock detector

Location:
components/CostasLoopBPSK/trunk/CostasLoopBPSK
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • components/CostasLoopBPSK/trunk/CostasLoopBPSK/CostasLoopBPSK.cpp

    r2228 r2390  
    3535 
    3636#undef VERBOSE 
    37 #define LOGGING 
     37#undef LOGGING 
     38#define LOCK_DETECTOR 
    3839#define PI 3.1415926536 
     40 
     41#ifdef LOGGING 
     42#define LOG_SIZE_MAX 10000 
     43#endif 
    3944 
    4045CostasLoopBPSK_i::CostasLoopBPSK_i(const char *uuid, omni_condition *condition) : Resource_impl(uuid), component_running(condition)  
     
    4247    dataIn = new standardInterfaces_i::complexShort_p("IF_in"); 
    4348    dataOut = new standardInterfaces_i::complexShort_u("baseband_out"); 
     49 
     50    // initialize algorithm variables 
     51    e_i = 10.0f; 
     52    e_q = 100.0f; 
     53    zeta_lock = 0.0025f; 
     54    lock = false; 
     55    lock_detect_threshold = 1.5f; 
    4456 
    4557    //Create the thread for the writer's processing function  
     
    174186 
    175187    float alpha, beta, xi, k1, Ac, BT; 
    176     Ac = 100.0f; 
     188    Ac = 15000.0f; 
    177189 
    178190    // define loop filter 
     
    184196    alpha = 2*xi*beta; 
    185197 
    186     float tmp2(0.0f), q_hat(0.0f), q_prime(0.0f), wcTs(1.57f); 
     198    float tmp2(0.0f), q_hat(0.0f), q_prime(0.0f), wcTs(0.0f), cv(0.0f); 
    187199 
    188200#ifdef LOGGING 
     
    201213    std::ofstream output_log; 
    202214    output_log.open("output_log.dat"); 
     215 
     216#ifdef LOCK_DETECTOR 
     217    std::ofstream lock_detect_log; 
     218    lock_detect_log.open("lock_detect_log.dat"); 
     219#endif 
     220 
     221    int log_size_counter(0); 
    203222#endif 
    204223 
     
    213232        input_data_length = I_in->length(); 
    214233 
     234        mem->lock_counter = 0; 
     235 
    215236        for (i=0; i<input_data_length; i++) 
    216237        { 
    217238             
    218 #ifdef VERBOSE 
    219             std::cout << "  " << (*I_in)[i] << "      " << (*Q_in)[i] << std::endl; 
    220 #endif 
    221  
    222239            //phase detection 
    223240            // TODO: perform complex mixer without using floats 
     
    235252#endif 
    236253 
     254#ifdef LOCK_DETECTOR 
     255            mem->e_i = (1-mem->zeta_lock)*(mem->e_i) +  
     256                          (mem->zeta_lock)*float( abs( I_out[i] ) ); 
     257            mem->e_q = (1-mem->zeta_lock)*(mem->e_q) +  
     258                          (mem->zeta_lock)*float( abs( Q_out[i] ) ); 
     259            mem->lock_detect = mem->e_i / mem->e_q; 
     260//            std::cout << ":: e_i = " << mem->e_i << std::endl; 
     261//            std::cout << ":: e_q = " << mem->e_q << std::endl; 
     262//            std::cout << ":: lock_detect = " << mem->lock_detect << std::endl; 
     263            if ( mem->lock_detect > mem->lock_detect_threshold ) 
     264            { 
     265                mem->lock = true; 
     266                mem->lock_counter++; 
     267            } 
     268//            std::cout << ":: lock_counter = " << mem->lock_counter << std::endl; 
     269#endif 
     270 
    237271            q_prime = pd2*beta + tmp2; 
    238272            q_hat = alpha*pd2 + q_prime; 
    239273            tmp2 = q_prime; 
    240             nco_control = nco_control + wcTs + q_hat; 
     274            cv = wcTs + q_hat; 
     275 
     276            if (cv > PI/2 ) 
     277                cv = PI/2; 
     278            else if ( cv < -PI/2 ) 
     279                cv = -PI/2; 
     280            else; 
     281 
     282            nco_control = nco_control + cv; 
    241283 
    242284            if ( nco_control > 2*PI ) 
     
    251293 
    252294#ifdef LOGGING 
    253             input_log       << (*I_in)[i] << "  " << (*Q_in)[i] << std::endl; 
    254             pd2_log         << pd2 << std::endl; 
    255             nco_control_log << nco_control << std::endl; 
    256             nco_log         << nco_i << "  " << nco_q << std::endl; 
    257             output_log      << I_out[i] << "  " << Q_out[i] << std::endl; 
     295            if (log_size_counter < LOG_SIZE_MAX ) 
     296            { 
     297                input_log       << (*I_in)[i] << "  " << (*Q_in)[i] << std::endl; 
     298                pd2_log         << pd2 << std::endl; 
     299                nco_control_log << nco_control << std::endl; 
     300                nco_log         << nco_i << "  " << nco_q << std::endl; 
     301                output_log      << I_out[i] << "  " << Q_out[i] << std::endl; 
     302#ifdef LOCK_DETECTOR 
     303                lock_detect_log << mem->e_i << "  " << mem->e_q << std::endl; 
     304#endif 
     305            } 
     306            log_size_counter++; 
    258307#endif 
    259308        } 
     
    261310        mem->dataIn->bufferEmptied(); 
    262311        mem->dataOut->pushPacket(I_out, Q_out); 
     312 
     313#ifdef VERBOSE 
     314#ifdef LOCK_DETECTOR 
     315        std::cout << "CostasLoopBPSK: locked on " << mem->lock_counter << " / " 
     316                  << input_data_length << " samples" << std::endl; 
     317#endif 
     318#endif 
     319 
    263320    } 
    264321#ifdef LOGGING 
     
    268325    nco_log.close(); 
    269326    output_log.close(); 
    270 #endif 
    271  
    272 } 
    273  
    274      
     327#ifdef LOCK_DETECTOR 
     328    lock_detect_log.close(); 
     329#endif 
     330#endif 
     331 
     332} 
     333 
     334     
  • components/CostasLoopBPSK/trunk/CostasLoopBPSK/CostasLoopBPSK.h

    r2228 r2390  
    8989 
    9090        // --- algorithm variables --- 
     91 
     92        // lock detection varaiables 
     93        float e_i; 
     94        float e_q; 
     95        bool lock; 
     96        int lock_counter; 
     97        float lock_detect; 
     98        float lock_detect_threshold; 
     99        float zeta_lock; 
    91100         
    92101}; 
  • components/CostasLoopBPSK/trunk/CostasLoopBPSK/plot_results.m

    r2228 r2390  
    77load nco_control_log.dat; 
    88load nco_log.dat; 
    9 load pd_log.dat; 
    109load pd2_log.dat; 
    1110load baseband.txt; 
     
    3736); 
    3837 
    39 figure; 
    40 plot(... 
    41      t(1:N),pd_log(1:N,2),"-;pd-Q;",... 
    42      t(1:N),output_log(1:N,2),"-;Q-out;" 
    43 ); 
    4438 
    4539figure;