-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetFloatingPointData.m
64 lines (51 loc) · 1.37 KB
/
getFloatingPointData.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
function [time,s,c,w,theta] = getFloatingPointData(rpm,time_high,fs,np)
%% Create Rectangular Pulses
rps = rpm/60;
num_seconds_per_one_rev = 1/rps;
number_of_pulses_per_revoultion = np;
t = 0:1/fs:time_high;
pulse_frequency = 1/(num_seconds_per_one_rev/np);
x2 = square(2*pi*pulse_frequency*t)/2 + 0.5;
%plot(t,x2)
%ylim([-0.5 1.5])
%% Create Counted Rectangular Pulses
count = 0;
counted_pulses= [];
for i = 1:length(x2)-1
if x2(i) == 1 && x2(i+1) == 0
count = count + 1;
end
if (count == number_of_pulses_per_revoultion)
count = 0;
end
counted_pulses(i) = (count);
end
counted_pulses(length(x2)) = (counted_pulses(length(x2)-1));
%plot(t,counted_pulses,"-",t,x2,"--");
%% Calaculate Taylor's Series Representation of the Count
n = 1;for j = 1:length(counted_pulses)
w= counted_pulses(j)/number_of_pulses_per_revoultion;
theta(j) = w;
x = w*2*pi;
%fprintf("%u %u\n",j,length(counted_pulses));
ty = 0;
for i = 0:n
ty = ty +(((-1)^(i))*((x^(2*i+1)))/(factorial(2*i+1)));
end
ts_sin(j) = ty;
%fprintf("%.16f\n",ty);
sin_s(j) = sin(x);
cos_s(j) = cos(x);
if (t(j) ~= 0)
angular_velocity(j) = x/t(j);
end
end
%%
%plot(t,ts_sin);
%plot(t,sin_s);
%plot(t,cos_s);
%% EKF
s = sin_s;
c = cos_s;
w = angular_velocity;
time = t;