📄 bpskqpsk_matlat.m
字号:
clear;
N1 = 10^6 % select bit size
rand('state',100); % initialize rand() function
randn('state',200); % initialize randn() function
% BPSK Case1
case1 = rand(1,N1)>0.5; % 0,1阑 阿阿 0.5 犬伏肺 积己
s1 = 2*case1-1; % 0 -> -1, 1 -> 0 函炼
n1 = 1/sqrt(2)*[randn(1,N1) + j*randn(1,N1)]; % white gaussian noise, 0dB variance
Eb_N0 = [-3:10];
for a = 1:length(Eb_N0)
% Noise addition
y1 = s1 + 10^(-Eb_N0(a)/20)*n1; % additive white gaussian noise
% receiver - hard decision decoding
case1Hat = real(y1)>0;
% error啊 抄 term阑 技绢辰促.
E1(a) = size(find([case1- case1Hat]),2);
end
case1ber = E1/N1; % simulated ber
% BPSK Case2
case2 = rand(1,N1)>(1/3); % 0,1阑 阿阿 1/3,2/3 犬伏肺 积己
s2 = 2*case2-1; % 0 -> -1, 1 -> 0 函炼
n2 = 1/sqrt(2)*[randn(1,N1) + j*randn(1,N1)]; % white gaussian noise, 0dB variance
Eb_N0 = [-3:10];
for b = 1:length(Eb_N0)
% Noise addition
y2 = s2 + 10^(-Eb_N0(b)/20)*n2; % additive white gaussian noise
% receiver - hard decision decoding
case2Hat = real(y2)>0;
% error啊 抄 term阑 技绢辰促.
E2(b) = size(find([case2- case2Hat]),2);
end
case2ber = E2/N1; % simulated ber
% QPSK Case1
N2 = 10^5; % symbols 荐
Es_N0 = [-3:20];
case3Hat = zeros(1,N2);
for c = 1:length(Es_N0)
case3 = (2*(rand(1,N2)>0.5)-1) + j*(2*(rand(1,N2)>0.5)-1); % 0.5狼 悼老茄 犬伏肺 0,1 积己
s3 = (1/sqrt(2))*case3; % signal 积己
n3 = 1/sqrt(2)*[randn(1,N2) + j*randn(1,N2)]; % white guassian noise, 0dB variance
y3 = s3 + 10^(-Es_N0(c)/20)*n3; % additive white gaussian noise
% demodulation
y3_re = real(y3); % real part
y3_im = imag(y3); % imaginary part
ipHat(find(y3_re < 0 & y3_im < 0)) = -1 + -1*j; % real, imaginary甫 唱穿绢 demodulation 荐青
ipHat(find(y3_re >= 0 & y3_im > 0)) = 1 + 1*j;
ipHat(find(y3_re < 0 & y3_im >= 0)) = -1 + 1*j;
ipHat(find(y3_re >= 0 & y3_im < 0)) = 1 - 1*j;
% error啊 抄 term阑 技绢辰促
E3(c) = size(find([case3- case3Hat]),2); .
end
case3ber = E3/N2;
% QPSK Case2
case4Hat = zeros(1,N2);
for d = 1:length(Es_N0)
case4 = (2*(rand(1,N2)>1/3)-1) + j*(2*(rand(1,N2)>1/3)-1); % 1/3, 2/3 狼 犬伏肺 0,1 积己
s4 = (1/sqrt(2))*case4; % 俊呈瘤甫 1肺 沥痹拳 窍咯 signal 积己
n4 = 1/sqrt(2)*[randn(1,N2) + j*randn(1,N2)]; % white guassian noise, 0dB variance
y4 = s4 + 10^(-Es_N0(d)/20)*n4; % additive white gaussian noise
% demodulation
y4_re = real(y4); % real part
y4_im = imag(y4); % imaginary part
% 4啊瘤 level肺 盒幅窍咯 demodulation
ipHat(find(y4_re < 0 & y4_im < 0)) = -1 + -1*j;
ipHat(find(y4_re >= 0 & y4_im > 0)) = 1 + 1*j;
ipHat(find(y4_re < 0 & y4_im >= 0)) = -1 + 1*j;
ipHat(find(y4_re >= 0 & y4_im < 0)) = 1 - 1*j;
% error啊 抄 term阑 技绢辰促.
E4(d) = size(find([case4- case4Hat]),2);
end
case4ber = E4/N2;
%plot
close all
figure
semilogy(Eb_N0,case1ber,'s-');
hold on
semilogy(Eb_N0,case2ber,'+-');
hold on
semilogy(Es_N0,case3ber,'o-');
hold on
semilogy(Es_N0,case4ber,'p-');
axis([-3 10 10^-5 0.5])
grid on
legend( 'BPSK case1','BPSK case2','QPSK case1','QPSK case2');
xlabel('Eb/No, dB');
ylabel('Bit Error Rate');
title('Bit error probability curve for BPSK & QPSK modulation');
scatterplot(y1);
grid on
title('Constellation of BPSK case1');
scatterplot(y2);
grid on
title('Constellation of BPSK case2');
scatterplot(y3);
grid on
title('Constellation of QPSK case1');
scatterplot(y4);
grid on
title('Constellation of QPSK case2');
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -