-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathepsk.m
95 lines (80 loc) · 2.58 KB
/
epsk.m
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
function epsk(g,f)
%For more information, visit: www.matpic.com
%Modulation 8PSK
%Example: g is a binay vector; f is the carrier frequency.
%epsk([1 0 1 1 1 0],2)
%Author: Diego Orlando Barragán Guerrero
%diegokillemall@yahoo.com
%Loja (ECUADOR)
%Long live Heavy-Metal
%See also:
%http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=14328&objectType=FILE
if nargin > 2
error('Too many input arguments');
elseif nargin==1
f=1;
end
if f<1;
error('Frequency must be bigger than 1');
end
%*-*-*-*-*-*
l=length(g);
r=l/3;
re=ceil(r);
val=re-r;
if val~=0;
error('Please insert a vector divisible for 3');
end
%*-*-*-*-*-*
t=0:2*pi/149:2*pi;
cp=[];sp=[];
mod=[];mod1=[];bit=[];
for n=1:3:length(g);
if g(n)==0 && g(n+1)==1 && g(n+2)==1
die=cos(pi/8)*ones(1,150);
die1=sin(pi/8)*ones(1,150);
se=[zeros(1,50) ones(1,50) ones(1,50)];
elseif g(n)==0 && g(n+1)==1 && g(n+2)==0
die=cos(3*pi/8)*ones(1,150);
die1=sin(3*pi/8)*ones(1,150);
se=[zeros(1,50) ones(1,50) zeros(1,50)];
elseif g(n)==0 && g(n+1)==0 && g(n+2)==0
die=cos(5*pi/8)*ones(1,150);
die1=sin(5*pi/8)*ones(1,150);
se=[zeros(1,50) zeros(1,50) zeros(1,50)];
elseif g(n)==0 && g(n+1)==0 && g(n+2)==1
die=cos(7*pi/8)*ones(1,150);
die1=sin(7*pi/8)*ones(1,150);
se=[zeros(1,50) zeros(1,50) ones(1,50)];
elseif g(n)==1 && g(n+1)==0 && g(n+2)==1
die=cos(-7*pi/8)*ones(1,150);
die1=sin(-7*pi/8)*ones(1,150);
se=[ones(1,50) zeros(1,50) ones(1,50)];
elseif g(n)==1 && g(n+1)==0 && g(n+2)==0
die=cos(-5*pi/8)*ones(1,150);
die1=sin(-5*pi/8)*ones(1,150);
se=[ones(1,50) zeros(1,50) zeros(1,50)];
elseif g(n)==1 && g(n+1)==1 && g(n+2)==0
die=cos(-3*pi/8)*ones(1,150);
die1=sin(-3*pi/8)*ones(1,150);
se=[ones(1,50) ones(1,50) zeros(1,50)];
elseif g(n)==1 && g(n+1)==1 && g(n+2)==1
die=cos(-pi/8)*ones(1,150);
die1=sin(-pi/8)*ones(1,150);
se=[ones(1,50) ones(1,50) ones(1,50)];
end
c=cos(f*t);
s=sin(f*t);
cp=[cp die]; %Amplitude cosino
sp=[sp -die1]; %Amplitude sino
mod=[mod c]; %cosino carrier (Q)
mod1=[mod1 s]; %sino carrier (I)
bit=[bit se];
end
opsk=cp.*mod+sp.*mod1;
subplot(2,1,1);plot(bit,'LineWidth',1.5);grid on;
title('Binary Signal')
axis([0 50*length(g) -1.5 1.5]);
subplot(2,1,2);plot(opsk,'LineWidth',1.5);grid on;
title('8PSK modulation')
axis([0 50*length(g) -1.5 1.5]);