嗯,你把具体的需求嗯写到记事本发给我
【相关推荐】
1.仿真符号数会影响图像
如果符号数少,会导致图像下部出现失真(将代码中符号数改为1000000即可看出差别)。
第二种方法(以matlab文档为基础)
代码:
frmLen = 100; % 数据长度
numPackets = 1000; % 个数
EbNo = 0:2:20; % 信噪比
N = 2; % 最大发射天线数
M = 2; % 最大接收天线数
% BPSK
P = 2;
hMod = comm.BPSKModulator;
hDemod = comm.BPSKDemodulator('OutputDataType','double');
% 利用alzmouti方法
hAlamoutiEnc = comm.OSTBCEncoder;
hAlamoutiDec = comm.OSTBCCombiner;
hAWGN1Rx = comm.AWGNChannel('NoiseMethod', 'Signal to noise ratio (Eb/No)',...
'SignalPower', 1);
hAWGN2Rx = clone(hAWGN1Rx);
% 误码率计算
hErrorCalc1 = comm.ErrorRate;
hErrorCalc2 = comm.ErrorRate;
hErrorCalc3 = comm.ErrorRate;
% 为提高速度预置
H = zeros(frmLen, N, M);
ber_noDiver = zeros(3,length(EbNo));
ber_Alamouti = zeros(3,length(EbNo));
ber_MaxRatio = zeros(3,length(EbNo));
grid on;
hold on;
ax = gca;
ax.YScale = 'log';
xlim([EbNo(1), EbNo(end)]);
ylim([1e-4 1]);
xlabel('Eb/No (dB)');
ylabel('BER');
title('1x1,1x2,1x3');
for idx = 1:length(EbNo)
reset(hErrorCalc1);
reset(hErrorCalc2);
reset(hErrorCalc3);
hAWGN1Rx.EbNo = EbNo(idx);
hAWGN2Rx.EbNo = EbNo(idx);
for packetIdx = 1:numPackets
% 生成每一帧的数据
data = randi([0 P-1], frmLen, 1);
% 调制数据
modData = step(hMod, data);
% Alamouti空时编码
encData = step(hAlamoutiEnc, modData);
%为发射天线和接收天线构造瑞利衰落响应矩阵
H(1:N:end, :, :) = (randn(frmLen/2, N, M) + ...
1i*randn(frmLen/2, N, M))/sqrt(2);
% 假设保持两个符号周期不变
H(2:N:end, :, :) = H(1:N:end, :, :);
% H代表1x1, 2x1, 1x2信道
H11 = H(:,1,1);
H21 = H(:,:,1)/sqrt(2);
H12 = squeeze(H(:,1,:));
% 经过信道传输
chanOut11 = H11 .* modData;
chanOut21 = sum(H21.* encData, 2);
chanOut12 = H12 .* repmat(modData, 1, 2);
% 添加AWGN(加性高斯白噪声信道)影响
rxSig11 = step(hAWGN1Rx, chanOut11);
rxSig21 = step(hAWGN1Rx, chanOut21);
rxSig12 = step(hAWGN2Rx, chanOut12);
% Alamouti空时编码合成
decData = step(hAlamoutiDec, rxSig21, H21);
% 最大距离检测
demod11 = step(hDemod, rxSig11.*conj(H11));
demod21 = step(hDemod, decData);
demod12 = step(hDemod, sum(rxSig12.*conj(H12), 2));
ber_noDiver(:,idx) = step(hErrorCalc1, data, demod11);
ber_Alamouti(:,idx) = step(hErrorCalc2, data, demod21);
ber_MaxRatio(:,idx) = step(hErrorCalc3, data, demod12);
end
% 画图
semilogy(EbNo(1:idx), ber_noDiver(1,1:idx), 'r*', ...
EbNo(1:idx), ber_Alamouti(1,1:idx), 'go', ...
EbNo(1:idx), ber_MaxRatio(1,1:idx), 'bs')
legend('1x1', '2x1','1x2');
drawnow;
end
fitBER11 = berfit(EbNo, ber_noDiver(1,:));
fitBER21 = berfit(EbNo, ber_Alamouti(1,:));
fitBER12 = berfit(EbNo, ber_MaxRatio(1,:));
semilogy(EbNo, fitBER11, 'r', EbNo, fitBER21, 'g', EbNo, fitBER12, 'b');
hold off;
结果