Vous êtes sur la page 1sur 7

% Written by Hoang Dinh Ha;Class: 07DT1 ; 20/03/2011 % This program provides BER performance of Digital modulations over % Wireless/wireline

channels close all; clear all; %============ System settings in the simulation============================ M = input('type M: '); %Modulation level of M-ary quadrature amplitude modulation (MQAM), e.g., BPSK -> M=2; QPSK -> M =4; ...... B = log2(M); % number of bits to be conveyed by one MQAM complex symbol N = 1e3; % number of MQAM complex symbols per one transmission burst/frame num_trials = 10; % number of trials, e.g., the number of bursts to be transmitted in the simulation SNR = [0:2:30]; % signal-to-noise ratios (SNRs) are considered in the simulation %------------------------------------------------------------------------sig_power = signal_power_computation(M); % average MQAM symbol energy; ***Please extend to the case of M >2 BER_AWGN = zeros(1,length(SNR)); % contain bit error rate values of the simulation under AWGN channels BER_fading = zeros(1,length(SNR)); BER_noCSI = zeros(1,length(SNR)); for index = 1:length(SNR) No = sig_power/( 10^( SNR(index)/10 ) ); % noise sample variance or noise power for loop = 1:num_trials % Bit generation at transmitter bit_seq = rand(1,B*N) > .5; % uncoded or coded binary bits to be transmitted % Digital modulation [tx_sig] = MQAM_modulator( reshape(bit_seq,B,N) ); % transmitted signal % over AGWN channel (e.g.,wireline channels) noise_samples = sqrt(No/2)*( randn(1,N) + j*randn(1,N) ); % AWGN noise samples rx_sig_AWGN = tx_sig + noise_samples; % received signal over AWGN channels [reco_bit_AWGN] = MQAM_Demodulator_AWGN(rx_sig_AWGN,M); %Bit detection under MQAM modulation %-----------------***Please extend to the case of M >2------------% over fading channels (e.g., wireless channels), assuming perfect channel estimation has % been established by existing techniques, i.e., h is perfectly known at the receiver h = sqrt(1/2)*( randn(1,N) + j*randn(1,N) ); % Generation of Rayleigh fading gains rx_sig_fading = h.*tx_sig + noise_samples; % received signal over fading channels [reco_bit_fading] = MQAM_Demodulator(rx_sig_fading,h,M);% Bit detection under MQAM modulation over wireless channels % Consider the case of wireless channels without channel state

% information (CSI) at receiver, i.e., ignore the presence of fading gains h in the received signal [reco_bit_noCSI] = MQAM_Demodulator_AWGN(rx_sig_fading,M); %Bit detection under MQAM modulation %----*** Please consider the case of multipath fading where channel impluse response is {h_0, h_1} *** % Count the number of error bits occuring BER_AWGN(index) = (BER_AWGN(index) + sum( abs(bit_seq - reco_bit_AWGN) )); BER_fading(index) = (BER_fading(index) + sum( abs(bit_seq - reco_bit_fading) )); BER_noCSI(index) = (BER_noCSI(index) + sum( abs(bit_seq -reco_bit_noCSI) )); end end BER_noCSI = BER_noCSI/(B*N*num_trials) BER_fading = BER_fading/(B*N*num_trials) BER_AWGN = BER_AWGN/(B*N*num_trials) figure(1) semilogy(SNR,BER_noCSI,'k^--','LineWidth',2); hold on; semilogy(SNR,BER_fading,'ro-','LineWidth',2); hold on; semilogy(SNR,BER_AWGN,'s-','LineWidth',2); hold on; xlabel('SNR (dB)'); ylabel('Bit error rate (BER)'); legend( 'Wireless transmission without CSI',... 'Wireless transmission with CSI',... 'Wireline transmission, i.e., AWGN channels'); figure(2) subplot(3,1,1); plot(real(tx_sig),imag(tx_sig),'ro','LineWidth',2); xlim([min(real(rx_sig_fading)) max(real(rx_sig_fading))]); ylim([min(imag(rx_sig_fading)) max(imag(rx_sig_fading))]); legend( 'MQAM constellation at transmitter'); subplot(3,1,2); plot( real(rx_sig_AWGN),imag(rx_sig_AWGN),'o'); xlim([min(real(rx_sig_fading)) max(real(rx_sig_fading))]); ylim([min(imag(rx_sig_fading)) max(imag(rx_sig_fading))]); legend( 'MQAM constellation at receiver over AWGN channels'); subplot(3,1,3); plot( real(rx_sig_fading),imag(rx_sig_fading),'ko'); xlim([min(real(rx_sig_fading)) max(real(rx_sig_fading))]);

ylim([min(imag(rx_sig_fading)) max(imag(rx_sig_fading))]); legend( 'MQAM constellation at receiver over wireless channels');

function [QAM_sym] = MQAM_modulator(bit_tupple); tupple_Len = length(bit_tupple(:,1)); burst_len = length( bit_tupple(1,:) ); %[int_value] = two_bit_to_int(two_bits); for sam =1:burst_len if tupple_Len == 1 QAM_sym(sam) = 2*bit_tupple(1,sam) -1; elseif tupple_Len == 2 QAM_sym(sam) = (2*bit_tupple(1,sam) -1) +j*(2*bit_tupple(2,sam) -1); elseif tupple_Len == 3 QAM_sym(sam) = 2*bit_tupple(1,sam) -1+ j*sign(bit_tupple(2,sam)-0.5)*(2*bit_tupple(3,sam) +3); elseif tupple_Len == 4 QAM_sym(sam) = sign(bit_tupple(1,sam)-0.5)*(-2*bit_tupple(2,sam) +3) +... j*sign(bit_tupple(3,sam)-0.5)*(-2*bit_tupple(4,sam) +3); elseif tupple_Len == 5 QAM_sym(sam) = sign(bit_tupple(1,sam)-0.5)*(-2*bit_tupple(2,sam) +3) +... j*sign(bit_tupple(3,sam)-0.5)*two_bit_to_int(bit_tupple(4:5,sam)); elseif tupple_Len == 6 QAM_sym(sam) = sign(bit_tupple(1,sam)0.5)*two_bit_to_int(bit_tupple(2:3,sam)) +... j*sign(bit_tupple(4,sam)-0.5)*two_bit_to_int(bit_tupple(5:6,sam)); end end

