-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGUI_start.m
383 lines (296 loc) · 13 KB
/
GUI_start.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
function varargout = GUI_start(varargin)
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @GUI_start_OpeningFcn, ...
'gui_OutputFcn', @GUI_start_OutputFcn, ...
'gui_LayoutFcn', [], ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before GUI_start is made visible.
function GUI_start_OpeningFcn(hObject, eventdata, handles, varargin)
% Choose default command line output for GUI_start
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% --- Outputs from this function are returned to the command line.
function varargout = GUI_start_OutputFcn(hObject, eventdata, handles)
% Get default command line output from handles structure
varargout{1} = handles.output;
function edit1_Callback(hObject, eventdata, handles)
% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit2_Callback(hObject, eventdata, handles)
% --- Executes during object creation, after setting all properties.
function edit2_CreateFcn(hObject, eventdata, handles)
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
global Flag_1 container_csi Flag_collect coss isYun num_collect
Flag_collect = 0;
num_collect = 100;
isYun = 1;
while Flag_1
%% Build a TCP Server and wait for connection
%% 建立TCP服务器并等待连接
port = 8090;
t = tcpip('0.0.0.0', port, 'NetworkRole', 'server');
t.InputBufferSize = 1024;
t.Timeout = 15;
fprintf('Waiting for connection on port %d\n',port);
fopen(t);
fprintf('Accept connection from %s\n',t.RemoteHost);
%% Set plot parameters 设定绘图参数
axis([1,30,-10,30]);
t1=0;
m1=zeros(30,1);
%% Starting in R2014b, the EraseMode property has been removed from all graphics objects.
%% https://mathworks.com/help/matlab/graphics_transition/how-do-i-replace-the-erasemode-property.html
[~, DATESTR] = version();
if datenum(DATESTR) > datenum('February 11, 2014')
% p = plot(gui_handles.axes1,t1,m1,'MarkerSize',5);
p = plot(handles.axes1,t1,m1);
else
%p = plot(gui_handles.axes1,t1,m1,'EraseMode','Xor','MarkerSize',5);
p = plot(handles.axes1,t1,m1,'EraseMode','Xor','MarkerSize',5);
end
% xlabel('Subcarrier index');
% ylabel('SNR (dB)');
%% Initialize variables
csi_entry = []; % 记录
index = -1; % The index of the plots which need shadowing
broken_perm = 0; % Flag marking whether we've encountered a broken CSI yet
triangle = [1 3 6]; % What perm should sum to for 1,2,3 antennas
%% Process all entries in socket 处理套接字中的所有条目
% Need 3 bytes -- 2 byte size field and 1 byte code
while Flag_1
% Read size and code from the received packets
s = warning('error', 'instrument:fread:unsuccessfulRead');
try
field_len = fread(t, 1, 'uint16');
% t:文件句柄 1 :是读入的元素个数 'uint16': 格式
% 读取 二进制文件
catch
warning(s);
disp('Timeout, please restart the client and connect again.');
break;
end
code = fread(t,1);
% If unhandled code, skip (seek over) the record and continue
if (code == 187) % get beamforming or phy data
bytes = fread(t, field_len-1, 'uint8');
bytes = uint8(bytes);
if (length(bytes) ~= field_len-1)
fclose(t);
return;
end
else if field_len <= t.InputBufferSize % skip all other info
fread(t, field_len-1, 'uint8');
continue;
else
continue;
end
end
if (code == 187) % (tips: 187 = hex2dec('bb')) Beamforming matrix -- output a record
csi_entry = read_bfee(bytes);
perm = csi_entry.perm; % 接收天线的信号排列到处理测量的3个RF链
Nrx = csi_entry.Nrx; % 天线的数量
if Nrx > 1 % No permuting needed for only 1 antenna
if sum(perm) ~= triangle(Nrx) % matrix does not contain default values
if broken_perm == 0
broken_perm = 1;
fprintf('WARN ONCE: Found CSI (%s) with Nrx=%d and invalid perm=[%s]\n', filename, Nrx, int2str(perm));
end
else
csi_entry.csi(:,perm(1:Nrx),:) = csi_entry.csi(:,1:Nrx,:);
end
end
end
index = mod(index+1, 10);
csi = get_scaled_csi(csi_entry);%CSI data
%You can use the CSI data here.
%This plot will show graphics about recent 10 csi packets
set(p(index*3 + 1),'XData', [1:30], 'YData', db(abs(squeeze(csi(1,1,:)).')), 'color', 'b', 'linestyle', '-');
if Nrx > 1
set(p(index*3 + 2),'XData', [1:30], 'YData', db(abs(squeeze(csi(1,2,:)).')), 'color', 'g', 'linestyle', '-');
end
if Nrx > 2
set(p(index*3 + 3),'XData', [1:30], 'YData', db(abs(squeeze(csi(1,3,:)).')), 'color', 'r', 'linestyle', '-');
container_csi = db(abs(squeeze(csi).'));
if Flag_collect & num_collect
% disp(size(container_csi))
coss = [coss;container_csi];
num_collect = num_collect - 1;
end
end
axis([1,30,-10,40]);
drawnow;
csi_entry = [];
end
%% Close file
fclose(t);
delete(t);
isYun = 0;
end
% --- Executes on selection change in listbox1.
function listbox1_Callback(hObject, eventdata, handles)
% --- Executes during object creation, after setting all properties.
function listbox1_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% 增加ID
id_yet = get(handles.listbox1, 'string');
id_count = length(id_yet);
id_add = num2str(id_count + 1);
set(handles.listbox1, 'string', sort([id_yet; id_add]));
mkdir(strcat('data/user', id_add));
function pushbutton2_Callback(hObject, eventdata, handles)
% 增加数据--》步态的csi数据
global isYun Flag_collect coss num_collect
if isYun
% 判断是否打开了tcp
end
sp=actxserver('SAPI.SpVoice');
sp.Speak('请开始行走');
As = get(handles.listbox1,'value');
filepath = strcat('data/user', As,'/',As,'.mat');
Flag_collect = 1;
while num_collect
end
save(filepath,'coss');
Flag_collect = 0;
coss = [];
% --- Executes on button press in pushbutton5.
function pushbutton5_Callback(hObject, eventdata, handles)
% 复位按钮
global collect_con coss
coss = [];
collect_con = [];
% --- Executes on button press in pushbutton4.
function pushbutton4_Callback(hObject, eventdata, handles)
% 识别按钮
global Flag_collect coss num_collect
sp=actxserver('SAPI.SpVoice');
sp.Speak('请开始行走');
Flag_collect = 1;
while num_collect
end
plot(handles.axes3,coss);
Flag_collect = 0;
% svm
n = get(handles.listbox1, 'string');
svm_trainer = svm_training(create_training_data(n));
score = create_testing_data(coss);
coss =[];
classify_label = svm_classifying(svm_trainer,score);
% 显示
set(handles.text14,'String',classify_label);
% --- Executes on mouse press over axes background.
function axes2_ButtonDownFcn(hObject, eventdata, handles)
% --- Executes during object creation, after setting all properties.
function axes2_CreateFcn(hObject, eventdata, handles)
% 代码注释 --到yc机器开启
global vid vid_res n_bands;
[vid, vid_res, n_bands] = open_camera();
axes(handles.axes2);
hImage = image(zeros(vid_res(2),vid_res(1),n_bands));
preview(vid, hImage);
% --- Executes during object creation, after setting all properties.
function axes1_CreateFcn(hObject, eventdata, handles)
% --- Executes during object creation, after setting all properties.
function figure1_CreateFcn(hObject, eventdata, handles)
global Flag_1
Flag_1 = 1;
% --- Executes during object deletion, before destroying properties.
function figure1_DeleteFcn(hObject, eventdata, handles)
global Flag_1
Flag_1 = 0;
% --- Executes on button press in pushbutton6.
function pushbutton6_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton6 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
open('recognition.fig');
function edit4_Callback(hObject, eventdata, handles)
% hObject handle to edit4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit4 as text
% str2double(get(hObject,'String')) returns contents of edit4 as a double
% --- Executes during object creation, after setting all properties.
function edit4_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit3_Callback(hObject, eventdata, handles)
% hObject handle to edit3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit3 as text
% str2double(get(hObject,'String')) returns contents of edit3 as a double
% --- Executes during object creation, after setting all properties.
function edit3_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit5_Callback(hObject, eventdata, handles)
% hObject handle to edit5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit5 as text
% str2double(get(hObject,'String')) returns contents of edit5 as a double
% --- Executes during object creation, after setting all properties.
function edit5_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit6_Callback(hObject, eventdata, handles)
% hObject handle to edit6 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit6 as text
% str2double(get(hObject,'String')) returns contents of edit6 as a double
% --- Executes during object creation, after setting all properties.
function edit6_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit6 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end