Changeset 2390
- Timestamp:
- 12/19/06 21:06:37 (6 years ago)
- Location:
- components/CostasLoopBPSK/trunk/CostasLoopBPSK
- Files:
-
- 3 modified
-
CostasLoopBPSK.cpp (modified) (10 diffs)
-
CostasLoopBPSK.h (modified) (1 diff)
-
plot_results.m (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
components/CostasLoopBPSK/trunk/CostasLoopBPSK/CostasLoopBPSK.cpp
r2228 r2390 35 35 36 36 #undef VERBOSE 37 #define LOGGING 37 #undef LOGGING 38 #define LOCK_DETECTOR 38 39 #define PI 3.1415926536 40 41 #ifdef LOGGING 42 #define LOG_SIZE_MAX 10000 43 #endif 39 44 40 45 CostasLoopBPSK_i::CostasLoopBPSK_i(const char *uuid, omni_condition *condition) : Resource_impl(uuid), component_running(condition) … … 42 47 dataIn = new standardInterfaces_i::complexShort_p("IF_in"); 43 48 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; 44 56 45 57 //Create the thread for the writer's processing function … … 174 186 175 187 float alpha, beta, xi, k1, Ac, BT; 176 Ac = 1 00.0f;188 Ac = 15000.0f; 177 189 178 190 // define loop filter … … 184 196 alpha = 2*xi*beta; 185 197 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); 187 199 188 200 #ifdef LOGGING … … 201 213 std::ofstream output_log; 202 214 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); 203 222 #endif 204 223 … … 213 232 input_data_length = I_in->length(); 214 233 234 mem->lock_counter = 0; 235 215 236 for (i=0; i<input_data_length; i++) 216 237 { 217 238 218 #ifdef VERBOSE219 std::cout << " " << (*I_in)[i] << " " << (*Q_in)[i] << std::endl;220 #endif221 222 239 //phase detection 223 240 // TODO: perform complex mixer without using floats … … 235 252 #endif 236 253 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 237 271 q_prime = pd2*beta + tmp2; 238 272 q_hat = alpha*pd2 + q_prime; 239 273 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; 241 283 242 284 if ( nco_control > 2*PI ) … … 251 293 252 294 #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++; 258 307 #endif 259 308 } … … 261 310 mem->dataIn->bufferEmptied(); 262 311 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 263 320 } 264 321 #ifdef LOGGING … … 268 325 nco_log.close(); 269 326 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 89 89 90 90 // --- 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; 91 100 92 101 }; -
components/CostasLoopBPSK/trunk/CostasLoopBPSK/plot_results.m
r2228 r2390 7 7 load nco_control_log.dat; 8 8 load nco_log.dat; 9 load pd_log.dat;10 9 load pd2_log.dat; 11 10 load baseband.txt; … … 37 36 ); 38 37 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 );44 38 45 39 figure;