1.要求:

目前大夫主要以听诊器倾听病人的气管、肺部区域的声音,对病人的疾病进行判断;请设计一个听诊的软件,要求如下:
1) 可记录病人的姓名、年龄、性别、病史、不同疾病部位等状况;
2) 对病人的气管、肺部等区域的声音进行采集、分析、存储(前端听诊
部分不用考虑,只考虑数据采集部分)。
3) 可分析不同声音分量的大小,给出频谱图,以及主要频率的幅度,便
于大夫分析和验证;
4) 由于采集到的信号经常存在某些干扰信号,比如心脏的震动,请设计
低通、带通、带阻滤波器对信号处理,滤波器参数在用户界面中可以进行设
置,方便医生进行使用;
5) 编制 GUI 用户界面,实现上述所有功能。

2.实现

image.png

  1. classdef app1 < matlab.apps.AppBase
  2. % Properties that correspond to app components
  3. properties (Access = public)
  4. UIFigure matlab.ui.Figure
  5. Label_6 matlab.ui.control.Label
  6. Button_6 matlab.ui.control.Button
  7. Button_5 matlab.ui.control.Button
  8. Button_4 matlab.ui.control.Button
  9. Button_3 matlab.ui.control.Button
  10. Button_2 matlab.ui.control.Button
  11. EditField_6 matlab.ui.control.EditField
  12. Label_5 matlab.ui.control.Label
  13. Button matlab.ui.control.Button
  14. EditField_5 matlab.ui.control.EditField
  15. EditField_5Label matlab.ui.control.Label
  16. EditField_4 matlab.ui.control.EditField
  17. Label_4 matlab.ui.control.Label
  18. EditField_3 matlab.ui.control.EditField
  19. EditField_3Label matlab.ui.control.Label
  20. EditField_2 matlab.ui.control.EditField
  21. Label_3 matlab.ui.control.Label
  22. EditField matlab.ui.control.EditField
  23. EditFieldLabel matlab.ui.control.Label
  24. DropDown matlab.ui.control.DropDown
  25. Label matlab.ui.control.Label
  26. UIAxes4 matlab.ui.control.UIAxes
  27. UIAxes3 matlab.ui.control.UIAxes
  28. UIAxes2 matlab.ui.control.UIAxes
  29. UIAxes matlab.ui.control.UIAxes
  30. end
  31. % Callbacks that handle component events
  32. methods (Access = private)
  33. % Code that executes after component creation
  34. function startupFcn(app)
  35. app.Label_6.Text = '4156';
  36. global strname;
  37. global strage;
  38. global strsex;
  39. global strmedical;
  40. global strdds;
  41. global strpath;
  42. strname = ["病人1名字","病人2名字","病人3名字","病人4名字","病人5名字","病人6名字","病人7名字","病人8名字","病人9名字","病人10名字"];
  43. strage = ["病人1年龄","病人2年龄","病人3年龄","病人4年龄","病人5年龄","病人6年龄","病人7年龄","病人8年龄","病人9年龄","病人10年龄"];
  44. strsex = ["病人1性别","病人2性别","病人3性别","病人4性别","病人5性别","病人6性别","病人7性别","病人8性别","病人9性别","病人10性别"];
  45. strmedical = ["病人1病史","病人2病史","病人3病史","病人4病史","病人5病史","病人6病史","病人7病史","病人8病史","病人9病史","病人10病史"];
  46. strdds = [ "病人1生病部位","病人2生病部位","病人3生病部位","病人4生病部位","病人5生病部位","病人6生病部位","病人7生病部位","病人8生病部位","病人9生病部位","病人10生病部位"];
  47. strpath = ["1.m4a","2.m4a","3.m4a","4.m4a","5.m4a","6.m4a","7.m4a","8.m4a","9.m4a","10.m4a"];
  48. end
  49. % Value changed function: DropDown
  50. function DropDownValueChanged(app, event)
  51. % app.Label_2.Text = app.DropDown.Value;
  52. %
  53. global strname;
  54. global strage;
  55. global strsex;
  56. global strmedical;
  57. global strdds;
  58. global strpath;
  59. sequence = int8(str2double(app.DropDown.Value));
  60. app.EditField.Value = strname(sequence);
  61. app.EditField_2.Value = strage(sequence);
  62. app.EditField_3.Value = strsex(sequence);
  63. app.EditField_4.Value = strmedical(sequence);
  64. app.EditField_5.Value = strdds(sequence);
  65. app.EditField_6.Value = strpath(sequence);
  66. end
  67. % Drop down opening function: DropDown
  68. function DropDownOpening(app, event)
  69. end
  70. % Button pushed function: Button_2
  71. function Button_2Pushed(app, event)
  72. % filterDesigner;
  73. anpath = strcat(app.EditField_6.Value);
  74. [y1,fs]=audioread(anpath);
  75. y1=y1(:,1);%取单列
  76. global global_y1 global_fs;
  77. global_y1 = y1;
  78. global_fs = fs;
  79. N1=length(y1); %求信号长度
  80. n=0:N1-1; %所有元素
  81. t1=n/fs; %时间
  82. f1=-24000:fs/N1:fs*(N1-1)/N1-24000; %频率
  83. Y1=fftshift(fft(y1,N1)); %傅里叶变换
  84. ratio = app.EditField.Value;
  85. sound(y1,fs);
  86. plot(app.UIAxes,t1,y1);
  87. app.UIAxes.XLim = [0 2.5];
  88. app.UIAxes.XTick = 0:0.5:2.5;
  89. plot(app.UIAxes2,f1,abs(Y1));
  90. app.UIAxes2.XLim = [-5000 5000];
  91. app.UIAxes2.XTick = -5000:500:5000;
  92. end
  93. % Button pushed function: Button
  94. function ButtonPushed(app, event)
  95. global strname;
  96. global strage;
  97. global strsex;
  98. global strmedical;
  99. global strdds;
  100. sequence = int8(str2double(app.DropDown.Value));
  101. strname(sequence) = app.EditField.Value;
  102. strage(sequence) = app.EditField_2.Value;
  103. strsex(sequence) = app.EditField_3.Value;
  104. strmedical(sequence) = app.EditField_4.Value;
  105. strdds(sequence) = app.EditField_5.Value;
  106. strpath(sequence) = app.EditField_6.Value;
  107. end
  108. % Window scroll wheel function: UIFigure
  109. function UIFigureWindowScrollWheel(app, event)
  110. verticalScrollAmount = event.VerticalScrollAmount;
  111. verticalScrollCount = event.VerticalScrollCount;
  112. end
  113. % Close request function: UIFigure
  114. function UIFigureCloseRequest(app, event)
  115. delete(app)
  116. end
  117. % Button pushed function: Button_3
  118. function Button_3Pushed(app, event)
  119. global global_y1 global_fs;
  120. fs = global_fs;
  121. LPF_Coe = load('lpf.mat'); %低通滤波
  122. y2 = filter(LPF_Coe.Num,1,global_y1);
  123. N2=length(y2);
  124. k=0:1:N2-1;
  125. t2=k/fs;
  126. f2=-24000:fs/N2:fs*(N2-1)/N2-24000;
  127. Y2=fftshift(fft(y2,N2));
  128. plot(app.UIAxes3,t2,y2);
  129. app.UIAxes3.XLim = [0 2.5];
  130. app.UIAxes3.XTick = 0:0.5:2.5;
  131. plot(app.UIAxes4,f2,abs(Y2));
  132. app.UIAxes4.XLim = [-5000 5000];
  133. app.UIAxes4.XTick = -5000:500:5000;
  134. end
  135. % Button pushed function: Button_6
  136. function Button_6Pushed(app, event)
  137. filterDesigner;
  138. end
  139. % Button pushed function: Button_4
  140. function Button_4Pushed(app, event)
  141. global global_y1 global_fs;
  142. fs = global_fs;
  143. BPF_Coe = load('bpf.mat'); %带通滤波
  144. y2 = filter(BPF_Coe.Num,1,global_y1);
  145. N2=length(y2);
  146. k=0:1:N2-1;
  147. t2=k/fs;
  148. f2=-24000:fs/N2:fs*(N2-1)/N2-24000;
  149. Y2=fftshift(fft(y2,N2));
  150. plot(app.UIAxes3,t2,y2);
  151. app.UIAxes3.XLim = [0 2.5];
  152. app.UIAxes3.XTick = 0:0.5:2.5;
  153. plot(app.UIAxes4,f2,abs(Y2));
  154. app.UIAxes4.XLim = [-5000 5000];
  155. app.UIAxes4.XTick = -5000:500:5000;
  156. end
  157. % Button down function: UIAxes4
  158. function UIAxes4ButtonDown(app, event)
  159. end
  160. % Button pushed function: Button_5
  161. function Button_5Pushed(app, event)
  162. global global_y1 global_fs;
  163. fs = global_fs;
  164. HPF_Coe = load('hpf.mat'); %高通滤波
  165. y2 = filter(HPF_Coe.Num,1,global_y1);
  166. N2=length(y2);
  167. k=0:1:N2-1;
  168. t2=k/fs;
  169. f2=-24000:fs/N2:fs*(N2-1)/N2-24000;
  170. Y2=fftshift(fft(y2,N2));
  171. plot(app.UIAxes3,t2,y2);
  172. app.UIAxes3.XLim = [0 2.5];
  173. app.UIAxes3.XTick = 0:0.5:2.5;
  174. plot(app.UIAxes4,f2,abs(Y2));
  175. app.UIAxes4.XLim = [-5000 5000];
  176. app.UIAxes4.XTick = -5000:500:5000;
  177. end
  178. end
  179. % Component initialization
  180. methods (Access = private)
  181. % Create UIFigure and components
  182. function createComponents(app)
  183. % Create UIFigure and hide until all components are created
  184. app.UIFigure = uifigure('Visible', 'off');
  185. app.UIFigure.AutoResizeChildren = 'off';
  186. app.UIFigure.Color = [0.9412 0.9412 0.9412];
  187. app.UIFigure.Position = [200 200 1063 592];
  188. app.UIFigure.Name = '数字听诊器 1802501 180200815 王世阳';
  189. app.UIFigure.CloseRequestFcn = createCallbackFcn(app, @UIFigureCloseRequest, true);
  190. app.UIFigure.WindowScrollWheelFcn = createCallbackFcn(app, @UIFigureWindowScrollWheel, true);
  191. app.UIFigure.WindowStyle = 'modal';
  192. % Create UIAxes
  193. app.UIAxes = uiaxes(app.UIFigure);
  194. title(app.UIAxes, 'Title')
  195. xlabel(app.UIAxes, 'X')
  196. ylabel(app.UIAxes, 'Y')
  197. zlabel(app.UIAxes, 'Z')
  198. app.UIAxes.Position = [346 284 300 185];
  199. % Create UIAxes2
  200. app.UIAxes2 = uiaxes(app.UIFigure);
  201. title(app.UIAxes2, 'Title')
  202. xlabel(app.UIAxes2, 'X')
  203. ylabel(app.UIAxes2, 'Y')
  204. zlabel(app.UIAxes2, 'Z')
  205. app.UIAxes2.Position = [666 284 300 185];
  206. % Create UIAxes3
  207. app.UIAxes3 = uiaxes(app.UIFigure);
  208. title(app.UIAxes3, 'Title')
  209. xlabel(app.UIAxes3, 'X')
  210. ylabel(app.UIAxes3, 'Y')
  211. zlabel(app.UIAxes3, 'Z')
  212. app.UIAxes3.Position = [346 13 300 185];
  213. % Create UIAxes4
  214. app.UIAxes4 = uiaxes(app.UIFigure);
  215. title(app.UIAxes4, 'Title')
  216. xlabel(app.UIAxes4, 'X')
  217. ylabel(app.UIAxes4, 'Y')
  218. zlabel(app.UIAxes4, 'Z')
  219. app.UIAxes4.ButtonDownFcn = createCallbackFcn(app, @UIAxes4ButtonDown, true);
  220. app.UIAxes4.Position = [685 13 300 185];
  221. % Create Label
  222. app.Label = uilabel(app.UIFigure);
  223. app.Label.HorizontalAlignment = 'right';
  224. app.Label.Position = [54 522 53 22];
  225. app.Label.Text = '病人序号';
  226. % Create DropDown
  227. app.DropDown = uidropdown(app.UIFigure);
  228. app.DropDown.Items = {'01', '02', '03', '04', '05', '06', '07', '08', '09', '10'};
  229. app.DropDown.DropDownOpeningFcn = createCallbackFcn(app, @DropDownOpening, true);
  230. app.DropDown.ValueChangedFcn = createCallbackFcn(app, @DropDownValueChanged, true);
  231. app.DropDown.Position = [122 522 100 22];
  232. app.DropDown.Value = '01';
  233. % Create EditFieldLabel
  234. app.EditFieldLabel = uilabel(app.UIFigure);
  235. app.EditFieldLabel.HorizontalAlignment = 'right';
  236. app.EditFieldLabel.Position = [82 461 29 22];
  237. app.EditFieldLabel.Text = '姓名';
  238. % Create EditField
  239. app.EditField = uieditfield(app.UIFigure, 'text');
  240. app.EditField.Position = [126 461 100 22];
  241. % Create Label_3
  242. app.Label_3 = uilabel(app.UIFigure);
  243. app.Label_3.HorizontalAlignment = 'right';
  244. app.Label_3.Position = [82 404 29 22];
  245. app.Label_3.Text = '年龄';
  246. % Create EditField_2
  247. app.EditField_2 = uieditfield(app.UIFigure, 'text');
  248. app.EditField_2.Position = [126 404 100 22];
  249. % Create EditField_3Label
  250. app.EditField_3Label = uilabel(app.UIFigure);
  251. app.EditField_3Label.HorizontalAlignment = 'right';
  252. app.EditField_3Label.Position = [82 351 29 22];
  253. app.EditField_3Label.Text = '性别';
  254. % Create EditField_3
  255. app.EditField_3 = uieditfield(app.UIFigure, 'text');
  256. app.EditField_3.Position = [126 351 100 22];
  257. % Create Label_4
  258. app.Label_4 = uilabel(app.UIFigure);
  259. app.Label_4.HorizontalAlignment = 'right';
  260. app.Label_4.Position = [82 284 29 22];
  261. app.Label_4.Text = '病史';
  262. % Create EditField_4
  263. app.EditField_4 = uieditfield(app.UIFigure, 'text');
  264. app.EditField_4.Position = [122 216 200 100];
  265. % Create EditField_5Label
  266. app.EditField_5Label = uilabel(app.UIFigure);
  267. app.EditField_5Label.HorizontalAlignment = 'right';
  268. app.EditField_5Label.Position = [61 165 53 22];
  269. app.EditField_5Label.Text = '不同疾病';
  270. % Create EditField_5
  271. app.EditField_5 = uieditfield(app.UIFigure, 'text');
  272. app.EditField_5.Position = [122 87 200 100];
  273. % Create Button
  274. app.Button = uibutton(app.UIFigure, 'push');
  275. app.Button.ButtonPushedFcn = createCallbackFcn(app, @ButtonPushed, true);
  276. app.Button.Position = [122 36 100 24];
  277. app.Button.Text = '存档/修改';
  278. % Create Label_5
  279. app.Label_5 = uilabel(app.UIFigure);
  280. app.Label_5.HorizontalAlignment = 'right';
  281. app.Label_5.Position = [388 522 77 22];
  282. app.Label_5.Text = '病人声音路径';
  283. % Create EditField_6
  284. app.EditField_6 = uieditfield(app.UIFigure, 'text');
  285. app.EditField_6.Position = [480 522 100 22];
  286. app.EditField_6.Value = '1.m4a';
  287. % Create Button_2
  288. app.Button_2 = uibutton(app.UIFigure, 'push');
  289. app.Button_2.ButtonPushedFcn = createCallbackFcn(app, @Button_2Pushed, true);
  290. app.Button_2.Position = [480 480 100 24];
  291. app.Button_2.Text = '绘制频谱图';
  292. % Create Button_3
  293. app.Button_3 = uibutton(app.UIFigure, 'push');
  294. app.Button_3.ButtonPushedFcn = createCallbackFcn(app, @Button_3Pushed, true);
  295. app.Button_3.Position = [381 225 100 24];
  296. app.Button_3.Text = '低通滤波';
  297. % Create Button_4
  298. app.Button_4 = uibutton(app.UIFigure, 'push');
  299. app.Button_4.ButtonPushedFcn = createCallbackFcn(app, @Button_4Pushed, true);
  300. app.Button_4.Position = [556 225 100 24];
  301. app.Button_4.Text = '带通滤波';
  302. % Create Button_5
  303. app.Button_5 = uibutton(app.UIFigure, 'push');
  304. app.Button_5.ButtonPushedFcn = createCallbackFcn(app, @Button_5Pushed, true);
  305. app.Button_5.Position = [732 225 100 24];
  306. app.Button_5.Text = '高通滤波';
  307. % Create Button_6
  308. app.Button_6 = uibutton(app.UIFigure, 'push');
  309. app.Button_6.ButtonPushedFcn = createCallbackFcn(app, @Button_6Pushed, true);
  310. app.Button_6.Position = [885 224 100 24];
  311. app.Button_6.Text = '更改滤波器参数';
  312. % Create Label_6
  313. app.Label_6 = uilabel(app.UIFigure);
  314. app.Label_6.Position = [686 501 35 22];
  315. % Show the figure after all components are created
  316. app.UIFigure.Visible = 'on';
  317. end
  318. end
  319. % App creation and deletion
  320. methods (Access = public)
  321. % Construct app
  322. function app = app1
  323. % Create UIFigure and components
  324. createComponents(app)
  325. % Register the app with App Designer
  326. registerApp(app, app.UIFigure)
  327. % Execute the startup function
  328. runStartupFcn(app, @startupFcn)
  329. if nargout == 0
  330. clear app
  331. end
  332. end
  333. % Code that executes before app deletion
  334. function delete(app)
  335. % Delete UIFigure when app is deleted
  336. delete(app.UIFigure)
  337. end
  338. end
  339. end

3.路径读取

anpath = strcat(app.EditField_6.Value);
[y1,fs]=audioread(anpath);

4.读取到的字符串转成数组

            ratio = app.EditField.Value;
            ratio = 1000*str2double(ratio);