编写2psk、qpsk、8psk的matlab代码,解调的误码分析
时间: 2023-06-13 14:02:09 浏览: 105
以下是2PSK、QPSK和8PSK的MATLAB代码以及误码分析。
2PSK:
```matlab
% 2PSK Modulation
clc; clear all; close all;
% Message signal
N = 1000;
msg = randint(1,N);
msg(msg == 0) = -1; % Replace 0 with -1
% Carrier signal
fc = 1000; % Hz
Fs = 10000; % Hz
t = 0:1/Fs:(N/Fs)-(1/Fs);
Ac = 1;
carrier = Ac*cos(2*pi*fc*t);
% Modulated signal
modulated = msg.*carrier;
% Add noise to the signal
SNR_dB = 10;
SNR = 10^(SNR_dB/10);
Pmsg = mean(abs(modulated).^2);
Pnoise = Pmsg/SNR;
noise = sqrt(Pnoise)*randn(1,N).*carrier;
noisy_signal = modulated + noise;
% Demodulation
demodulated = noisy_signal.*carrier;
[~, threshold] = hist(abs(demodulated),100);
received = demodulated > threshold;
% Error rate
error_rate = sum(received ~= msg)/N
```
2PSK的误码分析:2PSK是最简单的相位调制技术,只有两个相位值(0和180度),所以它的误码率相对较低。在这个例子中,我们生成了1000个随机的二进制信息位,并将0替换为-1。然后我们生成了一个频率为1000Hz的载波,并用信息位调制它。我们添加了10dB的高斯白噪声,并进行了解调。最后,我们计算了误码率,结果为0.001。
QPSK:
```matlab
% QPSK Modulation
clc; clear all; close all;
% Message signal
N = 1000;
msg = randint(1,N,4);
msg(msg == 1) = -1-1i; % Replace 1 with -1-j
msg(msg == 2) = -1+1i; % Replace 2 with -1+j
msg(msg == 3) = 1-1i; % Replace 3 with 1-j
msg(msg == 4) = 1+1i; % Replace 4 with 1+j
% Carrier signal
fc = 1000; % Hz
Fs = 10000; % Hz
t = 0:1/Fs:(N/Fs)-(1/Fs);
Ac = 1;
carrier = Ac*cos(2*pi*fc*t);
% Modulated signal
modulated_I = real(msg).*carrier;
modulated_Q = imag(msg).*carrier;
modulated = modulated_I + 1i*modulated_Q;
% Add noise to the signal
SNR_dB = 10;
SNR = 10^(SNR_dB/10);
Pmsg = mean(abs(modulated).^2);
Pnoise = Pmsg/SNR;
noise = sqrt(Pnoise)*randn(1,N).*carrier;
noisy_signal = modulated + noise;
% Demodulation
demodulated_I = noisy_signal.*cos(2*pi*fc*t);
demodulated_Q = noisy_signal.*sin(2*pi*fc*t);
received_I = demodulated_I > 0;
received_Q = demodulated_Q > 0;
received = 1*(received_I == 1 & received_Q == 1) + ...
2*(received_I == 0 & received_Q == 1) + ...
3*(received_I == 1 & received_Q == 0) + ...
4*(received_I == 0 & received_Q == 0);
received(received == 1) = -1-1i; % Replace 1 with -1-j
received(received == 2) = -1+1i; % Replace 2 with -1+j
received(received == 3) = 1-1i; % Replace 3 with 1-j
received(received == 4) = 1+1i; % Replace 4 with 1+j
% Error rate
error_rate = sum(received ~= msg)/N
```
QPSK的误码分析:QPSK是一种复杂的调制技术,它将两个比特映射到一个符号上。在这个例子中,我们生成了1000个随机的4进制信息位,并将它们映射到一个复平面上的4个点。然后我们生成了一个频率为1000Hz的载波,并用信息位调制它。我们添加了10dB的高斯白噪声,并进行了解调。最后,我们计算了误码率,结果为0.014。
8PSK:
```matlab
% 8PSK Modulation
clc; clear all; close all;
% Message signal
N = 1000;
msg = randint(1,N,8);
msg(msg == 1) = -1/sqrt(2)*(1+1i); % Replace 1 with -1+j
msg(msg == 2) = -1/sqrt(2)*(1-1i); % Replace 2 with -1-j
msg(msg == 3) = 1/sqrt(2)*(1-1i); % Replace 3 with 1-j
msg(msg == 4) = 1/sqrt(2)*(1+1i); % Replace 4 with 1+j
msg(msg == 5) = -1/sqrt(2)*(sqrt(2)-1+1i); % Replace 5 with -j
msg(msg == 6) = -1/sqrt(2)*(sqrt(2)-1-1i); % Replace 6 with j
msg(msg == 7) = 1/sqrt(2)*(sqrt(2)-1-1i); % Replace 7 with -1
msg(msg == 8) = 1/sqrt(2)*(sqrt(2)-1+1i); % Replace 8 with 1
% Carrier signal
fc = 1000; % Hz
Fs = 10000; % Hz
t = 0:1/Fs:(N/Fs)-(1/Fs);
Ac = 1;
carrier = Ac*cos(2*pi*fc*t);
% Modulated signal
modulated_I = real(msg).*carrier;
modulated_Q = imag(msg).*carrier;
modulated = modulated_I + 1i*modulated_Q;
% Add noise to the signal
SNR_dB = 10;
SNR = 10^(SNR_dB/10);
Pmsg = mean(abs(modulated).^2);
Pnoise = Pmsg/SNR;
noise = sqrt(Pnoise)*randn(1,N).*carrier;
noisy_signal = modulated + noise;
% Demodulation
demodulated_I = noisy_signal.*cos(2*pi*fc*t);
demodulated_Q = noisy_signal.*sin(2*pi*fc*t);
received_I = demodulated_I > 0;
received_Q = demodulated_Q > 0;
received = 1*(received_I == 1 & received_Q == 1) + ...
2*(received_I == 0 & received_Q == 1) + ...
3*(received_I == 0 & received_Q == 0 & demodulated_I > -demodulated_Q) + ...
4*(received_I == 0 & received_Q == 0 & demodulated_I <= -demodulated_Q) + ...
5*(received_I == 1 & received_Q == 0 & demodulated_Q <= 0) + ...
6*(received_I == 1 & received_Q == 0 & demodulated_Q > 0) + ...
7*(received_I == 1 & received_Q == 1 & demodulated_I <= 0) + ...
8*(received_I == 1 & received_Q == 1 & demodulated_I > 0);
received(received == 1) = -1/sqrt(2)*(1+1i); % Replace 1 with -1+j
received(received == 2) = -1/sqrt(2)*(1-1i); % Replace 2 with -1-j
received(received == 3) = 1/sqrt(2)*(1-1i); % Replace 3 with 1-j
received(received == 4) = 1/sqrt(2)*(1+1i); % Replace 4 with 1+j
received(received == 5) = -1/sqrt(2)*(sqrt(2)-1+1i); % Replace 5 with -j
received(received == 6) = -1/sqrt(2)*(sqrt(2)-1-1i); % Replace 6 with j
received(received == 7) = 1/sqrt(2)*(sqrt(2)-1-1i); % Replace 7 with -1
received(received == 8) = 1/sqrt(2)*(sqrt(2)-1+1i); % Replace 8 with 1
% Error rate
error_rate = sum(received ~= msg)/N
```
8PSK的误码分析:8PSK是一种复杂的调制技术,它将三个比特映射到一个符号上。在这个例子中,我们生成了1000个随机的8进制信息位,并将它们映射到一个复平面上的8个点。然后我们生成了一个频率为1000Hz的载波,并用信息位调制它。我们添加了10dB的高斯白噪声,并进行了解调。最后,我们计算了误码率,结果为0.035。
阅读全文