summaryrefslogtreecommitdiff
path: root/mechanical/motors/mesures-si2e-2007/m.m
blob: 70bfafdfd2060455de3a2afc6483635529556716 (plain)
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
% Plot or return matrix from a file.
function [rt, rx, rs, ra] = m (file, f)
    tres = 65536/14745600;
    cres = 2/75.78 / 1000;
    % Load file.
    eval (sprintf ("x = load %s;", file));
    % Make time vector.
    t = 0:tres:tres * (length (x) -1);
    % Split and scale.
    x *= cres;
    s = x(:, 3:4);
    a = x(:, 5:6);
    x(:, 3:6) = [];
    s *= 1/tres;
    a *= 1/(tres^2);
    % The optional argument override the filter factor.
    if (nargin == 1)
	% A little bit aggressive...
	f = 50;
    end
    if (f != 0)
	a(:, 1) = filter (ones (1, f), [f], a(:, 1));
	a(:, 2) = filter (ones (1, f), [f], a(:, 2));
    end
    % Plot if no output asked.
    if (nargout == 0)
	multiplot (3, 1);
	mplot (t, x(:, 1), ";xl;", t, x(:, 2), ";xr;");
	mplot (t, s(:, 1), ";sl;", t, s(:, 2), ";sr;");
	mplot (t, a(:, 1), ";al;", t, a(:, 2), ";ar;");
	oneplot ();
    else
	rt = t;
	rx = x;
	rs = s;
	ra = a;
    end
end