This repository has been archived by the owner on May 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MyoUI.m
executable file
·126 lines (108 loc) · 4.49 KB
/
MyoUI.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
classdef MyoUI < handle
properties
f % figure
wf % Long waveform
fwf % Frame waveform
sp % Spectrogram
fsp % Frame spectrum
interp % Interpreted signal
spectrogramWidth % Number of "columns" in the spectrogram for each frame
closed
end
methods
function self = MyoUI(Vmin, Vmax, Fs, P, N, freqs, spectrogramWidth, freqinterval)
self.f = figure('Name', 'Myoelectric measurements');
self.spectrogramWidth = spectrogramWidth;
gl = tiledlayout(2, 2);
% Long waveform + interpreted signal
ax = nexttile(gl);
%ax.Layout.Row = 1;
%ax.Layout.Column = 1;
self.wf = plot(ax, linspace(-P, 0, Fs*P)', zeros(Fs*P, 1));
axis(ax, [-P 0 Vmin, Vmax]);
xlabel(ax, 't [s]');
ylabel(ax, 'x [V]');
title(ax, 'Waveform');
hold(ax, 'on');
self.interp = area(ax, repmat(linspace(-P, 0, Fs/N*P)', 1, 2), zeros(Fs/N*P, 2));
legend(ax, 'x', 'RMS(x)', 'max(TK(x))');
ylabel(ax, 'y');
grid(ax, 'on');
% Last frame waveform
ax = nexttile(gl);
%ax.Layout.Row = 1;
%ax.Layout.Column = 2;
self.fwf = plot(ax, linspace(-N/Fs, 0, N)', zeros(N, 1));
axis(ax, [-N/Fs 0 Vmin Vmax]);
xlabel(ax, 't [s]');
ylabel(ax, 'x [V]');
title(ax, 'Last frame waveform');
grid(ax, 'on');
% Long spectrogram
ax = nexttile(gl);
%ax.Layout.Row = 2;
%ax.Layout.Column = 1;
[X, Y] = meshgrid(linspace(-P, 0, Fs/N*P*spectrogramWidth), freqs);
self.sp = pcolor(ax, X, Y, zeros(length(freqs), Fs/N*P*spectrogramWidth));
self.sp.EdgeAlpha = 0;
colormap(ax, viridis(256));
axis(ax, [-P 0 min(freqinterval) max(freqinterval)]);
xlabel(ax, 't [s]');
ylabel(ax, 'f [Hz]');
title(ax, 'Waterfall');
grid(ax, 'on');
% Last frame spectrogram
freqsfft = Fs*(0:N/2)'/N;
ax = nexttile(gl);
%ax.Layout.Row = 2;
%ax.Layout.Column = 2;
self.fsp = semilogx(ax, ones(length(freqsfft), 1), freqsfft);
axis(ax, [db2mag(-90) Vmax min(freqinterval) max(freqinterval)]);
ticks = [-90, -60, -30, -12, 0, mag2db(Vmax)];
xticks(ax, db2mag(ticks));
xticklabels(ax, arrayfun(@(db) sprintf('%ddB', db), ticks, 'UniformOutput', false));
%set(ax, 'YAxisLocation', 'right');
ylabel(ax, 'f [Hz]');
xlabel(ax, 'A [V]');
title(ax, 'Last frame spectrum');
grid(ax, 'on');
self.closed = false;
end
function displayProcessedFrame(self, t, x, A, y)
% DISPLAYPROCESSEDFRAME Update MyoUI with a new frame, consisting
% of: a time vector |t|, a measured time-domain amplitude vector
% |x|, a frequency-domain amplitude vector |A|, and an interpreted
% measured value |y|.
N = length(t);
% Long waveform
longt = [self.wf.XData(N+1:end), t'];
self.wf.XData = longt;
self.wf.YData = [self.wf.YData(N+1:end), x'];
self.wf.Parent.XLim = [longt(1) longt(end)];
% Interpreted signal
for i = 1 : 2
self.interp(i).XData = [self.interp(i).XData(2:end), mean(t)];
self.interp(i).YData = [self.interp(i).YData(2:end), y(i)];
end
% Frame waveform
self.fwf.XData = [self.fwf.XData t'];
self.fwf.YData = [self.fwf.YData x'];
self.fwf.Parent.XLim = [t(1) t(end)];
% Spectrogram
%self.sp.XData = [self.sp.XData(:,self.spectrogramWidth+1:end), repmat(t', size(Awl, 1), 1)];
self.sp.XData = [self.sp.XData(:,self.spectrogramWidth+1:end), repmat(t(end), size(A, 1), 1)];
self.sp.ZData = [self.sp.ZData(:,self.spectrogramWidth+1:end), A];
self.sp.CData = [self.sp.CData(:,self.spectrogramWidth+1:end), A];
self.sp.Parent.XLim = [self.sp.XData(1,1) t(end)];
% Frame spectrum
self.fsp.XData = A;
drawnow;
end
function closed = isclosed(self)
closed = self.closed;
end
function closeReq(self)
self.closed = true;
end
end
end