Changeset 5742
 Timestamp:
 11/14/07 19:00:38 (8 years ago)
 Location:
 SigProc/branches/SigProcc
 Files:

 3 modified
Legend:
 Unmodified
 Added
 Removed

SigProc/branches/SigProcc/Makefile.am
r5722 r5742 37 37 tests/dot_product_testsuite.h \ 38 38 tests/pack_testsuite.h \ 39 tests/gray_codec_testsuite.h 39 tests/gray_codec_testsuite.h \ 40 tests/modem_energy_scaling_testsuite.h 40 41 # tests/modem_testsuite.h 41 42 
SigProc/branches/SigProcc/src/modem.c
r5741 r5742 30 30 } 31 31 32 void modulator_calculate_levels(modulation_scheme _t *ms, float *ref_i, float *ref_q)33 { 34 switch (ms >scheme) {32 void modulator_calculate_levels(modulation_scheme ms, unsigned int m, float *ref_i, float *ref_q) 33 { 34 switch (ms) { 35 35 36 case PSK: 37 modulator_calculate_levels_psk(ms, ref_i, ref_q); 38 return; 39 case QAM: 40 modulator_calculate_levels_rqam(ms, ref_i, ref_q); 41 return; 42 case PAM: 43 modulator_calculate_levels_pam(ms, ref_i, ref_q); 36 case MOD_PSK: 37 modulator_calculate_levels_psk(ms, m, ref_i, ref_q); 38 break; 39 case MOD_QAM: 40 modulator_calculate_levels_rqam(ms, m, ref_i, ref_q); 41 break; 42 case MOD_PAM: 43 modulator_calculate_levels_pam(ms, m, ref_i, ref_q); 44 break; 44 45 default: 45 46 perror("ERROR: modulator_calculate_levels, unknown/unsupported modulation scheme\n"); 46 return; 47 } 48 } 49 50 void modulator_calculate_levels_psk(modulation_scheme_t *ms, float *ref_i, float *ref_q) 47 break; 48 } 49 modulator_scale_levels(ms, m, ref_i, ref_q); 50 51 } 52 53 void modulator_calculate_levels_psk(modulation_scheme ms, unsigned int m, float *ref_i, float *ref_q) 51 54 { 52 55 unsigned int i; 56 unsigned int M = 1<<m; 53 57 float t; 54 float two_pi_inv_M = 2*M_PI/ ms>M;55 for (i=0; i< ms>M; i++) {58 float two_pi_inv_M = 2*M_PI/M; 59 for (i=0; i<M; i++) { 56 60 t = i*two_pi_inv_M; 57 61 ref_i[i] = cosf(t); … … 60 64 } 61 65 62 void modulator_calculate_levels_pam(modulation_scheme_t *ms, float *ref_i, float *ref_q) 63 { 64 } 65 66 void modulator_calculate_levels_rqam(modulation_scheme_t *ms, float *ref_i, float *ref_q) 67 { 66 void modulator_calculate_levels_pam(modulation_scheme ms, unsigned int m, float *ref_i, float *ref_q) 67 { 68 } 69 70 void modulator_calculate_levels_rqam(modulation_scheme ms, unsigned int m, float *ref_i, float *ref_q) 71 { 72 int M = 1<<m; 68 73 int i, I; 69 74 int q, Q; 70 if ( (ms>m % 2)==0) {75 if ( (m%2)==0 ) { 71 76 // square QAM 72 I = 1<<(m s>m/2);77 I = 1<<(m/2); 73 78 Q = I; 74 79 } else { 75 80 // rectangular QAM 76 I = 1<<((m s>m+1)/2);77 Q = 1<<((m s>m1)/2);78 } 79 assert(I*Q== ms>M);81 I = 1<<((m+1)/2); 82 Q = 1<<((m1)/2); 83 } 84 assert(I*Q==M); 80 85 81 86 unsigned int n=0; … … 89 94 } 90 95 91 float modulator_get_scaling_factor(modulation_scheme_t * ms) 92 { 93 switch (ms>scheme) { 96 float modulator_get_scaling_factor(modulation_scheme _ms, unsigned int _M) 97 { 98 printf("modulator_get_scaling_factor invoked with ms=%d\n", _ms); 99 switch (_ms) { 94 100 95 101 // PSK 96 case PSK:102 case MOD_PSK: 97 103 return PSK_ALPHA; 98 104 99 105 // QAM 100 case QAM:101 switch ( ms>M) {106 case MOD_QAM: 107 switch (_M) { 102 108 case 4: return QAM4_ALPHA; 103 109 //case 8: return RQAM8_ALPHA; … … 108 114 case 256: return QAM256_ALPHA; break; 109 115 default: 110 perror("ERROR! Unsupported QAM level\n");116 perror("ERROR! modulator_get_scaling_factor unsupported QAM level\n"); 111 117 break; 112 118 } … … 114 120 115 121 // PAM 116 case PAM:117 switch ( ms>M) {122 case MOD_PAM: 123 switch (_M) { 118 124 case 4: return PAM4_ALPHA; 119 125 case 8: return PAM8_ALPHA; 120 126 case 16: return PAM16_ALPHA; 121 127 default: 122 perror("ERROR! Unsupported QAM level\n");128 perror("ERROR! modulator_get_scaling_factor, unsupported PAM level\n"); 123 129 break; 124 130 } … … 126 132 127 133 default: 128 perror("ERROR! Unknown/unsupported modulation scheme\n");134 perror("ERROR! modulator_get_scaling_factor, unknown/unsupported modulation scheme\n"); 129 135 break; 130 136 … … 133 139 } 134 140 135 void modulator_scale_levels(modulation_scheme_t *ms, float *ref_i, float *ref_q) 136 { 137 float alpha = modulator_get_scaling_factor(ms); 141 void modulator_scale_levels(modulation_scheme ms, unsigned int m, float *ref_i, float *ref_q) 142 { 143 unsigned int M = 1<<m; 144 float alpha = modulator_get_scaling_factor(ms, M); 145 printf("\nalpha = %f\n", alpha); 138 146 139 147 unsigned int i; 140 for (i=0; i< ms>M; i++) {148 for (i=0; i<M; i++) { 141 149 ref_i[i] *= alpha; 142 150 ref_q[i] *= alpha; … … 148 156 modulator * mod; 149 157 mod = (modulator*) malloc( sizeof(modulator) ); 150 mod>levels_i = ( int*) calloc( _M, sizeof(int) );151 mod>levels_q = ( int*) calloc( _M, sizeof(int) );158 mod>levels_i = (float*) calloc( _M, sizeof(float) ); 159 mod>levels_q = (float*) calloc( _M, sizeof(float) ); 152 160 153 161 return mod; 154 162 } 155 163 156 void modulator_init(modulator *_m, modulation_scheme_t mod, int _e) 157 { 158 164 void free_modulator(modulator * mod) 165 { 166 free(mod>levels_i); 167 free(mod>levels_q); 168 free(mod); 169 } 170 171 void modulator_init(modulator *_m, modulation_scheme mod, unsigned int M, int _e) 172 { 173 if (M<2) { 174 perror("ERROR: modulator_init, modulator must have at least 2 symbols\n"); 175 return; 176 } 177 178 _m>M = M; 179 unsigned int bits_per_symbol=0; 180 while ( !(M & 0x01) ) { 181 M >>= 1; 182 bits_per_symbol++; 183 } 159 184 _m>ms = mod; 185 _m>m = bits_per_symbol; 186 187 modulator_calculate_levels(_m>ms, _m>m, _m>levels_i, _m>levels_q); 188 189 printf("modulator_init creating new scheme:\n"); 190 printf(" m = %d\n", _m>m); 191 printf(" M = %d\n", _m>M); 192 unsigned int i; 193 for (i=0; i<_m>M; i++) 194 printf(" i(%d)=%f; q(%d)=%f;\n", i+1, _m>levels_i[i], i+1, _m>levels_q[i]); 160 195 } 161 196 
SigProc/branches/SigProcc/src/sigprocc.h
r5741 r5742 284 284 // 285 285 // 286 287 /* 288 enum modulation_scheme { 289 UNKNOWN, // Unknown modulation scheme 290 BPSK, QPSK, PSK8, PSK16, PSK32, // Phase shift keying 291 DBPSK, DQPSK, DPSK8, DPSK16, DSPK32, // Differential PSK 292 PAM4, PAM8, PAM16, PAM32, // Pulse amplitude modulation 293 BFSK, FSK4, FSK8, FSK16, // Frequency shift keying 294 QAM4, QAM8, QAM16, QAM32, QAM64, QAM128, QAM256 // Quadrature amplitude modulation 295 }; 296 */ 297 298 struct modulation_scheme { 299 enum mod_scheme { 300 UNKNOWN, 301 PSK, 302 DPSK, 303 PAM, 304 FSK, 305 QAM 306 } scheme; 307 unsigned int m; 308 unsigned int M; 309 }; 310 311 typedef struct modulation_scheme modulation_scheme_t; 286 typedef enum { 287 MOD_UNKNOWN, 288 MOD_PSK, 289 MOD_DPSK, 290 MOD_PAM, 291 MOD_FSK, 292 MOD_QAM 293 } modulation_scheme; 294 295 //typedef struct modulation_scheme modulation_scheme_t; 312 296 313 297 unsigned int gray(unsigned int symbol_in); 314 298 315 void modulator_calculate_levels(modulation_scheme _t*, float*, float*);316 void modulator_calculate_levels_psk(modulation_scheme _t*, float*, float*);317 void modulator_calculate_levels_pam(modulation_scheme _t*, float*, float*);318 void modulator_calculate_levels_rqam(modulation_scheme _t*, float*, float*);319 void modulator_scale_levels(modulation_scheme _t*, float*, float*);320 321 float modulator_get_scaling_factor(modulation_scheme _t*);299 void modulator_calculate_levels(modulation_scheme, unsigned int, float*, float*); 300 void modulator_calculate_levels_psk(modulation_scheme, unsigned int, float*, float*); 301 void modulator_calculate_levels_pam(modulation_scheme, unsigned int, float*, float*); 302 void modulator_calculate_levels_rqam(modulation_scheme, unsigned int, float*, float*); 303 void modulator_scale_levels(modulation_scheme, unsigned int, float*, float*); 304 305 float modulator_get_scaling_factor(modulation_scheme, unsigned int); 322 306 323 307 // PSK … … 348 332 349 333 typedef struct { 350 modulation_scheme_t ms; 334 modulation_scheme ms; 335 unsigned int m; 336 unsigned int M; 351 337 int energy; 352 int * levels_i;353 int * levels_q;354 355 float * ref_i;356 float * ref_q;338 float * levels_i; 339 float * levels_q; 340 341 int state_i; 342 int state_q; 357 343 } modulator; 358 344 359 345 modulator* modulator_create(unsigned int _M); 360 void modulator_init(modulator * _m, modulation_scheme_t mod, int _e); 361 346 void modulator_init(modulator*, modulation_scheme, unsigned int, int); 362 347 void modulate(modulator *_m, short symbol_in, short *I_out, short *Q_out); 363 348 void free_modulator(modulator * _ms);