【协作通信】基于matlab协作通信仿真【含Matlab源码 1006期】

举报
海神之光 发表于 2022/05/29 03:22:53 2022/05/29
【摘要】 一、获取代码方式 获取代码方式1: 完整代码已上传我的资源:【协作通信】基于matlab协作通信仿真【含Matlab源码 1006期】 获取代码方式2: 通过订阅紫极神光博客付费专栏,凭支付凭证,私信...

一、获取代码方式

获取代码方式1:
完整代码已上传我的资源:【协作通信】基于matlab协作通信仿真【含Matlab源码 1006期】

获取代码方式2:
通过订阅紫极神光博客付费专栏,凭支付凭证,私信博主,可获得此代码。

备注:
订阅紫极神光博客付费专栏,可免费获得1份代码(有效期为订阅日起,三天内有效);

二、部分源代码

%multi-hop ,主程序
tic
% --------------
% Set Parameters
nr_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 beahaviour

channel(1).attenuation.distance = 1;
channel(2).attenuation.distance = 0.5;
channel(3).attenuation.distance = 0.5;
% ----------------
% Start Simulation
BER = zeros(size(SNR));
for iSNR = 1:size(SNR,2)% returns the size of the dimension of SNR  specified by scalar 2

disp(['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 link
if (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

% ------------中继传输 ---------------
if (use_relay == 1)  % 采用中继协作
% ----------只有1个中继 ---------
% 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 phaseshift
case '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);
end
end
% 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 iterate
break;
end
end % Iteration
if (BER(iSNR)<100)
warning(['Result might not be precise when SNR equal ',num2str(SNR(iSNR))])
end
BER(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';
else
txt_genie = '';
end
txt_combining = [' - combining: ', rx(1).combining_type];
switch rx(1).combining_type
case 'FRC'
txt_combining = [txt_combining, ' ',...
num2str(rx(1).sd_weight),':1'];% Convert number to string
end
add2statistic(SNR,BER,[signal.modulation_type, '-',relay.mode, txt_combining,',','two-hop'])
else
switch channel(1).attenuation.pattern
case 'no'
txt_fading = ' - no fading';
otherwise
txt_fading = ' - Rayleigh fading';
end
add2statistic(SNR,BER,[signal.modulation_type, '-',relay.mode, txt_combining,',','two-hop'])
end
%---------------多跳仿真-----------%
channel(1).attenuation.distance = 1;
channel(2).attenuation.distance = 1/3;
channel(3).attenuation.distance = 1/3;
channel(4).attenuation.distance = 1/3;
% ----------------
% Start Simulation
BER = zeros(size(SNR));
for iSNR = 1:size(SNR,2)% returns the size of the dimension of SNR  specified by scalar 2
disp(['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 link
if (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

% ----中继传输-----%
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 phaseshift
case '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);
end
end
% 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 iterate
break;
end
end % Iteration
if (BER(iSNR)<100)
warning(['Result might not be precise when SNR equal ',...
num2str(SNR(iSNR))])
end
BER(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';
else
txt_genie = '';
end
txt_combining = [' - combining: ', rx(1).combining_type];



  
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177
  • 178
  • 179
  • 180
  • 181
  • 182
  • 183
  • 184
  • 185
  • 186
  • 187
  • 188
  • 189
  • 190
  • 191
  • 192
  • 193
  • 194
  • 195
  • 196
  • 197
  • 198
  • 199
  • 200
  • 201
  • 202
  • 203

三、运行结果

在这里插入图片描述
在这里插入图片描述

四、matlab版本及参考文献

1 matlab版本
2014a

2 参考文献
[1] 沈再阳.精通MATLAB信号处理[M].清华大学出版社,2015.
[2]高宝建,彭进业,王琳,潘建寿.信号与系统——使用MATLAB分析与实现[M].清华大学出版社,2020.
[3]王文光,魏少明,任欣.信号处理与系统分析的MATLAB实现[M].电子工业出版社,2018.

文章来源: qq912100926.blog.csdn.net,作者:海神之光,版权归原作者所有,如需转载,请联系作者。

原文链接:qq912100926.blog.csdn.net/article/details/117922038

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。