-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEncoder.m
More file actions
48 lines (43 loc) · 1.16 KB
/
Copy pathEncoder.m
File metadata and controls
48 lines (43 loc) · 1.16 KB
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
function [A_encoded,decision,Tb,Ap,R]=Encoder(A)
% A is L*R matrix, R is number of bits/sample, L is number of samples
[L,R]=size(A);
B=zeros(1,L*R);
%%% put the bits into a stream, from A (L*R) ->>> B(1*LR)
k=1;
for i=1:L
for j=1:R
B(k)=A(i,j);
k=k+1;
end
end
% B=reshape(A,[1,L*R]);
% B=transpose(B);
decision=input('Enter 1 for unipoler or 0 for polar representation');
while(decision ~=1 && decision ~=0)
disp("Choice isn't valid, try again");
decision=input('Enter 1 for unipoler, or 0 for polar representation');
end
switch decision
case 1
Ap=input('enterc pulse amplitude in volt');
Tb=input('enter bit duration in s');
A_encoded=Ap.*B;
case 0
Ap=input('enter pulse amplitude in volt');
Tb=input('enter bit duration in s');
for i=1:length(B)
switch B(i)
case 1
A_encoded(i)=Ap;
case 0
A_encoded(i)=-Ap;
end
end
end
t = 0:Tb:Tb*(length(1:10)-1);
figure;
hold on
stairs(t,A_encoded(1:10))
hold off
title('Encoded Message')
end