Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

MINISTRY OF DIGITAL TECHNOLOGIES OF THE REPUBLIC

OF UZBEKISTAN
TASHKENT UNIVERSITY OF INFORMATION TECHNOLOGIES
NAMED AFTER MUHAMMAD AL-KHWARIZMI

Assignment –
8,9

Student: Xusanboyev B.S.


Teacher: Tashmetov Sh.E.

Tashkent – 2023
Practise 8
Theme: Simulation of Phase Shift Keying
(QPSK-quadrature phase-shift keying, 4-PSK)

№ Modulating data Carrier signal Parameters


13 RAINY Cos(x) FD=0; fc=2;

Code:
clc
clear variables
clf

char = double('RAINY');

Ac = 1;
As = Ac;
fc = 2;
first_data = 1;
a(1:2)=first_data;
t1(1:2) = [0,1];

i = 3;

for cc = 1:length(char)
for n = 0:2:7
bit_n = bitshift(char(cc), -n);
a(i:i+1) = bitand(bit_n, 3);
t1(i) = (i-1)/2;
t1(i+1) = t1(i)+1;
i = i + 2;
end
end

nIterations = length(char) * 20000 + 4999;


t2 = zeros(1, nIterations);
c = zeros(1, nIterations);
s = zeros(1, nIterations);

for j = 1:nIterations
t2(j) = j / 5000;
i = floor(t2(j) * 2 + 1);
c(j) = Ac * cos(2 * pi * fc * t2(j));
s(j) = As * cos(2 * pi * fc * t2(j) + a(i) * pi / 2 + pi / 4);
end

subplot(4,1,1);
plot(t1, a);

subplot(4,1,2);
plot(t2, c);

subplot(4,1,3);
plot(t2, s, '.');
last_data = first_data;
buff_data = first_data;
time_c = 1;
rec_data(1:2) = first_data;
rec_time(1:2) = [0,1];
rec_c = 3;

for j = 4:length(s)
if t2(j) > time_c-0.2
if abs(s(j-1)-s(j-2)) > Ac*0.1
change_point = t2(j-1);
buff_data = get_data(s(j-3:j), last_data);
else
if abs(s(j-2)) < Ac*0.95 && (s(j-3) < s(j-2) && (j-1) > s(j) || s(j-3)
> s(j-2) && s(j-1) < s(j))
change_point = t2(j);
buff_data = get_data(s(j-3:j), last_data);
end
end
end
if t2(j) > time_c
last_data =
buff_data;
rec_data(rec_c:rec_c+1) = last_data;
rec_time(rec_c:rec_c+1) = [time_c, time_c+1];
time_c = time_c+1;
rec_c = rec_c+2;
end
end

subplot(4,1,4);
plot(rec_time, rec_data);

function res = get_data(s, last_data)


degree2 = asin(double(s(2)))/pi*180;
degree3 = asin(double(s(3)))/pi*180;
if s(2) > s(1)
if degree2 < 0
degree2 = 360 + degree2;
end
else
if degree2 > 0
degree2 = 180 - degree2;
else
degree2 = abs(180 - degree2);
end
end
if s(4) > s(3)
if degree3 < 0
degree3 = 360 + degree3;
end
else
if degree3 > 0
degree3 = 180 - degree3;
else
degree3 = abs(180 - degree3);
end
end
degree2 = degree2 - last_data*90;
degree3 = mod(degree3 - degree2, 360);
res = round(degree3/90);
end

Result:
Practise 9
Theme: Simulation of Phase Shift Keying
(QPSK-quadrature phase-shift keying, 4-PSK)

№ Modulating data Carrier signal Parameters


13 Bobur Cos(x) FD=0; fc=2;

Code:
clc
clear variables
clf

x = [0 1 0 0 0 0 1 0 0 1 1 0 1 1 1 1 0 1 1 0 0 0 1 0 0 1 1 1 0 1 0 1 0 1 1 1 0 0 1
0]; %Binary data is 'Bobur'

Ac = 1;
As = Ac;
fc = 1.35;
first_data = 1;
a(1:2)=first_data;
t1(1:2) = [0,1];
i = 3;
for cc = 1:length(x)
for n = 0:2:7
bit_n = bitshift(x(cc), -n);
a(i:i+1) = bitand(bit_n, 3);
t1(i) = (i-1)/2;
t1(i+1) = t1(i)+1;
i = i + 2;
end
end

nIterations = length(x) * 20000 + 4999;


t2 = zeros(1, nIterations);
c = zeros(1, nIterations);
s = zeros(1, nIterations);

for j = 1:nIterations
t2(j) = j / 5000;
i = floor(t2(j) * 2 + 1);
c(j) = Ac * cos(2 * pi * fc * t2(j));
s(j) = As * cos(2 * pi * fc * t2(j) + a(i) * pi / 2 + pi / 4);
end

subplot(4,1,1);
plot(t1, a);

subplot(4,1,2);
plot(t2, c);

subplot(4,1,3);
plot(t2, s, '.');

last_data = first_data;
buff_data = first_data;
time_c = 1;
rec_data(1:2) = first_data;
rec_time(1:2) = [first_data,1];
rec_c = 3;

for j = 4:length(s)
if t2(j) > time_c-0.2
if abs(s(j-1)-s(j-2)) > Ac*0.1
change_point = t2(j-1);
buff_data = get_data(s(j-3:j), last_data);
else
if abs(s(j-2)) < Ac*0.95 && (s(j-3) < s(j-2) && (j-1) > s(j) || s(j-3)
> s(j-2) && s(j-1) < s(j))
change_point = t2(j);
buff_data = get_data(s(j-3:j), last_data);
end
end
end

if t2(j) > time_c


last_data =
buff_data;
rec_data(rec_c:rec_c+1) = last_data;
rec_time(rec_c:rec_c+1) = [time_c, time_c+1];
time_c = time_c+1;
rec_c = rec_c+2;
end
end
subplot(4,1,4);
plot(rec_time, rec_data);

function res = get_data(s, last_data)


degree2 = asin(double(s(2)))/pi*180;
degree3 = asin(double(s(3)))/pi*180;
if s(2) > s(1)
if degree2 < 0
degree2 = 360 + degree2;
end
else
if degree2 > 0
degree2 = 180 - degree2;
else
degree2 = abs(180 - degree2);
end
end
if s(4) > s(3)
if degree3 < 0
degree3 = 360 + degree3;
end
else
if degree3 > 0
degree3 = 180 - degree3;
else
degree3 = abs(180 - degree3);
end
end
degree2 = degree2 - last_data*90;
degree3 = mod(degree3 - degree2, 360);
res = round(degree3/90);
end
Result

You might also like