-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathQPSK.sce
136 lines (136 loc) · 3.5 KB
/
QPSK.sce
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
126
127
128
129
130
131
132
133
134
135
136
clear;
clf;
fm=1; //Modulating wave frequency
dt=0.001;
t=0:dt:2;
m=sin(2*%pi*fm*t); //Modulating wave
//*********************Level Converter Block******************//
N=length(t);
modulating_signal=zeros(1:N);
for i =1:N
if(m(i)>0) then
modulating_signal(i)=1; //Modulating square wave
else
modulating_signal(i)=-1; //Modulating square wave
end
end
//*******************Carrier wave generator***************//
fc=fm*10; //Carrier wave frequency
Ac=4.25;
oddSample=1:2:N;
evenSample=2:2:N;
carrier_odd=Ac*sin(2*%pi*fc*dt*oddSample); //Carrier wave 1 with odd samples
carrier_even=Ac*cos(2*%pi*fc*dt*evenSample); //Carrier wave 2 with even samples
//****************Modulated signal generator*****************//
modulated_signal=zeros(1:N);
for i=1:N
if modulo(i,2)==0 then
modulated_signal(i) =modulating_signal(i).*carrier_even(i/2);
else
modulated_signal(i) = modulating_signal(i).*carrier_odd(i/2+1);
end
end
//******Addition of Gaussian Noise in Transmitted signal******//
r=rand(modulated_signal,"uniform");
hp=ffilt("hp",100,(fm)*dt);
filtered=filter(hp,1,r);
noiseVariance=0.1;
noise = sqrt(noiseVariance)*rand(1,length(modulated_signal));
//Generation of noise
qpsk=noise+modulated_signal; //Transmitted signal
//**********************Received signal**********************//
dm=zeros(1:N); //Received signal
for i=1:N
if modulo(i,2)==0 then
//disp(i);
20
dm(i)=qpsk(i).*carrier_even(i/2);
else
dm(i)=qpsk(i).*carrier_odd(i/2+1);
end
end
//*********************Demodulation Block*******************//
demodulated_signal=zeros(1:N);
for i=1:N
demodulated_signal(i)=(dm(i)*dt); //demodulated signal
end
//*************************Decision Block********************//
final_signal=zeros(1:N);
for i=1:N
if (demodulated_signal(i)>0) then
final_signal(i)=1; //Output of decision block
else
final_signal(i)=-1;//Output of decision block
end
end
//**********************Bit Error Probability****************//
count=0;
for i=1:N
if final_signal(i)==modulating_signal(i) then
count=count;
21
else
count=count+1;
end
end
disp(count);
disp(count/N); //Displaying the value of bit error probability
//****************************Plots**************************//
//Modulating signal
subplot(421);
plot(t,modulating_signal);
xgrid(3);
xlabel("time","fontsize",2);
ylabel("amplitude","fontsize",2);
title("Modulating signal", "fontsize", 4);
//carrier wave 1
subplot(422);
plot(carrier_odd);
xgrid(3);
xlabel("time","fontsize",2);
ylabel("amplitude","fontsize",2);
title("Odd carrier Signal", "fontsize", 4);
//carrier wave 2
subplot(423);
plot(carrier_even);
22
xgrid(3);
xlabel("time","fontsize",2);
ylabel("amplitude","fontsize",2);
title("Even carrier signal", "fontsize", 4);
//Modulated signal
subplot(424);
plot(modulated_signal);
xgrid(3);
xlabel("time","fontsize",2);
ylabel("amplitude","fontsize",2);
title("Modulated signal", "fontsize", 4);
//Transmitted signal with noise
subplot(425);
plot(qpsk);
xgrid(3);
xlabel("time","fontsize",2);
ylabel("amplitude","fontsize",2);
title("signal with noise", "fontsize", 4);
//Received signal
subplot(426);
plot(dm);
xgrid(3);
xlabel("time","fontsize",2);
ylabel("amplitude","fontsize",2);
23
title("Received signal", "fontsize", 4);
//Demodulated Signal
subplot(427);
plot(demodulated_signal);
xgrid(3);
xlabel("time","fontsize",2);
ylabel("amplitude","fontsize",2);
title("Demodulated signal", "fontsize", 4);
//Signal from decision box
subplot(428);
plot(final_signal);
xgrid(3);
xlabel("time","fontsize",2);
ylabel("amplitude","fontsize",2);
title("Final signal from decision box", "fontsize", 4);