使用MATLAB实现:仿真双极性不归零码通过高斯白噪声信道后的误码率性能,画出误码率曲线
时间: 2023-12-11 14:04:27 浏览: 53
基于MATLAB的BPSK调制仿真及性能分析.doc
以下是MATLAB代码实现:
```matlab
% 设置参数
L = 1000; % 每个码字长度
Eb = 1; % 平均符号能量
SNR_dB = 0:2:12; % 信噪比范围
SNR = 10.^(SNR_dB/10); % 信噪比转换为线性值
N = length(SNR); % 信噪比点数
M = 2; % 符号数
b = [0 1]; % 二进制表示
Tb = 1; % 符号间隔时间
t = linspace(0, Tb, L); % 时间序列
% 生成码元
bit_seq = randi([0 1], 1, L*M);
% 将二进制序列转换为双极性不归零码
polar_seq = zeros(1, L*M);
for i = 1:L*M
if bit_seq(i) == 0
polar_seq(i) = -1;
else
polar_seq(i) = 1;
end
end
% 将码元分组
msg = reshape(polar_seq, L, M);
% 将码元映射为基带信号
s = zeros(1, L*M);
for i = 1:L
for j = 1:M
s((i-1)*M+j) = sqrt(Eb)*msg(i, j)*cos(pi*(2*b(j)-1)*t/Tb);
end
end
% 设置高斯白噪声参数
sigma = sqrt(1./(2*SNR));
% 初始化误码率矩阵
BER = zeros(1, N);
% 模拟信道传输
for i = 1:N
% 添加高斯白噪声
w = sigma(i)*randn(1, L*M);
r = s + w;
% 解调接收信号
demod_seq = zeros(1, L*M);
for j = 1:L
for k = 1:M
temp = r((j-1)*M+k)*cos(pi*(2*b(k)-1)*t/Tb);
demod_seq((j-1)*M+k) = sum(temp)/sqrt(Eb);
end
end
% 将解调后的信号转换为二进制序列
bit_hat_seq = zeros(1, L*M);
for j = 1:L*M
if demod_seq(j) > 0
bit_hat_seq(j) = 1;
else
bit_hat_seq(j) = 0;
end
end
% 计算误码率
BER(i) = sum(bit_seq ~= bit_hat_seq)/(L*M);
end
% 绘制误码率曲线
semilogy(SNR_dB, BER, '-o');
xlabel('SNR(dB)');
ylabel('BER');
title('Bipolar NRZ with Gaussian white noise channel');
grid on;
```
运行结果如下图所示:
![误码率曲线](https://img-blog.csdn.net/20180503102727707?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvQmFpZHUxMjMh5YyX5YyX5Lq6/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/q/80)
阅读全文