1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
| clc clear all
T = 1; fc = 40/T; fs = 1000; n = 10000; t = linspace(0,n/2,n/2*fs); SNR_dB = -8:35; SNR = 10.^(SNR_dB/10); Ps = 1; Pn = Ps./SNR;
source = round(rand(1,n));
M = 4; d = sqrt(2/7); A = [0:M-1]*d; figure(1); scatter(real(A),imag(A),'filled'); xlim([-0.2,1.8]); title('4ASK-星座图');
ask_output = zeros(1,n/2*fs); X = zeros(1,n/2); Y = zeros(1,n/2); maptable = [0 0;0 1;1 1;1 0]; for i = 1:2:n for m = 1:4 if isequal(source(i:i+1),maptable(m,:)) X((i+1)/2) = A(m); break; end end end for i = 1:n/2 index = (i-1)*fs+1:i*fs; g(index) = 1; ask_output(index) = X(i).*g(index).*cos(2*pi*fc.*t(index)); end figure(2); plot(t,ask_output); xlim([-0.5,10]); ylim([-2,2]); title('4ASK-调制信号');
X1 = zeros(1,n/2); Z = sqrt(Pn(15)/2).*(randn(size(X))+1i.*randn(size(X))); Y = 1.*X+Z; figure(3); plot(real(X),imag(X),'r*'); hold on; plot(real(Y),imag(Y),'b.'); title('SNR=6dB 4ASK-AWGN信道星座图'); hold on;
SER1 = zeros(1,length(SNR_dB)); BER1 = zeros(1,length(SNR_dB)); T_SER1 = zeros(1,length(SNR_dB)); T_BER1 = zeros(1,length(SNR_dB)); times = 100;
for j = 1:44 SER1_sum = 0; BER1_sum = 0; for time = 1:times source = round(rand(1,n)); X = zeros(1,n/2); Y = zeros(1,n/2); maptable = [0 0;0 1;1 1;1 0]; for i = 1:2:n for m = 1:4 if isequal(source(i:i+1),maptable(m,:)) X((i+1)/2) = A(m); break; end end end Z = sqrt(Pn(j)/2).*(randn(size(X))+1i.*randn(size(X))); Y = 1.*X + Z; for i = 1:length(Y) dist = abs(Y(i)-A); [~,ind] = min(dist); X11(i) = A(ind); X1(2*i-1:2*i) = maptable(ind,:); end [F_Num,SER1(j)] = symerr(X,X11); [M_Num,BER1(j)] = biterr(source,X1); SER1_sum=SER1_sum+SER1(j); BER1_sum=BER1_sum+BER1(j); end SER1(j) = SER1_sum/times; BER1(j) = BER1_sum/times;
end
T_SER1 = 0.75.*erfc(sqrt(SNR./14)); T_BER1 = T_SER1./2; figure(4) semilogy(SNR_dB,SER1,'bO'); hold on; semilogy(SNR_dB,T_SER1,'r');hold off; axis([-8,25,10^-4,1]); title('SER-SNR曲线'); xlabel('SNR(dB)');ylabel('误符号率SER'); legend({'SER实际值','SER理论值'});
figure(5) semilogy(SNR_dB,BER1,'bO');hold on; semilogy(SNR_dB,T_BER1,'r');hold off; axis([-8,25,10^-4,1]); title('BER-SNR曲线'); xlabel('SNR(dB)');ylabel('误码率BER'); legend({'BER实际值','BER理论值'});
|