/*************************************************** Channel Coding Course Work: conolutional codes This program template has given the message generator, BPSK modulation, AWGN channel model and BPSK demodulation, you should first determine the encoder structure, then define the message and codeword length, generate the state table, write the convolutional encoder and decoder. If you have any question, please contact me via e-mail: lixh98@mail2.sysu.edu.cn, or, yangzhj59@mail2.sysu.edu.cn. ***************************************************/ #define _CRT_SECURE_NO_WARNINGS #include #include #include #include #define message_length ... //the length of message #define codeword_length ... //the length of codeword float code_rate = (float)message_length / (float)codeword_length; // channel coefficient #define pi 3.1415926 double N0, sgm; int state_table[...][...];//state table, the size should be defined yourself int state_num;//the number of the state of encoder structure int message[message_length], codeword[codeword_length];//message and codeword int re_codeword[codeword_length];//the received codeword int de_message[message_length];//the decoding message double tx_symbol[codeword_length][2];//the transmitted symbols double rx_symbol[codeword_length][2];//the received symbols void statetable(); void encoder(); void modulation(); void demodulation(); void channel(); void decoder(); void main() { int i; float SNR, start, finish; long int bit_error, seq, seq_num; double BER; double progress; //generate state table statetable(); //random seed srand((int)time(0)); //input the SNR and frame number printf("\nEnter start SNR: "); scanf("%f", &start); printf("\nEnter finish SNR: "); scanf("%f", &finish); printf("\nPlease input the number of message: "); scanf("%d", &seq_num); for (SNR = start; SNR <= finish; SNR++) { //channel noise N0 = (1.0 / code_rate) / pow(10.0, (float)(SNR) / 10.0); sgm = sqrt(N0 / 2); bit_error = 0; for (seq = 1; seq<=seq_num; seq++) { //generate binary message randomly /**************** Pay attention that message is appended by 0 whose number is equal to the state of encoder structure. ****************/ for (i = 0; i