Phase Demodulation and Detection
Matlab Coding
1 % MATLAB script 2 3 M = 4; 4 Es = 1; % Energy per symbol 5 T = 1; 6 Ts = 100/T; 7 fc = 30/T; 8 t = 0:T/100:T; 9 l_t = length(t); 10 g_T = sqrt(2/T)*ones(1,l_t); 11 si_1 = g_T.*cos(2*pi*fc*t); 12 si_2 = -g_T.*sin(2*pi*fc*t);
13 var = [ 0 0.05 0.5]; % Noise variance vector
14 k = 1; 15 % Generation of the noise components: 16 n_c = sqrt(var(k))*randn(1,l_t); 17 n_s = sqrt(var(k))*randn(1,l_t); 18 for m = 0:M-1 19 % Generation of the transmitted signal: 20 s_mc = sqrt(Es) * cos(2*pi*m/M); 21 s_ms = sqrt(Es) * sin(2*pi*m/M); 22 u_m = s_mc.*si_1 + s_ms.*si_2;
23 % The received signal: 24 r = u_m + n_c.*cos(2*pi*fc*t) - n_s.*sin(2*pi*fc*t);
25 % The correlator outputs: 26 y_c = zeros(1,l_t); 27 y_s = zeros(1,l_t); 28 for i = 1:l_t 29 y_c(i) = sum(r(1:i).*si_1(1:i)); 30 y_s(i) = sum(r(1:i).*si_2(1:i)); 31 echo off 32 end 33 echo on
34 % Plotting the results: 35 subplot(3,2,m+1) 36 plot([0 1:length(y_c)-1],y_c,'.-') 37 hold 38 plot([0 1:length(y_s)-1],y_s) 39 if m==0 40 title(['sigma^2 = ',num2str(var(k)),', Phi = 0^{circ}']) 41 ylabel('it{y_c(n), k=1}') 42 elseif m==1 43 title(['sigma^2 = ',num2str(var(k)),', Phi = 90^{circ}']) 44 ylabel('it{y_s(n), k=1}') 45 elseif m==2 46 title(['sigma^2 = ',num2str(var(k)),', Phi = 180^{circ}']) 47 ylabel('it{y_c(n), k=1}') 48 else 49 title(['sigma^2 = ',num2str(var(k)),', Phi = 270^{circ}']) 50 ylabel('it{y_s(n), k=1}') 51 end 52 xlabel('it{n}') 53 axis auto 54 echo off 55 end 56 echo on 57 k = 2; 58 for m = 0:M-1 59 % Generation of the transmitted signal: 60 s_mc = sqrt(Es) * cos(2*pi*m/M); 61 s_ms = sqrt(Es) * sin(2*pi*m/M); 62 u_m = s_mc.*si_1 + s_ms.*si_2; 63 % The received signal: 64 r = u_m + n_c.*cos(2*pi*fc*t) - n_s.*sin(2*pi*fc*t); 65 % The correlator outputs: 66 y_c = zeros(1,l_t); 67 y_s = zeros(1,l_t); 68 for i = 1:l_t 69 y_c(i) = sum(r(1:i).*si_1(1:i)); 70 y_s(i) = sum(r(1:i).*si_2(1:i)); 71 echo off 72 end 73 echo on 74 % Plotting the results: 75 if m>=2 76 if m==2 77 figure 78 end 79 subplot(3,2,m-1) 80 plot([0 1:length(y_c)-1],y_c,'.-') 81 hold 82 plot([0 1:length(y_s)-1],y_s) 83 if m==0 84 title(['sigma^2 = ',num2str(var(k)),', Phi = 0^{circ}']) 85 ylabel('it{y_c(n), k=2}') 86 elseif m==1 87 title(['sigma^2 = ',num2str(var(k)),', Phi = 90^{circ}']) 88 ylabel('it{y_s(n), k=2}') 89 elseif m==2 90 title(['sigma^2 = ',num2str(var(k)),', Phi = 180^{circ}']) 91 ylabel('it{y_c(n), k=2}') 92 else 93 title(['sigma^2 = ',num2str(var(k)),', Phi = 270^{circ}']) 94 ylabel('it{y_s(n)}, k=2') 95 end 96 xlabel('it{n}') 97 axis auto 98 else 99 subplot(3,2,2*k+1+m) 100 plot([0 1:length(y_c)-1],y_c,'.-') 101 hold 102 plot([0 1:length(y_s)-1],y_s) 103 if m==0 104 title(['sigma^2 = ',num2str(var(k)),', Phi = 0^{circ}']) 105 ylabel('it{y_c(n), k=2}') 106 elseif m==1 107 title(['sigma^2 = ',num2str(var(k)),', Phi = 90^{circ}']) 108 ylabel('it{y_s(n), k=2}') 109 elseif m==2 110 title(['sigma^2 = ',num2str(var(k)),', Phi = 180^{circ}']) 111 ylabel('it{y_c(n), k=2}') 112 else 113 title(['sigma^2 = ',num2str(var(k)),', Phi = 270^{circ}']) 114 ylabel('it{y_s(n), k=2}') 115 end 116 xlabel('it{n}') 117 axis auto 118 end 119 echo off 120 end 121 echo on
122 k = 3; 123 for m = 0:M-1 124 % Generation of the transmitted signal: 125 s_mc = sqrt(Es) * cos(2*pi*m/M); 126 s_ms = sqrt(Es) * sin(2*pi*m/M); 127 u_m = s_mc.*si_1 + s_ms.*si_2; 128 % The received signal: 129 r = u_m + n_c.*cos(2*pi*fc*t) - n_s.*sin(2*pi*fc*t); 130 % The correlator outputs: 131 y_c = zeros(1,l_t); 132 y_s = zeros(1,l_t); 133 for i = 1:l_t 134 y_c(i) = sum(r(1:i).*si_1(1:i)); 135 y_s(i) = sum(r(1:i).*si_2(1:i)); 136 echo off 137 end 138 echo on 139 % Plotting the results: 140 subplot(3,2,k+m) 141 plot([0 1:length(y_c)-1],y_c,'.-') 142 hold 143 plot([0 1:length(y_s)-1],y_s) 144 if m==0 145 title(['sigma^2 = ',num2str(var(k)),', Phi = 0^{circ}']) 146 ylabel('it{y_c(n), k=3}') 147 elseif m==1 148 title(['sigma^2 = ',num2str(var(k)),', Phi = 90^{circ}']) 149 ylabel('it{y_s(n), k=3}') 150 elseif m==2 151 title(['sigma^2 = ',num2str(var(k)),', Phi = 180^{circ}']) 152 ylabel('it{y_c(n), k=2}') 153 else 154 title(['sigma^2 = ',num2str(var(k)),', Phi = 270^{circ}']) 155 ylabel('it{y_s(n), k=3}') 156 end 157 xlabel('it{n}') 158 axis auto 159 echo off 160 end
Simulation Result
variance = 0
![](https://img2020.cnblogs.com/blog/977170/202009/977170-20200918221051676-297034409.png)
variance = 0.05
variance = 0.5
Reference,
1. <<Contemporary Communication System using MATLAB>> - John G. Proakis