1.试编写程序,仿真4PAM和4QAM调制信号在高斯信道下的性能,并与理论分析结果相比。(1)画出两条性能曲线,一条是根据理论平均错误概率画出,另一条是仿真曲线;(2)程序的基本流程:信源产生信息比特、调制、将调制信号送入信道(产生高斯白噪声的程序)、接收端检测、将检测结果与信源原始信息比较计算误符号率和误比特率;(3)在给定信噪比下,第二步需多次重复,以得到一个平均错误概率;(4)信噪比范围:4PAM(0dB-14dB),4QAM(0dB-14dB),间隔是1dB;也可在 BER =106左右终止。(5)信噪比计算 SNR =10log( Es /N0)=10log( REb /N0)。注意调制不能直接运用MATLAB内置函数pammod和qammod。注意标注中文注释。注意检测方法使用多进制调制信号软输出检测。注意一定用MATLAB编写。
时间: 2023-12-14 18:38:32 浏览: 100
基于4PAM调制方式的通信系统误码率matlab仿真,含仿真操作录像
5星 · 资源好评率100%
由于题目较长,我将分多个步骤来回答。首先是信源产生信息比特的函数代码:
```matlab
function [data_bits] = source(N)
% 产生随机的 N 比特信息
data_bits = randi([0,1],1,N);
end
```
接下来是4PAM调制的函数代码:
```matlab
function [modulated_symbols] = modulate_4pam(data_bits)
% 将二进制比特转换为4PAM调制符号
L = length(data_bits)/2;
modulated_symbols = zeros(1,L);
% 将二进制比特分成对
for i = 1:L
index = (i-1)*2+1;
bits = data_bits(index:index+1);
% 根据二进制比特计算4PAM符号
if bits(1) == 0 && bits(2) == 0
modulated_symbols(i) = -3;
elseif bits(1) == 0 && bits(2) == 1
modulated_symbols(i) = -1;
elseif bits(1) == 1 && bits(2) == 0
modulated_symbols(i) = 1;
elseif bits(1) == 1 && bits(2) == 1
modulated_symbols(i) = 3;
end
end
end
```
然后是4QAM调制的函数代码:
```matlab
function [modulated_symbols] = modulate_4qam(data_bits)
% 将二进制比特转换为4QAM调制符号
L = length(data_bits)/2;
modulated_symbols = zeros(1,L);
% 将二进制比特分成对
for i = 1:L
index = (i-1)*2+1;
bits = data_bits(index:index+1);
% 根据二进制比特计算4QAM符号
if bits(1) == 0 && bits(2) == 0
modulated_symbols(i) = -1-1i;
elseif bits(1) == 0 && bits(2) == 1
modulated_symbols(i) = -1+1i;
elseif bits(1) == 1 && bits(2) == 0
modulated_symbols(i) = 1-1i;
elseif bits(1) == 1 && bits(2) == 1
modulated_symbols(i) = 1+1i;
end
end
end
```
下一步是添加高斯白噪声的信道函数代码:
```matlab
function [noisy_symbols] = channel(symbols, SNR)
% 添加高斯白噪声
Es = mean(abs(symbols).^2); % 计算信号能量
N0 = Es./(10.^(SNR./10)); % 计算噪声功率谱密度
noise = sqrt(N0/2).*(randn(size(symbols))+1i*randn(size(symbols))); % 生成噪声
noisy_symbols = symbols + noise; % 加噪声
end
```
接着是多进制调制信号软输出检测的函数代码:
```matlab
function [detected_bits] = detect_soft(symbols)
% 多进制调制信号软输出检测
L = length(symbols);
detected_bits = zeros(1,2*L);
for i = 1:L
% 对每个符号进行软输出检测
if real(symbols(i)) < 0
detected_bits((i-1)*2+1) = 0;
detected_bits((i-1)*2+2) = 0;
else
detected_bits((i-1)*2+1) = 1;
detected_bits((i-1)*2+2) = 1;
end
if imag(symbols(i)) < 0
detected_bits((i-1)*2+1) = detected_bits((i-1)*2+1) + 0;
detected_bits((i-1)*2+2) = detected_bits((i-1)*2+2) + 0;
else
detected_bits((i-1)*2+1) = detected_bits((i-1)*2+1) + 1;
detected_bits((i-1)*2+2) = detected_bits((i-1)*2+2) + 1;
end
% 将检测结果转换为二进制比特
if detected_bits((i-1)*2+1) == 0 && detected_bits((i-1)*2+2) == 0
detected_bits((i-1)*2+1) = 0;
detected_bits((i-1)*2+2) = 0;
elseif detected_bits((i-1)*2+1) == 0 && detected_bits((i-1)*2+2) == 1
detected_bits((i-1)*2+1) = 0;
detected_bits((i-1)*2+2) = 1;
elseif detected_bits((i-1)*2+1) == 1 && detected_bits((i-1)*2+2) == 0
detected_bits((i-1)*2+1) = 1;
detected_bits((i-1)*2+2) = 0;
elseif detected_bits((i-1)*2+1) == 1 && detected_bits((i-1)*2+2) == 1
detected_bits((i-1)*2+1) = 1;
detected_bits((i-1)*2+2) = 1;
end
end
end
```
最后是主函数的代码,其中包含了调用以上函数的流程:
```matlab
clc; clear all; close all;
% 参数定义
N = 100000; % 信息比特数
SNR = 0:1:14; % 信噪比范围
M = [4, 16]; % 调制阶数
% 产生随机信息比特
data_bits = source(N);
% 仿真性能曲线
for m = 1:length(M)
fprintf('正在计算 %d-QAM 的性能曲线...\n', M(m));
for i = 1:length(SNR)
% 4PAM调制或4QAM调制
if M(m) == 4
symbols = modulate_4pam(data_bits);
const = [-3 -1 1 3];
else
symbols = modulate_4qam(data_bits);
const = [-3-3i -3-i -3+i -3+3i -1-3i -1-i -1+i -1+3i 1-3i 1-i 1+i 1+3i 3-3i 3-i 3+i 3+3i];
end
% 添加高斯白噪声信道
noisy_symbols = channel(symbols, SNR(i));
% 多进制调制信号软输出检测
detected_bits = detect_soft(noisy_symbols);
% 计算误符号率和误比特率
errors = sum(data_bits ~= detected_bits);
ber_simu(m,i) = errors/N/2;
ser_simu(m,i) = sum(abs(noisy_symbols-const(round(detected_bits/2)+1)).^2 > 4)/N;
end
end
% 理论性能曲线
ber_theory = zeros(size(ber_simu));
ser_theory = zeros(size(ser_simu));
for m = 1:length(M)
fprintf('正在计算 %d-QAM 的理论性能曲线...\n', M(m));
for i = 1:length(SNR)
% 4PAM调制或4QAM调制
if M(m) == 4
Es = mean(abs([-3 -1 1 3]).^2);
else
Es = mean(abs([-3-3i -3-i -3+i -3+3i -1-3i -1-i -1+i -1+3i 1-3i 1-i 1+i 1+3i 3-3i 3-i 3+i 3+3i]).^2);
end
N0 = Es./(10.^(SNR(i)./10));
% 计算误符号率和误比特率
if M(m) == 4
ber_theory(m,i) = qfunc(sqrt(2/5*10.^(SNR(i)./10)));
ser_theory(m,i) = 2*qfunc(sqrt(2/5*10.^(SNR(i)./10)));
else
ber_theory(m,i) = 2*(1-1/sqrt(M(m)))*qfunc(sqrt(3/2*log2(M(m))*10.^(SNR(i)./10)/(M(m)-1)));
ser_theory(m,i) = 1-(1-1/sqrt(M(m)))^2-qfunc(sqrt(3/2*log2(M(m))*10.^(SNR(i)./10)/(M(m)-1)))^2;
end
end
end
% 画图
figure(1);
semilogy(SNR, ber_theory(1,:), 'r-', 'LineWidth', 2);
hold on;
semilogy(SNR, ber_simu(1,:), 'bo');
semilogy(SNR, ber_theory(2,:), 'g-', 'LineWidth', 2);
semilogy(SNR, ber_simu(2,:), 'ms');
hold off;
grid on;
xlabel('SNR (dB)');
ylabel('BER');
legend('4-PAM理论曲线', '4-PAM仿真曲线', '16-QAM理论曲线', '16-QAM仿真曲线');
title('性能曲线比较');
figure(2);
semilogy(SNR, ser_theory(1,:), 'r-', 'LineWidth', 2);
hold on;
semilogy(SNR, ser_simu(1,:), 'bo');
semilogy(SNR, ser_theory(2,:), 'g-', 'LineWidth', 2);
semilogy(SNR, ser_simu(2,:), 'ms');
hold off;
grid on;
xlabel('SNR (dB)');
ylabel('SER');
legend('4-PAM理论曲线', '4-PAM仿真曲线', '16-QAM理论曲线', '16-QAM仿真曲线');
title('性能曲线比较');
```
运行主函数后就可以得到两条性能曲线并进行比较。
阅读全文