正交相位编码MATLAB程序
时间: 2023-11-28 22:05:25 浏览: 104
MATLAB.rar_正交 编码_正交多项式_离散 多项式_离散正交
下面是一个简单的正交相位编码(QPSK)的MATLAB程序:
```matlab
% 设置参数
N = 1000; % 生成的符号数
fc = 100; % 载波频率
fs = 1000; % 采样频率
T = 1/fs; % 采样周期
SNR = 10; % 信噪比
% 生成随机符号序列
symbols = randi([0 3],1,N);
% 进行映射
I = zeros(1,N);
Q = zeros(1,N);
for i = 1:N
if symbols(i) == 0
I(i) = 1;
Q(i) = 1;
elseif symbols(i) == 1
I(i) = -1;
Q(i) = 1;
elseif symbols(i) == 2
I(i) = -1;
Q(i) = -1;
else
I(i) = 1;
Q(i) = -1;
end
end
% 生成基带信号
t = (0:N-1)*T;
baseband = I.*cos(2*pi*fc*t) - Q.*sin(2*pi*fc*t);
% 添加高斯白噪声
power = mean(abs(baseband).^2);
noise_power = power/(10^(SNR/10));
noise = sqrt(noise_power)*randn(1,N);
received = baseband + noise;
% 解调
demod_I = received .* cos(2*pi*fc*t);
demod_Q = -received .* sin(2*pi*fc*t);
% 低通滤波
[b,a] = butter(4,2*fc/fs);
filtered_I = filter(b,a,demod_I);
filtered_Q = filter(b,a,demod_Q);
% 判决
demod_symbols = zeros(1,N);
for i = 1:N
if filtered_I(i) > 0 && filtered_Q(i) > 0
demod_symbols(i) = 0;
elseif filtered_I(i) < 0 && filtered_Q(i) > 0
demod_symbols(i) = 1;
elseif filtered_I(i) < 0 && filtered_Q(i) < 0
demod_symbols(i) = 2;
else
demod_symbols(i) = 3;
end
end
% 计算误码率
errors = sum(demod_symbols ~= symbols);
BER = errors/N;
% 绘制信号图像
subplot(2,1,1);
plot(t,I,'b',t,Q,'r');
xlabel('时间 (s)');
ylabel('幅度');
title('调制信号');
legend('I路','Q路');
subplot(2,1,2);
plot(t,received);
xlabel('时间 (s)');
ylabel('幅度');
title(['接收信号(SNR = ',num2str(SNR),' dB)']);
% 显示误码率
disp(['误码率:',num2str(BER)]);
```
在这个程序中,我们生成了一个长度为N的随机符号序列,然后进行了QPSK调制,把符号映射到I/Q空间中。然后,我们生成了一个基带信号,并添加了高斯白噪声。接着,我们解调了接收信号,并通过低通滤波得到了I/Q分量。最后,我们进行了判决,计算了误码率,并绘制了信号的图像。
阅读全文