我想模拟AWGN频道的QPSK,并将得到的误差与绘图上的理论误差进行比较。我想在MATLAB上针对从1到10的不同SNR值执行此操作。绘制此图时,我得到了模拟误差和理论误差之间的巨大差异。我怀疑我可能已经完成了解调部分。我在那里使用了atan函数,但我不确定它是否可以正常运行。你能帮我吗?
M=100000;
snrdB=1:10;
snr=10.^(snrdB/10);
sError = zeros(1,10);%simulated error
tError = zeros(1,10);%theoritical error
for i=1:10
symbols = randi([1,4],1,M);
symbols(symbols == 1) = 1;
symbols(symbols == 2) = 1i;
symbols(symbols == 3) = -1;
symbols(symbols == 4) = -1i;
%calculating total energy
Eb = 0;
for k=1:M
Eb = Eb + abs(symbols(k).^2);
end
Eb = Eb/2;
var = abs(sqrt(Eb/(2*snr(i))));%variance
noise = var*rand(1,M) + var*1i*rand(1,M);%noise
r=symbols+noise;%adding noise
symbols1 = atan(r);%demodulation
error = abs((symbols - symbols1)./abs(symbols));%error
sError(i) = mean(error);
tError(i) = 2*qfunc(sqrt(2*snr(i)));%theoritical error
end
%comparison
semilogy(snrdB, tError,'x-')
hold on
semilogy(snrdB, sError,'o-')
xlabel('snr(dB)')
ylabel('error')
grid on
答案 0 :(得分:1)
类似的事情应该起作用;
M=100000;
snrdB=1:10;
snr=10.^(snrdB/10);
sError = zeros(1,10);%simulated error
tError = zeros(1,10);%theoritical error
for i=1:10
symbols = randi([1,4],1,M);
symbols(symbols == 1) = 1;
symbols(symbols == 2) = 1i;
symbols(symbols == 3) = -1;
symbols(symbols == 4) = -1i;
var = 1/(2*sqrt(snr(i)));%variance
noise = var*(randn(1,M)) + var*j*(randn(1,M));
r=symbols+noise;%adding noise
c1 = exp(j*pi/4);
c2 = exp(-j*pi/4);
symbols1 = sign(real(symbols .* c1));
symbols2 = sign(imag(symbols .* c1));
symbols3 = sign(real(symbols .* c2));
symbols4 = sign(imag(symbols .* c2));
symbols1r = sign(real(r .* c1));
symbols2r = sign(imag(r .* c1));
symbols3r = sign(real(r .* c2));
symbols4r = sign(imag(r .* c2));
ind = find(symbols1==symbols1r & symbols2==symbols2r & symbols3==symbols3r & symbols4==symbols4r);
sError(i) = (M-length(ind))/M;
tError(i) = 2*qfunc(sqrt(2*snr(i)));%theoritical error
end
%comparison
semilogy(snrdB, tError,'x-')
hold on
semilogy(snrdB, sError,'o-')
xlabel('snr(dB)')
ylabel('error')
grid on
答案 1 :(得分:0)
我还认为解调有问题。您不应该在这里使用atan。我建议您应该分别处理实部和虚部。删除带有atan的行,并替换为以下行:
resymbols = real(r);
imsymbols = imag(r);
symbols1 = resymbols + 1i*imsymbols;