function [recovered_bits] = MQAM_Demodulator(rx_sig,h,M); num_sam = length(rx_sig); switch M case 2 %bits:0 1 s = [-1 1]; for sam =1:num_sam [distance,min_index] = min( abs( rx_sig(sam) - h(sam)*s ).^2 ); recovered_bits(sam) = min_index-1; end case 4 %bits:00 10 01 11 s = mang(M); %s = [-1-j 1-j -1+j 1+j]; for sam =1:num_sam [distance,min_index] = min( abs( rx_sig(sam) - h(sam)*s ).^2 ); recovered_bit_temp(1:2,sam) = dec2bin(min_index-1,2); end recovered_bits = reshape(recovered_bit_temp,1,2*num_sam); case 16 %bits:00.00 00.01 00.11 00.10 ..... s = mang(M); for sam =1:num_sam [distance,min_index] = min( abs( rx_sig(sam) - h(sam)*s ).^2 ); recovered_bit_temp(1:4,sam) = dec2bin(min_index-1,4); end recovered_bits = reshape(recovered_bit_temp,1,4*num_sam); case 32 s = mang(M); for sam =1:num_sam [distance,min_index] = min( abs( rx_sig(sam) - h(sam)*s ).^2 ); recovered_bit_temp(1:5,sam) = dec2bin(min_index-1,5); end recovered_bits = reshape(recovered_bit_temp,1,5*num_sam); case 64 %bits:000.000 000.001 000.011 000.010 ..... s = mang(M); for sam =1:num_sam [distance,min_index] = min( abs( rx_sig(sam) - h(sam)*s ).^2 ); recovered_bit_temp(1:6,sam) = dec2bin(min_index-1,6); end recovered_bits = reshape(recovered_bit_temp,1,6*num_sam); end

function [recovered_bits] = MQAM_Demodulator_AWGN(rx_sig,M); num_sam = length(rx_sig); switch M case 2 %bits:0 1 s = [-1 1]; for sam =1:num_sam [distance,min_index] = min( abs( rx_sig(sam) - s ).^2 ); recovered_bits(sam) = min_index-1; end case 4 %bits:00 10 01 11 s = mang(M); for sam =1:num_sam [distance,min_index] = min( abs( rx_sig(sam) - s ).^2 ); recovered_bit_temp(1:2,sam) = dec2bin(min_index-1,2); end recovered_bits = reshape(recovered_bit_temp,1,2*num_sam); case 16 %bits:00.00 00.01 00.11 00.10 ....... s = mang(M); for sam =1:num_sam [distance,min_index] = min( abs( rx_sig(sam) - s ).^2 ); recovered_bit_temp(1:4,sam) = dec2bin(min_index-1,4); end recovered_bits = reshape(recovered_bit_temp,1,4*num_sam); case 32 s = mang(M); for sam =1:num_sam [distance,min_index] = min( abs( rx_sig(sam) - s ).^2 ); recovered_bit_temp(1:5,sam) = dec2bin(min_index-1,5); end recovered_bits = reshape(recovered_bit_temp,1,5*num_sam); case 64 %bits:000.000 000.001 00.011 00.010 ....... s = mang(M); for sam =1:num_sam [distance,min_index] = min( abs( rx_sig(sam) - s ).^2 ); recovered_bit_temp(1:6,sam) = dec2bin(min_index-1,6); end recovered_bits = reshape(recovered_bit_temp,1,6*num_sam); end

function [sig_power] = signal_power_computation(M) switch M

case 2 sig_power = 1; case 4 sig_power = 2; case 16 sig_power = 4; case 32 sig_power= 5; case 64 sig_power = 6; end function [s]=mang(M); switch M case 2 m=2; n=1; case 4 m=2; n=2; case 16 m=4; n=4; case 32 m=8; n=4; case 64 m=8; n=8; end a=ones(m,n); b=a; temp1=-(m-1); temp2=-(n-1); for t=1:m a(t,:)=-temp1*i; temp1=temp1+2; end for t=1:n b(:,t)=temp2; temp2=temp2+2; end c=(a+b); switch M case 2 s=[c(2,1) c(1,1)]; case 4 s=[c(2,:) c(1,:)];

case 16 b=[c(:,1) c(:,4) c(:,2) c(:,3)]; s=[b(4,:) b(1,:) b(3,:) b(2,:)]; case 32 b=[c(:,1) c(:,4) c(:,2) c(:,3)]; s=[b(8,:) b(1,:) b(5,:) b(4,:) b(7,:) b(2,:) b(6,:) b(3,:)]; case 64 b=[c(:,1) c(:,8) c(:,4) c(:,5) c(:,2) c(:,7) c(:,3) c(:,6)]; s=[b(8,:) b(1,:) b(5,:) b(4,:) b(7,:) b(2,:) b(6,:) b(3,:)]; end end

Vous aimerez peut-être aussi