Cooperative Communication Simulation with Matlab Source Code

1 Introduction

Cooperative communication simulation

2 Code Section

%multi-hop , main programtic% --------------% Set Parametersnr_of_iterations = 1000;SNR = [-10:1:10];use_direct_link = 1;use_relay = 1;global statistic;statistic = generate_statistic_structure;global signal;signal = generate_signal_structure;signal(1).nr_of_bits = 2^10;signal.modulation_type = 'BPSK';% 'BPSK', 'QPSK'calculate_signal_parameter;channel = generate_channel_structure;channel(1).attenuation(1).pattern = 'Rayleigh';% 'no','Rayleigh'channel(1).attenuation(1).block_length = 1;channel(2) = channel(1);channel(3) = channel(1);channel(4) = channel(1);channel(5) = channel(1);channel(6) = channel(1);channel(7) = channel(1);channel(8) = channel(1);channel(9) = channel(1);channel(10) = channel(1);channel(11) = channel(1);channel(12) = channel(1);rx = generate_rx_structure;rx(1).combining_type = 'ERC'; %'ERC','FRC','SNRC','ESNRC','MRC'rx(1).sd_weight = 3;  % used for 'FRC'global relay;relay = generate_relay_structure;relay(1).mode = 'DAF'; %'AAF', 'DAF'relay.magic_genie = 0;relay(1).rx(1) = rx(1); % same behaviorchannel(1).attenuation.distance = 1;channel(2).attenuation.distance = 0.5;channel(3).attenuation.distance = 0.5;% ----------------% Start SimulationBER = zeros(size(SNR));for iSNR = 1:size(SNR,2)% returns the size of the dimension of SNR specified by scalar 2disp(['progress: ',int2str(iSNR),'/',int2str(size(SNR,2))])  %  Convert integer to string%%%%%%%%%%%%%%%%%%%%%%channel(1).noise(1).SNR = SNR(iSNR); % iSNR ??????channel(2).noise(1).SNR = SNR(iSNR);channel(3).noise(1).SNR = SNR(iSNR);for it = 1:nr_of_iterations;% --------------% Reset receiver rx = rx_reset(rx);relay.rx = rx_reset(relay.rx);% -----------% Direct linkif (use_direct_link == 1)[channel(1), rx] = add_channel_effect(channel(1), rx,...signal.symbol_sequence);rx = rx_correct_phaseshift(rx, channel(1).attenuation.phi);end% ------------Relay Transmission---------------if (use_relay == 1)  % Use relay cooperation% ----------Only 1 relay---------% Sender to relay[channel(2), relay.rx] = add_channel_effect(channel(2),relay.rx, signal.symbol_sequence);relay = prepare_relay2send(relay,channel(2));% Relay to destination[channel(3), rx] = add_channel_effect(channel(3), rx,relay.signal2send);% [received_symbol,signal.received_bit_sequence]=rx_combine(rx,channel,use_relay);switch relay.mode% Correct phaseshiftcase 'AAF'rx = rx_correct_phaseshift(rx,...channel(3).attenuation.phi + channel(2).attenuation.phi);case 'DAF'rx = rx_correct_phaseshift(rx,channel(3).attenuation.phi);endend% Receiver[received_symbol, signal.received_bit_sequence] = rx_combine(rx, channel(1),channel(3), use_relay);BER(iSNR) = BER(iSNR) + sum(not(signal.received_bit_sequence == signal.bit_sequence));if (BER(iSNR) > 10000)% Stop iteratebreak;endend % Iterationif (BER(iSNR)<100)warning(['Result might not be precise when SNR equal ',num2str(SNR(iSNR))])endBER(iSNR) = BER(iSNR) ./ it ./ signal.nr_of_bits;end% ---------------Present the result of the simulation---------------------txt_distance = [' - distance: ',...num2str(channel(1).attenuation.distance), ':',...num2str(channel(2).attenuation.distance), ':',...num2str(channel(3).attenuation.distance)];%txt_distance='';if (use_relay == 1)if (relay.magic_genie == 1)txt_genie = ' - Magic Genie';elsetxt_genie = '';endtxt_combining = [' - combining: ', rx(1).combining_type];switch rx(1).combining_typecase 'FRC'txt_combining = [txt_combining, ' ',...num2str(rx(1).sd_weight),':1'];% Convert number to stringendadd2statistic(SNR,BER,[signal.modulation_type, '-',relay.mode, txt_combining,',','two-hop'])else switch channel(1).attenuation.patterncase 'no'txt_fading = ' - no fading';otherwisetxt_fading = ' - Rayleigh fading';endadd2statistic(SNR,BER,[signal.modulation_type, '-',relay.mode, txt_combining,',','two-hop'])end%---------------Multi-hop Simulation-----------%channel(1).attenuation.distance = 1;channel(2).attenuation.distance = 1/3;channel(3).attenuation.distance = 1/3;channel(4).attenuation.distance = 1/3;% ----------------% Start SimulationBER = zeros(size(SNR));for iSNR = 1:size(SNR,2)% returns the size of the dimension of SNR specified by scalar 2disp(['progress: ',int2str(iSNR),'/',int2str(size(SNR,2))])  %  Convert integer to string%%%%%%%%%%%%%%%%%%%%%%channel(1).noise(1).SNR = SNR(iSNR); % iSNR ??????channel(2).noise(1).SNR = SNR(iSNR);channel(3).noise(1).SNR = SNR(iSNR);channel(4).noise(1).SNR = SNR(iSNR);for it = 1:nr_of_iterations;% --------------% Reset receiver rx = rx_reset(rx);relay.rx = rx_reset(relay.rx);% -----------% Direct linkif (use_direct_link == 1)[channel(1), rx] = add_channel_effect(channel(1), rx,...signal.symbol_sequence);rx = rx_correct_phaseshift(rx, channel(1).attenuation.phi);end% ----Relay Transmission-----%if (use_relay == 1)% Sender to relay[channel(2), relay.rx] = add_channel_effect(channel(2),relay.rx, signal.symbol_sequence);relay = prepare_relay2send(relay,channel(2));%  ??this function  %relay1 to Relay2[channel(3), relay.rx]=add_channel_effect(channel(3),relay.rx, relay.signal2send);relay=prepare_relay2send(relay,channel(3)); %relay2 to destination[channel(4),rx]=add_channel_effect(channel(4),rx,relay.signal2send);switch relay.mode% Correct phaseshiftcase 'AAF'rx = rx_correct_phaseshift(rx,...channel(2).attenuation.phi + channel(3).attenuation.phi+ channel(4).attenuation.phi);case 'DAF'rx = rx_correct_phaseshift(rx,channel(4).attenuation.phi);endend% Receiver[received_symbol, signal.received_bit_sequence] = rx_combine(rx, channel(1),channel(4), use_relay);BER(iSNR) = BER(iSNR) + sum(not(signal.received_bit_sequence == signal.bit_sequence));if (BER(iSNR) > 10000)% Stop iteratebreak;endend % Iterationif (BER(iSNR)<100)warning(['Result might not be precise when SNR equal ',...num2str(SNR(iSNR))])endBER(iSNR) = BER(iSNR) ./ it ./ signal.nr_of_bits;end% ---------------Present the result of the simulation---------------------txt_distance = [' - distance: ',...num2str(channel(2).attenuation.distance), ':',...num2str(channel(3).attenuation.distance), ':',...num2str(channel(4).attenuation.distance)];%txt_distance='';if (use_relay == 1)if (relay.magic_genie == 1)txt_genie = ' - Magic Genie';elsetxt_genie = '';endtxt_combining = [' - combining: ', rx(1).combining_type];switch rx(1).combining_typecase 'FRC'txt_combining = [txt_combining, ' ',...num2str(rx(1).sd_weight),':1'];% Convert number to stringendadd2statistic(SNR,BER,[signal.modulation_type, '-',relay.mode, txt_combining,',','three-hop'])else switch channel(1).attenuation.patterncase 'no'txt_fading = ' - no fading';otherwisetxt_fading = ' - Rayleigh fading';endadd2statistic(SNR,BER,[signal.modulation_type, '-',relay.mode, txt_combining,',','three-hop'])end% -----------------% % Graphs to compareSNR_linear = 10.^(SNR/10);add2statistic(SNR,ber(SNR_linear,'BPSK', 'Rayleigh'),'BPSK - single link transmiss')% add2statistic(SNR,ber_2_senders(SNR_linear, 'QPSK'),'QPSK - 2 senders')show_statistic;toc

3 Simulation Results

Cooperative Communication Simulation with Matlab Source Code

Cooperative Communication Simulation with Matlab Source Code

4 References

[1] Xian Huiyuan. Research on Wireless Resource Allocation Technology in Multi-User Cooperative Communication Networks [D]. Central South University, 2013.

About the Author: Specializes in intelligent optimization algorithms, neural network prediction, signal processing, cellular automata, image processing, path planning, drones, and various fields of Matlab simulation. Relevant Matlab code issues can be discussed privately.

Some theoretical references are from online literature; if there is any infringement, please contact the author for deletion.

Cooperative Communication Simulation with Matlab Source Code

Leave a Comment