-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtelegraph.m
More file actions
46 lines (43 loc) · 813 Bytes
/
Copy pathtelegraph.m
File metadata and controls
46 lines (43 loc) · 813 Bytes
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
%random telegraph signal
clear all;
close all;
%time interval to look at
time_horizon=20;
%accuracy of x axis
accuracy=10000;
%time
t=linspace(0,time_horizon,accuracy);
%poisson intensity
lambda=1;
%draw one poisson variable
N=poissrnd(time_horizon*lambda)
%construct the process sample
Nt=unifrnd(0,time_horizon,1,N);
Nt=sort(Nt);
%
%
%
%build the poisson shots
for i=1:N
X1mat(:,i)=abs(t-Nt(i))<(time_horizon/accuracy/2);
X1=sum(X1mat,2);
end
stem(t,X1)
%build the counting process
X2(1)=0;
for k=1:accuracy
X2(k+1)=X2(k)+X1(k);
end
figure
plot(t,X2(2:accuracy+1))
%build the random telegraph signal
X3(1)=1-2*binornd(1,0.5);
for k=1:accuracy
if(X1(k)==0)
X3(k+1)=X3(k);
else
X3(k+1)=-X3(k);
end
end
figure
plot(t,X3(2:accuracy+1))