找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 2646|回复: 1
打印 上一主题 下一主题
收起左侧

MATLAB Guide制作的语音滤波器源码

[复制链接]
跳转到指定楼层
楼主
数字信号处理实验的一个作业,主要是语音滤波功能
语音滤波器Guide界面如下:




MATLAB源代码:

  1. function varargout = FilterSpeech(varargin)
  2. % FILTERSPEECH MATLAB code for FilterSpeech.fig
  3. %      FILTERSPEECH, by itself, creates a new FILTERSPEECH or raises the existing
  4. %      singleton*.
  5. %
  6. %      H = FILTERSPEECH returns the handle to a new FILTERSPEECH or the handle to
  7. %      the existing singleton*.
  8. %
  9. %      FILTERSPEECH('CALLBACK',hObject,eventData,handles,...) calls the local
  10. %      function named CALLBACK in FILTERSPEECH.M with the given input arguments.
  11. %
  12. %      FILTERSPEECH('Property','Value',...) creates a new FILTERSPEECH or raises the
  13. %      existing singleton*.  Starting from the left, property value pairs are
  14. %      applied to the GUI before FilterSpeech_OpeningFcn gets called.  An
  15. %      unrecognized property name or invalid value makes property application
  16. %      stop.  All inputs are passed to FilterSpeech_OpeningFcn via varargin.
  17. %
  18. %      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
  19. %      instance to run (singleton)".
  20. %
  21. % See also: GUIDE, GUIDATA, GUIHANDLES

  22. % Edit the above text to modify the response to help FilterSpeech

  23. % Last Modified by GUIDE v2.5 11-Jun-2018 01:26:21

  24. % Begin initialization code - DO NOT EDIT
  25. gui_Singleton = 1;
  26. gui_State = struct('gui_Name',       mfilename, ...
  27.                    'gui_Singleton',  gui_Singleton, ...
  28.                    'gui_OpeningFcn', @FilterSpeech_OpeningFcn, ...
  29.                    'gui_OutputFcn',  @FilterSpeech_OutputFcn, ...
  30.                    'gui_LayoutFcn',  [] , ...
  31.                    'gui_Callback',   []);
  32. if nargin && ischar(varargin{1})
  33.     gui_State.gui_Callback = str2func(varargin{1});
  34. end

  35. if nargout
  36.     [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
  37. else
  38.     gui_mainfcn(gui_State, varargin{:});
  39. end
  40. % End initialization code - DO NOT EDIT


  41. % --- Executes just before FilterSpeech is made visible.
  42. function FilterSpeech_OpeningFcn(hObject, eventdata, handles, varargin)
  43. % This function has no output args, see OutputFcn.
  44. % hObject    handle to figure
  45. % eventdata  reserved - to be defined in a future version of MATLAB
  46. % handles    structure with handles and user data (see GUIDATA)
  47. % varargin   command line arguments to FilterSpeech (see VARARGIN)

  48. % Choose default command line output for FilterSpeech
  49. handles.output = hObject;
  50. set(handles.uipanel3,'parent',gcf);
  51. set(handles.uipanel11,'parent',gcf);
  52. set(handles.uipanel12,'parent',gcf);
  53. handles.fs=20000;
  54. handles.y=0;
  55. %set(handles.fig1,'xcolor',[1 1 1]);
  56. % Update handles structure
  57. guidata(hObject, handles);

  58. % UIWAIT makes FilterSpeech wait for user response (see UIRESUME)
  59. % uiwait(handles.figure1);


  60. % --- Outputs from this function are returned to the command line.
  61. function varargout = FilterSpeech_OutputFcn(hObject, eventdata, handles)
  62. % varargout  cell array for returning output args (see VARARGOUT);
  63. % hObject    handle to figure
  64. % eventdata  reserved - to be defined in a future version of MATLAB
  65. % handles    structure with handles and user data (see GUIDATA)

  66. % Get default command line output from handles structure
  67. varargout{1} = handles.output;


  68. % --- Executes on button press in pushbutton5.
  69. function pushbutton5_Callback(hObject, eventdata, handles)
  70. % hObject    handle to pushbutton5 (see GCBO)
  71. % eventdata  reserved - to be defined in a future version of MATLAB
  72. % handles    structure with handles and user data (see GUIDATA)
  73. %handles.r=audiorecorder(44100,16,2);
  74. handles.r=audiorecorder(44100,16,1);
  75. record(handles.r);
  76. guidata(hObject,handles);

  77. % --- Executes on button press in pushbutton7.
  78. function pushbutton7_Callback(hObject, eventdata, handles)
  79. % hObject    handle to pushbutton7 (see GCBO)
  80. % eventdata  reserved - to be defined in a future version of MATLAB
  81. % handles    structure with handles and user data (see GUIDATA)
  82. pause(handles.r);
  83. guidata(hObject,handles);

  84. % --- Executes on button press in pushbutton8.
  85. function pushbutton8_Callback(hObject, eventdata, handles)
  86. % hObject    handle to pushbutton8 (see GCBO)
  87. % eventdata  reserved - to be defined in a future version of MATLAB
  88. % handles    structure with handles and user data (see GUIDATA)
  89. resume(handles.r);
  90. guidata(hObject,handles);

  91. % --- Executes on button press in pushbutton9.
  92. function pushbutton9_Callback(hObject, eventdata, handles)
  93. % hObject    handle to pushbutton9 (see GCBO)
  94. % eventdata  reserved - to be defined in a future version of MATLAB
  95. % handles    structure with handles and user data (see GUIDATA)
  96. stop(handles.r);
  97. handles.myspeech=getaudiodata(handles.r);
  98. guidata(hObject,handles);

  99. % --- Executes on button press in pushbutton10.
  100. function pushbutton10_Callback(hObject, eventdata, handles)
  101. % hObject    handle to pushbutton10 (see GCBO)
  102. % eventdata  reserved - to be defined in a future version of MATLAB
  103. % handles    structure with handles and user data (see GUIDATA)
  104. [filename,~]=uiputfile({'*.wav'},'保存录音');
  105. if(filename==0)
  106.     return
  107. end
  108. audiowrite(filename,handles.myspeech,44100);
  109. guidata(hObject,handles);

  110. % --- Executes on button press in pushbutton11.
  111. function pushbutton11_Callback(hObject, eventdata, handles)
  112. % hObject    handle to pushbutton11 (see GCBO)
  113. % eventdata  reserved - to be defined in a future version of MATLAB
  114. % handles    structure with handles and user data (see GUIDATA)
  115. sound(handles.myspeech,44100);
  116. guidata(hObject,handles);

  117. % --- Executes on button press in pushbutton12.
  118. function pushbutton12_Callback(hObject, eventdata, handles)
  119. % hObject    handle to pushbutton12 (see GCBO)
  120. % eventdata  reserved - to be defined in a future version of MATLAB
  121. % handles    structure with handles and user data (see GUIDATA)
  122. clear sound;
  123. guidata(hObject,handles);

  124. % --- Executes on button press in pushbutton13.
  125. function pushbutton13_Callback(hObject, ~, handles)
  126. % hObject    handle to pushbutton13 (see GCBO)
  127. % eventdata  reserved - to be defined in a future version of MATLAB
  128. % handles    structure with handles and user data (see GUIDATA)
  129. %plot(handles.fig1,handles.myspeech);
  130. %handles.t=0:1/44100:(length(handles.myspeech)-1)/44100;
  131. handles.y=handles.myspeech;
  132. handles.fs=44100;
  133. handles.sizeOfy=size(handles.y);
  134. handles.t=0:1/handles.fs:(length(handles.y)-1)/handles.fs;
  135. plot(handles.fig1,handles.t,handles.myspeech);
  136. title(handles.fig1,'录音信号时域波形','color','w');
  137. N=length(handles.t);
  138. df=44100/N;
  139. handles.f=[0:df:df*(N-1)]-44100/2;
  140. plot(handles.fig2,handles.f,fftshift(abs(fft(handles.y,N))));
  141. title(handles.fig2,'录音信号频域波形','color','w');
  142. set(handles.fig1,'XColor','w','YColor','w') ;
  143. set(handles.fig2,'XColor','w','YColor','w') ;
  144. guidata(hObject,handles);

  145. % --- Executes on button press in pushbutton1.
  146. function pushbutton1_Callback(hObject, eventdata, handles)
  147. % hObject    handle to pushbutton1 (see GCBO)
  148. % eventdata  reserved - to be defined in a future version of MATLAB
  149. % handles    structure with handles and user data (see GUIDATA)
  150. [filename,filepath]=uigetfile('.wav','选择音频信号');
  151. if(filename==0)
  152.     return
  153. end
  154. audeofile=strcat(filepath,filename);
  155. [handles.y,handles.fs]=audioread(audeofile);
  156. handles.sizeOfy=size(handles.y);
  157. handles.t=0:1/handles.fs:(length(handles.y)-1)/handles.fs;
  158. plot(handles.fig1,handles.t,handles.y);
  159. title(handles.fig1,'音频信号时域波形','color','w');
  160. N=length(handles.t);
  161. df=handles.fs/N;
  162. handles.f=[0:df:df*(N-1)]-handles.fs/2;
  163. handles.fy=fftshift(abs(fft(handles.y,N)));
  164. plot(handles.fig2,handles.f,handles.fy);
  165. title(handles.fig2,'音频信号频域波形','color','w');
  166. set(handles.fig1,'XColor','w','YColor','w') ;
  167. set(handles.fig2,'XColor','w','YColor','w') ;
  168. guidata(hObject, handles);

  169. % --- Executes on button press in pushbutton2.
  170. function pushbutton2_Callback(hObject, eventdata, handles)
  171. % hObject    handle to pushbutton2 (see GCBO)
  172. % eventdata  reserved - to be defined in a future version of MATLAB
  173. % handles    structure with handles and user data (see GUIDATA)
  174. set(handles.uipanel3,'visible','off');
  175. set(handles.uipanel11,'visible','on');
  176. guidata(hObject, handles);


  177. % --- Executes on button press in pushbutton3.
  178. function pushbutton3_Callback(hObject, eventdata, handles)
  179. % hObject    handle to pushbutton3 (see GCBO)
  180. % eventdata  reserved - to be defined in a future version of MATLAB
  181. % handles    structure with handles and user data (see GUIDATA)
  182. %sound(handles.y,0.5*handles.fs);
  183. set(handles.uipanel12,'visible','on');
  184. set(handles.uipanel3,'visible','off');
  185. set(handles.uipanel11,'visible','off');
  186. guidata(hObject,handles);

  187. % --- Executes on button press in pushbutton4.
  188. function pushbutton4_Callback(hObject, eventdata, handles)
  189. % hObject    handle to pushbutton4 (see GCBO)
  190. % eventdata  reserved - to be defined in a future version of MATLAB
  191. % handles    structure with handles and user data (see GUIDATA)
  192. clear sound;
  193. guidata(hObject,handles);


  194. function edit1_Callback(hObject, eventdata, handles)
  195. % hObject    handle to edit1 (see GCBO)
  196. % eventdata  reserved - to be defined in a future version of MATLAB
  197. % handles    structure with handles and user data (see GUIDATA)

  198. % Hints: get(hObject,'String') returns contents of edit1 as text
  199. %        str2double(get(hObject,'String')) returns contents of edit1 as a double


  200. % --- Executes during object creation, after setting all properties.
  201. function edit1_CreateFcn(hObject, eventdata, handles)
  202. % hObject    handle to edit1 (see GCBO)
  203. % eventdata  reserved - to be defined in a future version of MATLAB
  204. % handles    empty - handles not created until after all CreateFcns called

  205. % Hint: edit controls usually have a white background on Windows.
  206. %       See ISPC and COMPUTER.
  207. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  208.     set(hObject,'BackgroundColor','white');
  209. end



  210. function edit2_Callback(hObject, eventdata, handles)
  211. % hObject    handle to edit2 (see GCBO)
  212. % eventdata  reserved - to be defined in a future version of MATLAB
  213. % handles    structure with handles and user data (see GUIDATA)

  214. % Hints: get(hObject,'String') returns contents of edit2 as text
  215. %        str2double(get(hObject,'String')) returns contents of edit2 as a double


  216. % --- Executes during object creation, after setting all properties.
  217. function edit2_CreateFcn(hObject, eventdata, handles)
  218. % hObject    handle to edit2 (see GCBO)
  219. % eventdata  reserved - to be defined in a future version of MATLAB
  220. % handles    empty - handles not created until after all CreateFcns called

  221. % Hint: edit controls usually have a white background on Windows.
  222. %       See ISPC and COMPUTER.
  223. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  224.     set(hObject,'BackgroundColor','white');
  225. end



  226. function edit3_Callback(hObject, eventdata, handles)
  227. % hObject    handle to edit3 (see GCBO)
  228. % eventdata  reserved - to be defined in a future version of MATLAB
  229. % handles    structure with handles and user data (see GUIDATA)

  230. % Hints: get(hObject,'String') returns contents of edit3 as text
  231. %        str2double(get(hObject,'String')) returns contents of edit3 as a double


  232. % --- Executes during object creation, after setting all properties.
  233. function edit3_CreateFcn(hObject, eventdata, handles)
  234. % hObject    handle to edit3 (see GCBO)
  235. % eventdata  reserved - to be defined in a future version of MATLAB
  236. % handles    empty - handles not created until after all CreateFcns called

  237. % Hint: edit controls usually have a white background on Windows.
  238. %       See ISPC and COMPUTER.
  239. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  240.     set(hObject,'BackgroundColor','white');
  241. end



  242. function edit4_Callback(hObject, eventdata, handles)
  243. % hObject    handle to edit4 (see GCBO)
  244. % eventdata  reserved - to be defined in a future version of MATLAB
  245. % handles    structure with handles and user data (see GUIDATA)

  246. % Hints: get(hObject,'String') returns contents of edit4 as text
  247. %        str2double(get(hObject,'String')) returns contents of edit4 as a double


  248. % --- Executes during object creation, after setting all properties.
  249. function edit4_CreateFcn(hObject, eventdata, handles)
  250. % hObject    handle to edit4 (see GCBO)
  251. % eventdata  reserved - to be defined in a future version of MATLAB
  252. % handles    empty - handles not created until after all CreateFcns called

  253. % Hint: edit controls usually have a white background on Windows.
  254. %       See ISPC and COMPUTER.
  255. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  256.     set(hObject,'BackgroundColor','white');
  257. end



  258. function edit5_Callback(hObject, eventdata, handles)
  259. % hObject    handle to edit5 (see GCBO)
  260. % eventdata  reserved - to be defined in a future version of MATLAB
  261. % handles    structure with handles and user data (see GUIDATA)

  262. % Hints: get(hObject,'String') returns contents of edit5 as text
  263. %        str2double(get(hObject,'String')) returns contents of edit5 as a double


  264. % --- Executes during object creation, after setting all properties.
  265. function edit5_CreateFcn(hObject, eventdata, handles)
  266. % hObject    handle to edit5 (see GCBO)
  267. % eventdata  reserved - to be defined in a future version of MATLAB
  268. % handles    empty - handles not created until after all CreateFcns called

  269. % Hint: edit controls usually have a white background on Windows.
  270. %       See ISPC and COMPUTER.
  271. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  272.     set(hObject,'BackgroundColor','white');
  273. end



  274. function edit6_Callback(hObject, eventdata, handles)
  275. % hObject    handle to edit6 (see GCBO)
  276. % eventdata  reserved - to be defined in a future version of MATLAB
  277. % handles    structure with handles and user data (see GUIDATA)

  278. % Hints: get(hObject,'String') returns contents of edit6 as text
  279. %        str2double(get(hObject,'String')) returns contents of edit6 as a double


  280. % --- Executes during object creation, after setting all properties.
  281. function edit6_CreateFcn(hObject, eventdata, handles)
  282. % hObject    handle to edit6 (see GCBO)
  283. % eventdata  reserved - to be defined in a future version of MATLAB
  284. % handles    empty - handles not created until after all CreateFcns called

  285. % Hint: edit controls usually have a white background on Windows.
  286. %       See ISPC and COMPUTER.
  287. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  288.     set(hObject,'BackgroundColor','white');
  289. end


  290. % --- Executes on button press in pushbutton14.
  291. function pushbutton14_Callback(hObject, eventdata, handles)
  292. % hObject    handle to pushbutton14 (see GCBO)
  293. % eventdata  reserved - to be defined in a future version of MATLAB
  294. % handles    structure with handles and user data (see GUIDATA)

  295. %if(handles.fs==0)
  296.     %handles.fs=20000;
  297.     %set(handles.text7,'string','');
  298.     %set(handles.text7,'string','默认fs为2000Hz ');
  299. %end
  300. handles.wp1=str2double(get(handles.edit1,'string'));
  301. handles.wp2=str2double(get(handles.edit2,'string'));
  302. handles.ws1=str2double(get(handles.edit4,'string'));
  303. handles.ws2=str2double(get(handles.edit5,'string'));
  304. handles.wap1=handles.wp1*2/handles.fs;
  305. handles.wap2=handles.wp2*2/handles.fs;
  306. handles.was1=handles.ws1*2/handles.fs;
  307. handles.was2=handles.ws2*2/handles.fs;
  308. rp=str2double(get(handles.edit3,'string'));
  309. rs=str2double(get(handles.edit6,'string'));
  310. handles.dll=get(handles.popupmenu1,'value');
  311. if(rp>0&&rs>rp)
  312.     if(handles.dll==1)
  313.         if(handles.wap2>0&&handles.wap2<handles.was1&&handles.was1<1)
  314.             [handles.n,handles.wn]=buttord(handles.wap2,handles.was1,rp,rs);
  315.             [handles.bz,handles.az]=butter(handles.n,handles.wn,'low');
  316.             [H,F]=freqz(handles.bz,handles.az,400,handles.fs);
  317.             plot(handles.fig3,F,20*log10(abs(H)));
  318.             set(handles.text7,'string','');
  319.             set(handles.text7,'string','参数选择合理');
  320.         else
  321.             set(handles.text7,'string','');
  322.             %n0=strcat(get(handles.text7,'string'),'输入频带不符合要求');
  323.             %set(handles.text7,'string',n0);
  324.             set(handles.text7,'string','输入频带不符合要求');
  325.         end
  326.     elseif(handles.dll==2)
  327.         if(handles.wap1<1&&handles.wap1>handles.was2&&handles.was2>0)
  328.             [handles.n,handles.wn]=buttord(handles.wap1,handles.was2,rp,rs);
  329.             [handles.bz,handles.az]=butter(handles.n,handles.wn,'high');
  330.             [H,F]=freqz(handles.bz,handles.az,400,handles.fs);
  331.             plot(handles.fig3,F,20*log10(abs(H)));
  332.             set(handles.text7,'string','');
  333.             set(handles.text7,'string','参数选择合理');
  334.         else
  335.             set(handles.text7,'string','');
  336.             %n0=strcat(get(handles.text7,'string'),'输入频带不符合要求');
  337.             %set(handles.text7,'string',n0);
  338.             set(handles.text7,'string','输入频带不符合要求');
  339.         end
  340.     elseif(handles.dll==3)
  341.         if(handles.was1>0&&handles.was1<handles.wap1&&handles.wap1<handles.wap2&&handles.wap2<handles.was2&&handles.was2<1)
  342.             handles.wap=[handles.wap1,handles.wap2];
  343.             handles.was=[handles.was1,handles.was2];
  344.             [handles.n,handles.wn]=buttord(handles.wap,handles.was,rp,rs);
  345.             [handles.bz,handles.az]=butter(handles.n,handles.wn,'bandpass');
  346.             [H,F]=freqz(handles.bz,handles.az,400,handles.fs);
  347.             plot(handles.fig3,F,20*log10(abs(H)));
  348.             set(handles.text7,'string','');
  349.             set(handles.text7,'string','参数选择合理');
  350.         else
  351.             %return
  352.             set(handles.text7,'string','');
  353.             %n0=strcat(get(handles.text7,'string'),'输入频带不符合要求');
  354.             %set(handles.text7,'string',n0);
  355.             set(handles.text7,'string','输入频带不符合要求');
  356.         end
  357.     elseif(handles.dll==4)
  358.         if(handles.wap1>0&&handles.wap1<handles.was1&&handles.was1<handles.was2&&handles.was2<handles.wap2&&handles.wap2<1)
  359.             handles.wap=[handles.wap1,handles.wap2];
  360.             handles.was=[handles.was1,handles.was2];
  361.             [handles.n,handles.wn]=buttord(handles.wap,handles.was,rp,rs);
  362.             [handles.bz,handles.az]=butter(handles.n,handles.wn,'stop');
  363.             [H,F]=freqz(handles.bz,handles.az,400,handles.fs);
  364.             plot(handles.fig3,F,20*log10(abs(H)));
  365.             set(handles.text7,'string','');
  366.             set(handles.text7,'string','参数选择合理');
  367.         else
  368.             %return
  369.             set(handles.text7,'string','');
  370.             %n0=strcat(get(handles.text7,'string'),'输入频带不符合要求');
  371.             %set(handles.text7,'string',n0);
  372.             set(handles.text7,'string','输入频带不符合要求');
  373.         end
  374.     end
  375. else
  376.     set(handles.text7,'string','');
  377.     %n0=strcat(get(handles.text7,'string'),'输入增益不符合要求');
  378.     %set(handles.text7,'string',n0);
  379.     set(handles.text7,'string','输入增益不符合要求');
  380. end
  381. set(handles.fig3,'XColor','w','YColor','w') ;
  382. guidata(hObject,handles);

  383. % --- Executes on selection change in popupmenu1.
  384. function popupmenu1_Callback(hObject, eventdata, handles)
  385. % hObject    handle to popupmenu1 (see GCBO)
  386. % eventdata  reserved - to be defined in a future version of MATLAB
  387. % handles    structure with handles and user data (see GUIDATA)

  388. % Hints: contents = cellstr(get(hObject,'String')) returns popupmenu1 contents as cell array
  389. %        contents{get(hObject,'Value')} returns selected item from popupmenu1


  390. % --- Executes during object creation, after setting all properties.
  391. function popupmenu1_CreateFcn(hObject, eventdata, handles)
  392. % hObject    handle to popupmenu1 (see GCBO)
  393. % eventdata  reserved - to be defined in a future version of MATLAB
  394. % handles    empty - handles not created until after all CreateFcns called

  395. % Hint: popupmenu controls usually have a white background on Windows.
  396. %       See ISPC and COMPUTER.
  397. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  398.     set(hObject,'BackgroundColor','white');
  399. end


  400. % --- Executes on button press in pushbutton15.
  401. function pushbutton15_Callback(hObject, eventdata, handles)
  402. % hObject    handle to pushbutton15 (see GCBO)
  403. % eventdata  reserved - to be defined in a future version of MATLAB
  404. % handles    structure with handles and user data (see GUIDATA)
  405. if(handles.y==0)
  406.     set(handles.text8,'string','');
  407.     set(handles.text8,'string','无输入信号');
  408.     return;
  409. else
  410.     handles.yy=filter(handles.bz,handles.az,handles.y);
  411.     plot(handles.fig4,handles.t,handles.yy);
  412.     title(handles.fig4,'滤波后信号时域波形','color','w');
  413.     plot(handles.fig5,handles.f,fftshift(abs(fft(handles.yy,length(handles.yy)))));
  414.     title(handles.fig5,'滤波后信号频域波形','color','w');
  415.     set(handles.fig4,'XColor','w','YColor','w') ;
  416.     set(handles.fig5,'XColor','w','YColor','w') ;
  417.     set(handles.text8,'string','');
  418.     set(handles.text8,'string','输入输出合理');
  419. end
  420. guidata(hObject,handles);

  421. % --- Executes on button press in pushbutton16.
  422. function pushbutton16_Callback(hObject, eventdata, handles)
  423. % hObject    handle to pushbutton16 (see GCBO)
  424. % eventdata  reserved - to be defined in a future version of MATLAB
  425. % handles    structure with handles and user data (see GUIDATA)
  426. [filename,~]=uiputfile({'*.wav'},'保存滤波后音频文件');
  427. if(filename==0)
  428.     return
  429. end
  430. audiowrite(filename,handles.yy,handles.fs);
  431. guidata(hObject,handles);

  432. % --- Executes on button press in pushbutton17.
  433. function pushbutton17_Callback(hObject, eventdata, handles)
  434. % hObject    handle to pushbutton17 (see GCBO)
  435. % eventdata  reserved - to be defined in a future version of MATLAB
  436. % handles    structure with handles and user data (see GUIDATA)
  437. sound(handles.yy,handles.fs);
  438. guidata(hObject,handles);

  439. % --- Executes on button press in pushbutton18.
  440. function pushbutton18_Callback(hObject, eventdata, handles)
  441. % hObject    handle to pushbutton18 (see GCBO)
  442. % eventdata  reserved - to be defined in a future version of MATLAB
  443. % handles    structure with handles and user data (see GUIDATA)
  444. clear sound;
  445. guidata(hObject,handles);


  446. % --- Executes during object creation, after setting all properties.
  447. function uipanel1_CreateFcn(hObject, eventdata, handles)
  448. % hObject    handle to uipanel1 (see GCBO)
  449. % eventdata  reserved - to be defined in a future version of MATLAB
  450. % handles    empty - handles not created until after all CreateFcns called


  451. % --- If Enable == 'on', executes on mouse press in 5 pixel border.
  452. % --- Otherwise, executes on mouse press in 5 pixel border or over pushbutton1.
  453. function pushbutton1_ButtonDownFcn(hObject, eventdata, handles)
  454. % hObject    handle to pushbutton1 (see GCBO)
  455. % eventdata  reserved - to be defined in a future version of MATLAB
  456. % handles    structure with handles and user data (see GUIDATA)


  457. % --- Executes on button press in pushbutton19.
  458. function pushbutton19_Callback(hObject, eventdata, handles)
  459. % hObject    handle to pushbutton19 (see GCBO)
  460. % eventdata  reserved - to be defined in a future version of MATLAB
  461. % handles    structure with handles and user data (see GUIDATA)
  462. handles.t=0:1/handles.fs:(length(handles.y)-1)/handles.fs;
  463. handles.snb=str2double(get(handles.edit7,'string'));
  464. %handles.f0=str2double(get(handles.edit8,'string'));
  465. handles.nll=get(handles.popupmenu2,'value');
  466. if(handles.nll==1)
  467. %     handles.y=handles.y(:,1);
  468. %     handles.t0=0:(length(handles.y)-1)/handles.fs;
  469. %     handles.n=handles.snb*sin(2*pi*handles.f0*handles.t0);
  470.     handles.n=handles.snb*randn(length(handles.y),1);
  471.     handles.y=handles.y+handles.n;
  472. %     if(handles.sizeOfy(2)==1)
  473. %         handles.y=handles.y+handles.n;
  474. %         %handles.y=handles.y+handles.snb*sin(2*pi*handles.f0*handles.t);
  475. %     elseif(handles.sizeOfy(2)==2)
  476. %         handles.y1=handles.y(:,1);
  477. %         handles.y2=handles.y(:,2);
  478. %         handles.y=[handles.y1;handles.y2];
  479. %         handles.t1=0:1/handles.fs:(length(handles.y1)-1)/handles.fs;
  480. %         handles.n1=handles.snb*sin(2*pi*handles.f0*handles.t1);
  481. %         handles.t2=0:1/handles.fs:(length(handles.y2)-1)/handles.fs;
  482. %         handles.n2=handles.snb*sin(2*pi*handles.f0*handles.t2);
  483. %         x=length(handles.y1)
  484. %         y=length(handles.y2)
  485. %         z=length(handles.n1)
  486. %         s=length(handles.n2)
  487. %         m=length(handles.y)
  488. %         handles.y1=handles.y1+handles.n;
  489. %         handles.y2=handles.y2+handles.n;
  490. %         handles.y=[handles.y1,handles.y2];
  491. %         handles.t1=0:(2*(length(handles.y)-1))/handles.fs;
  492. %         handles.n=handles.snb*sin(2*pi*handles.f0*handles.t1);
  493. %         handles.y=handles.y+handles.n;
  494. %     end
  495. elseif(handles.nll==2)
  496.     handles.y=awgn(handles.y,handles.snb);
  497. end
  498. plot(handles.fig1,handles.t,handles.y);
  499. title(handles.fig1,'混入噪声信号时域波形','color','w');
  500. N=length(handles.t);
  501. df=handles.fs/N;
  502. handles.f=[0:df:df*(N-1)]-handles.fs/2;
  503. handles.fy=fftshift(abs(fft(handles.y,N)));
  504. plot(handles.fig2,handles.f,handles.fy);
  505. title(handles.fig2,'混入噪声信号频域波形','color','w');
  506. set(handles.fig1,'XColor','w','YColor','w') ;
  507. set(handles.fig2,'XColor','w','YColor','w') ;
  508. guidata(hObject,handles);


  509. function edit8_Callback(hObject, eventdata, handles)
  510. % hObject    handle to edit8 (see GCBO)
  511. % eventdata  reserved - to be defined in a future version of MATLAB
  512. % handles    structure with handles and user data (see GUIDATA)

  513. % Hints: get(hObject,'String') returns contents of edit8 as text
  514. %        str2double(get(hObject,'String')) returns contents of edit8 as a double


  515. % --- Executes during object creation, after setting all properties.
  516. function edit8_CreateFcn(hObject, eventdata, handles)
  517. % hObject    handle to edit8 (see GCBO)
  518. % eventdata  reserved - to be defined in a future version of MATLAB
  519. % handles    empty - handles not created until after all CreateFcns called

  520. % Hint: edit controls usually have a white background on Windows.
  521. %       See ISPC and COMPUTER.
  522. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  523.     set(hObject,'BackgroundColor','white');
  524. end



  525. function edit7_Callback(hObject, eventdata, handles)
  526. % hObject    handle to edit7 (see GCBO)
  527. % eventdata  reserved - to be defined in a future version of MATLAB
  528. % handles    structure with handles and user data (see GUIDATA)

  529. % Hints: get(hObject,'String') returns contents of edit7 as text
  530. %        str2double(get(hObject,'String')) returns contents of edit7 as a double


  531. % --- Executes during object creation, after setting all properties.
  532. function edit7_CreateFcn(hObject, eventdata, handles)
  533. % hObject    handle to edit7 (see GCBO)
  534. % eventdata  reserved - to be defined in a future version of MATLAB
  535. % handles    empty - handles not created until after all CreateFcns called

  536. % Hint: edit controls usually have a white background on Windows.
  537. %       See ISPC and COMPUTER.
  538. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  539.     set(hObject,'BackgroundColor','white');
  540. end


  541. % --- Executes on selection change in popupmenu2.
  542. function popupmenu2_Callback(hObject, eventdata, handles)
  543. % hObject    handle to popupmenu2 (see GCBO)
  544. % eventdata  reserved - to be defined in a future version of MATLAB
  545. % handles    structure with handles and user data (see GUIDATA)

  546. % Hints: contents = cellstr(get(hObject,'String')) returns popupmenu2 contents as cell array
  547. %        contents{get(hObject,'Value')} returns selected item from popupmenu2


  548. % --- Executes during object creation, after setting all properties.
  549. function popupmenu2_CreateFcn(hObject, eventdata, handles)
  550. % hObject    handle to popupmenu2 (see GCBO)
  551. % eventdata  reserved - to be defined in a future version of MATLAB
  552. % handles    empty - handles not created until after all CreateFcns called

  553. % Hint: popupmenu controls usually have a white background on Windows.
  554. %       See ISPC and COMPUTER.
  555. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  556.     set(hObject,'BackgroundColor','white');
  557. end


  558. % --- Executes on button press in pushbutton20.
  559. function pushbutton20_Callback(hObject, eventdata, handles)
  560. % hObject    handle to pushbutton20 (see GCBO)
  561. % eventdata  reserved - to be defined in a future version of MATLAB
  562. % handles    structure with handles and user data (see GUIDATA)
  563. set(handles.uipanel11,'visible','off');
  564. set(handles.uipanel3,'visible','on');
  565. guidata(hObject,handles);


  566. % --- Executes during object creation, after setting all properties.
  567. function pushbutton14_CreateFcn(hObject, eventdata, handles)
  568. % hObject    handle to pushbutton14 (see GCBO)
  569. % eventdata  reserved - to be defined in a future version of MATLAB
  570. % handles    empty - handles not created until after all CreateFcns called


  571. % --- Executes on selection change in popupmenu3.
  572. function popupmenu3_Callback(hObject, eventdata, handles)
  573. % hObject    handle to popupmenu3 (see GCBO)
  574. % eventdata  reserved - to be defined in a future version of MATLAB
  575. % handles    structure with handles and user data (see GUIDATA)

  576. % Hints: contents = cellstr(get(hObject,'String')) returns popupmenu3 contents as cell array
  577. %        contents{get(hObject,'Value')} returns selected item from popupmenu3


  578. % --- Executes during object creation, after setting all properties.
  579. function popupmenu3_CreateFcn(hObject, eventdata, handles)
  580. % hObject    handle to popupmenu3 (see GCBO)
  581. % eventdata  reserved - to be defined in a future version of MATLAB
  582. % handles    empty - handles not created until after all CreateFcns called

  583. % Hint: popupmenu controls usually have a white background on Windows.
  584. %       See ISPC and COMPUTER.
  585. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  586.     set(hObject,'BackgroundColor','white');
  587. end


  588. % --- Executes on selection change in popupmenu4.
  589. function popupmenu4_Callback(hObject, eventdata, handles)
  590. % hObject    handle to popupmenu4 (see GCBO)
  591. % eventdata  reserved - to be defined in a future version of MATLAB
  592. % handles    structure with handles and user data (see GUIDATA)

  593. % Hints: contents = cellstr(get(hObject,'String')) returns popupmenu4 contents as cell array
  594. %        contents{get(hObject,'Value')} returns selected item from popupmenu4


  595. % --- Executes during object creation, after setting all properties.
  596. function popupmenu4_CreateFcn(hObject, eventdata, handles)
  597. % hObject    handle to popupmenu4 (see GCBO)
  598. % eventdata  reserved - to be defined in a future version of MATLAB
  599. % handles    empty - handles not created until after all CreateFcns called

  600. % Hint: popupmenu controls usually have a white background on Windows.
  601. %       See ISPC and COMPUTER.
  602. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  603.     set(hObject,'BackgroundColor','white');
  604. end


  605. % --- Executes on button press in pushbutton21.
  606. function pushbutton21_Callback(hObject, eventdata, handles)
  607. % hObject    handle to pushbutton21 (see GCBO)
  608. % eventdata  reserved - to be defined in a future version of MATLAB
  609. % handles    structure with handles and user data (see GUIDATA)
  610. %handles.v1=str2double(get(handles.popupmenu3,'value'));
  611. handles.v1=get(handles.popupmenu3,'value');
  612. handles.v2=get(handles.popupmenu3,'string');
  613. handles.vo=str2double(handles.v2(handles.v1));
  614. %handles.v3=str2double(get(handles.popupmenu4,'value'));
  615. handles.v3=get(handles.popupmenu4,'value');
  616. handles.v4=get(handles.popupmenu4,'string');
  617. handles.ve=str2double(handles.v4(handles.v3));
  618. sound(handles.vo.*handles.y,handles.ve.*handles.fs);
  619. guidata(hObject,handles);

  620. % --- Executes on button press in pushbutton22.
  621. function pushbutton22_Callback(hObject, eventdata, handles)
  622. % hObject    handle to pushbutton22 (see GCBO)
  623. % eventdata  reserved - to be defined in a future version of MATLAB
  624. % handles    structure with handles and user data (see GUIDATA)
  625. set(handles.uipanel12,'visible','off');
  626. set(handles.uipanel3,'visible','on');
  627. guidata(hObject,handles);
复制代码


全部资料51hei下载地址:
语音滤波器.rar (115.3 KB, 下载次数: 29)


评分

参与人数 1黑币 +50 收起 理由
admin + 50 共享资料的黑币奖励!

查看全部评分

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

沙发
ID:319014 发表于 2019-3-27 11:47 | 只看该作者
什么用啊
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表