matlab编写2psk、qpsk、8psk调制解调的蒙特卡罗仿真,并将误码曲线绘制在同一个图中,并且代码中矩阵维度必须一致,且索引不能超出矩阵维度
时间: 2023-06-10 10:06:54 浏览: 80
8PSK调制解调.rar_8psk matlab_8psk modulation_8psk解调_8psk调制MATLAB_调制与
5星 · 资源好评率100%
以下是一个可能的实现,其中使用了MATLAB内置的函数生成随机比特序列和AWGN噪声。注意代码中的注释,特别是有关索引的部分。
```matlab
% 生成随机比特序列
M = 8; % 调制阶数
N = 100000; % 比特序列长度
bits = randi([0 1], N, 1);
% 将比特序列分组,每组 M 个比特
msg = reshape(bits, [], M);
% 生成调制映射表
map = pskmod(0:M-1, M);
% 将比特序列映射为调制符号
sym = map(bi2de(msg));
% 添加 AWGN 噪声
SNRdB = 10; % 信噪比(dB)
SNR = 10^(SNRdB/10); % 信噪比(线性)
noiseVar = 1/SNR;
noise = sqrt(noiseVar/2)*(randn(size(sym))+1i*randn(size(sym)));
rxSym = sym + noise;
% 解调调制符号并计算误比特率
estBits = de2bi(pskdemod(rxSym, map), M);
numErrs = sum(sum(estBits ~= msg));
ber = numErrs/N/M;
% 绘制误码曲线
SNRdBVec = linspace(-10, 20, 31);
berVec = zeros(size(SNRdBVec));
for ii = 1:length(SNRdBVec)
SNRdB = SNRdBVec(ii);
SNR = 10^(SNRdB/10);
noiseVar = 1/SNR;
noise = sqrt(noiseVar/2)*(randn(size(sym))+1i*randn(size(sym)));
rxSym = sym + noise;
estBits = de2bi(pskdemod(rxSym, map), M);
numErrs = sum(sum(estBits ~= msg));
berVec(ii) = numErrs/N/M;
end
semilogy(SNRdBVec, berVec);
grid on;
xlabel('SNR (dB)');
ylabel('BER');
title('PSK调制解调误码率');
hold on;
% 重复上述步骤,生成并绘制其它调制方案的误码曲线
M = 2;
msg = reshape(bits, [], M);
map = qammod(0:M-1, M);
sym = map(bi2de(msg));
noiseVar = 1/SNR;
noise = sqrt(noiseVar/2)*(randn(size(sym))+1i*randn(size(sym)));
rxSym = sym + noise;
estBits = de2bi(qamdemod(rxSym, map), M);
numErrs = sum(sum(estBits ~= msg));
ber = numErrs/N/M;
berVec = zeros(size(SNRdBVec));
for ii = 1:length(SNRdBVec)
SNRdB = SNRdBVec(ii);
SNR = 10^(SNRdB/10);
noiseVar = 1/SNR;
noise = sqrt(noiseVar/2)*(randn(size(sym))+1i*randn(size(sym)));
rxSym = sym + noise;
estBits = de2bi(qamdemod(rxSym, map), M);
numErrs = sum(sum(estBits ~= msg));
berVec(ii) = numErrs/N/M;
end
semilogy(SNRdBVec, berVec);
legend('8PSK', '2PSK');
M = 4;
msg = reshape(bits, [], M);
map = pskmod(0:M-1, M);
sym = map(bi2de(msg));
noiseVar = 1/SNR;
noise = sqrt(noiseVar/2)*(randn(size(sym))+1i*randn(size(sym)));
rxSym = sym + noise;
estBits = de2bi(pskdemod(rxSym, map), M);
numErrs = sum(sum(estBits ~= msg));
ber = numErrs/N/M;
berVec = zeros(size(SNRdBVec));
for ii = 1:length(SNRdBVec)
SNRdB = SNRdBVec(ii);
SNR = 10^(SNRdB/10);
noiseVar = 1/SNR;
noise = sqrt(noiseVar/2)*(randn(size(sym))+1i*randn(size(sym)));
rxSym = sym + noise;
estBits = de2bi(pskdemod(rxSym, map), M);
numErrs = sum(sum(estBits ~= msg));
berVec(ii) = numErrs/N/M;
end
semilogy(SNRdBVec, berVec);
legend('8PSK', '2PSK', '4PSK');
M = 8;
msg = reshape(bits, [], M);
map = pskmod(0:M-1, M);
sym = map(bi2de(msg));
noiseVar = 1/SNR;
noise = sqrt(noiseVar/2)*(randn(size(sym))+1i*randn(size(sym)));
rxSym = sym + noise;
estBits = de2bi(pskdemod(rxSym, map), M);
numErrs = sum(sum(estBits ~= msg));
ber = numErrs/N/M;
berVec = zeros(size(SNRdBVec));
for ii = 1:length(SNRdBVec)
SNRdB = SNRdBVec(ii);
SNR = 10^(SNRdB/10);
noiseVar = 1/SNR;
noise = sqrt(noiseVar/2)*(randn(size(sym))+1i*randn(size(sym)));
rxSym = sym + noise;
estBits = de2bi(pskdemod(rxSym, map), M);
numErrs = sum(sum(estBits ~= msg));
berVec(ii) = numErrs/N/M;
end
semilogy(SNRdBVec, berVec);
legend('8PSK', '2PSK', '4PSK', '8PSK');
```
阅读全文