语音信号matlab+GUI滤波处理_第1页
语音信号matlab+GUI滤波处理_第2页
语音信号matlab+GUI滤波处理_第3页
语音信号matlab+GUI滤波处理_第4页
语音信号matlab+GUI滤波处理_第5页
已阅读5页,还剩9页未读, 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、function varargout = digitalfilter(varargin)% DIGITALFILTER MATLAB code for digitalfilter.fig% DIGITALFILTER, by itself, creates a new DIGITALFILTER or raises the existing% singleton*.% H = DIGITALFILTER returns the handle to a new DIGITALFILTER or the handle to% the existing singleton*.% DIGITALFIL

2、TER('CALLBACK',hObject,eventData,handles,.) calls the local% function named CALLBACK in DIGITALFILTER.M with the given input arguments.% DIGITALFILTER('Property','Value',.) creates a new DIGITALFILTER or raises the% existing singleton*. Starting from the left, property value

3、pairs are% applied to the GUI before digitalfilter_OpeningFcn gets called. An% unrecognized property name or invalid value makes property application% stop. All inputs are passed to digitalfilter_OpeningFcn via varargin.% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one%

4、instance to run (singleton)".% See also: GUIDE, GUIDATA, GUIHANDLES% Edit the above text to modify the response to help digitalfilter% Last Modified by GUIDE v2.5 11-Dec-2013 15:44:57% Begin initialization code - DO NOT EDITgui_Singleton = 1;gui_State = struct('gui_Name', mfilename, . &

5、#39;gui_Singleton', gui_Singleton, . 'gui_OpeningFcn', digitalfilter_OpeningFcn, . 'gui_OutputFcn', digitalfilter_OutputFcn, . 'gui_LayoutFcn', , . 'gui_Callback', );if nargin && ischar(varargin1) gui_State.gui_Callback = str2func(varargin1);endif nargout

6、varargout1:nargout = gui_mainfcn(gui_State, varargin:);else gui_mainfcn(gui_State, varargin:);end% End initialization code - DO NOT EDIT% - Executes just before digitalfilter is made visible.function digitalfilter_OpeningFcn(hObject, eventdata, handles, varargin)% This function has no output args, s

7、ee OutputFcn.% hObject handle to figure% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% varargin command line arguments to digitalfilter (see VARARGIN)% Choose default command line output for digitalfilterhandles.output =

8、 hObject;% Update handles structureguidata(hObject, handles);% UIWAIT makes digitalfilter wait for user response (see UIRESUME)% uiwait(handles.figure1);% - Outputs from this function are returned to the command line.function varargout = digitalfilter_OutputFcn(hObject, eventdata, handles) % varargo

9、ut cell array for returning output args (see VARARGOUT);% hObject handle to figure% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Get default command line output from handles structurevarargout1 = handles.output;function

10、 filtering_Callback(hObject, eventdata, handles) %m_filter_choice_string=get(handles.m_filter_choice,'String');%读取此时设计的滤波器的类型,“Howpass、Lowpass、Bandpass、Bandstop” %set(handles.play_af,'Visible','off'); filter_order_value=str2num(get(handles.filter_order,'String'); filt

11、er_startf_value=str2num(get(handles.filter_startf,'String'); filter_stopf_value=str2num(get(handles.filter_stopf,'String'); filtering_value=get(handles.filtering,'Value'); global fs; N=filter_order_value; if(get(handles.filter_hp,'Value')=1) wn=filter_stopf_value/fs*2

12、; b=fir1(N,wn,'high'); end if(get(handles.filter_lp,'Value')=1) wn=filter_stopf_value/fs*2; b=fir1(N,wn,'low'); end if(get(handles.filter_bp,'Value')=1) w1=filter_startf_value/fs*2; w2=filter_stopf_value/fs*2; b=fir1(N,w1 w2,'bandpass'); end if(get(handles.fil

13、ter_bs,'Value')=1) w1=filter_startf_value/fs*2; w2=filter_stopf_value/fs*2; b=fir1(N,w1 w2,'DC-1'); end%设计滤波器/用下拉菜单实现% switch m_filter_choice_string% case HP%高通% wn=filter_stopf_value/44100*2;% b=fir1(N,wn,'high');% case LP%低通% wn=filter_stopf_value/44100*2;% b=fir1(N,wn,'

14、;low');% case BP%带通% w1=filter_startf_value/44100*2;% w2=w1+filter_band/44100*2;% b=fir1(N,w1 w2,'bandpass');% case BS%带阻% w1=filter_startf_value/44100*2;% w2=w1+filter_band/44100*2;% b=fir1(N,w1 w2,'DC-1');% end; % 滤波处理 if(filtering_value=1)% fs=44100; %语音信号采样频率为22050% x=wavread

15、('C:Documents and SettingsCYJ-714My DocumentsMATLABmeiname.wav'); %读取语音信号的数据,赋给变量x% x1=x(:,2);%抽取一声道% t=(0:length(x1)-1)/44100% % X1=fft(x1,1024); %对信号做1024点FFT变 global fs; global xx1;%xx1是截取后的音频信号 x1=xx1; t=(0:length(xx1)-1)/44100; f=fs*(0:511)/1024; s=filter(b,1,x1); S1=fft(s,1024); %对信号做1

16、024点FFT变换 %画出图形*4% axes(handles.m_filter);% freqz(b,1); %生成频率响应参数 %set(handles.m_filter,'XminorTick','on') % axes(handles.m_signal_be);% plot(t,x1,'g');% hold on;% plot(t,s,'r');% legend('a','b');% title('原始语音信号');xlabel('time');ylabel(

17、'magnitude');% axis('manual');% hold on; %set(handles.m_signal_be,'XminorTick','on') axes(handles.m_signal_af) plot(t,s); %axis(0 10 -0.8 0.8); title('滤波后语音信号');xlabel('time');ylabel('magnitude'); %set(handles.m_signal_af,'XminorTick',&

18、#39;on') % axes(handles.m_fft_be);% axis auto;% plot(f,abs(X1(1:512),'g');% hold on;% plot(f,abs(S1(1:512),'r');% legend;% title('原始语音信号频谱');xlabel('frequency');ylabel('magnitude');% axis('manual');% hold on; %set(handles.m_fft_be,'XminorTick&#

19、39;,'on') axes(handles.m_fft_af); plot(f,abs(S1(1:512); %axis(0 25000 0 14); title('滤波后语音信号频谱');xlabel('frequency');ylabel('magnitude'); axes(handles.m_filter); H=fft(b,1024);%求出它的DFT变换,然后用plot分别画图即可。 plot(1:512/1024*fs,20*log10(abs(H(1:512); %这个是幅频特性衰减函数 %plot(angle(

20、H); %这个是相频特性,% h,f1=freqz(b,1); %生成频率响应参数% subplot(2,1,1);% plot(f1,abs(h) ;%画幅频响应图% subplot(2,1,2);% plot(f1,angle(h); %画相频响应图% handles.song=s1; global m_song;%m_song是滤波后的音频信号 m_song=s; end% wavwrite(s1,44100,'C:Documents and SettingsCYJ-714My DocumentsMATLABflanger.wav'); guidata(hObject,h

21、andles); % hObject handle to m_execute (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% hObject handle to m_filter_choice (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles str

22、ucture with handles and user data (see GUIDATA)% Hints: contents = cellstr(get(hObject,'String') returns m_filter_choice contents as cell array% contentsget(hObject,'Value') returns selected item from m_filter_choice% hObject handle to m_execute (see GCBO)% eventdata reserved - to be

23、 defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% hObject handle to m_filter_choice (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Hints: contents = cellstr(ge

24、t(hObject,'String') returns m_filter_choice contents as cell array% contentsget(hObject,'Value') returns selected item from m_filter_choicefunction play_af_Callback(hObject, eventdata, handles)% S=wavread('C:Documents and SettingsCYJ-714My DocumentsMATLABmeiname.wav'); % soun

25、d(S,44100);% set(handles.play_af,'UserData',1); global m_song; global fs; m_m_song=m_song; sound(m_m_song,fs); % m_song=handles.song% sound(m_m_song,44100);% i=1;% % sound(S1,44100);% while(get(handles.play_af,'UserData')=1)% if (i<=3)%总长度为6秒% sound(m_m_song(i-1)*fs/10+1:i*fs/10),

26、fs);% i=i+1;% end% end guidata(hObject,handles); % function stopplay_af_Callback(hObject, eventdata, handles)% set(handles.play_af,'UserData',0);% guidata(hObject,handles);% function m_filter_choice_Callback(hObject, eventdata, handles)% m_filter_choice_value=get(handles.m_filter_choice,'

27、;String');%读取此时设计的滤波器的类型,“Howpass、Lowpass、Bandpass、Bandstop”% %当选择Lowpass或者Highpass,屏蔽相应的临界频率的显示% if(m_filter_choice_value=HP)|(m_filter_choice_value=LP) % set(handles.filter_order,'visible','on');% set(handles.filter_band,'visible','off');% set(handles.filter_sto

28、pf,'visible','on');% set(handles.filter_starf,'visible','off');% else % %当选择Bandpass或者Bandstop,使相应的临界频率的显示,使参数能够输入% if(m_filter_choice_value=BP)|(m_filter_choice_value=BS) % set(handles.m_order,'visible','on');% set(handles.m_stopf,'visible',&#

29、39;off');% set(handles.m_startf,'visible','on');% set(handles.m_band,'visible','on'); % end% end% function m_filter_choice_CreateFcn(hObject, eventdata, handles)% % % Hint: popupmenu controls usually have a white background on Windows.% % See ISPC and COMPUTER.% i

30、f ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')% set(hObject,'BackgroundColor','white');% endfunction filter_order_Callback(hObject, eventdata, handles) filter_order_value=str2num(get(handles.filter_order,'String&

31、#39;);%在按键调用时也要加上 if (isempty(filter_order_value) set(hObject,'String','1') %无输入时,设为0end% function filter_order_CreateFcn(hObject, eventdata, handles)% % % Hint: edit controls usually have a white background on Windows.% % See ISPC and COMPUTER.% if ispc && isequal(get(hObjec

32、t,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')% set(hObject,'BackgroundColor','white');% endfunction filter_band_Callback(hObject, eventdata, handles)% % function filter_band_CreateFcn(hObject, eventdata, handles)% % % Hint: edit controls usually have

33、a white background on Windows.% % See ISPC and COMPUTER.% if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')% set(hObject,'BackgroundColor','white');% endfunction filter_hp_Callback(hObject, eventdata, handles) input=ge

34、t(handles.filter_hp,'Value');%读取此时设计的滤波器的类型,“Howpass、Lowpass、Bandpass、Bandstop”%当选择Lowpass或者Highpass,屏蔽相应的临界频率的显示 if(input=1) set(handles.filter_stopf,'visible','on'); set(handles.filter_startf,'visible','off'); set(handles.filter_lp,'Visible','off

35、'); set(handles.filter_bp,'Visible','off'); set(handles.filter_bs,'Visible','off'); else if(input=0) set(handles.filter_lp,'Visible','on'); set(handles.filter_bp,'Visible','on'); set(handles.filter_bs,'Visible','on')

36、; set(handles.filter_hp,'Visible','on'); set(handles.filter_stopf,'visible','on'); set(handles.filter_startf,'visible','on'); end endfunction filter_lp_Callback(hObject, eventdata, handles) input=get(handles.filter_lp,'Value');%读取此时设计的滤波器的类型,“H

37、owpass、Lowpass、Bandpass、Bandstop”%当选择Lowpass或者Highpass,屏蔽相应的临界频率的显示 if(input=1) set(handles.filter_stopf,'visible','on'); set(handles.filter_startf,'visible','off'); set(handles.filter_hp,'Visible','off'); set(handles.filter_bp,'Visible','o

38、ff'); set(handles.filter_bs,'Visible','off'); else if(input=0) set(handles.filter_lp,'Visible','on'); set(handles.filter_bp,'Visible','on'); set(handles.filter_bs,'Visible','on'); set(handles.filter_hp,'Visible','on'

39、); set(handles.filter_stopf,'visible','on'); set(handles.filter_startf,'visible','on'); end endfunction filter_bp_Callback(hObject, eventdata, handles) input=get(handles.filter_bp,'Value');%读取此时设计的滤波器的类型,“Howpass、Lowpass、Bandpass、Bandstop”%当选择Lowpass或者Highpass

40、,屏蔽相应的临界频率的显示 if(input=1) set(handles.filter_stopf,'visible','on'); set(handles.filter_startf,'visible','on'); set(handles.filter_lp,'Visible','off'); set(handles.filter_hp,'Visible','off'); set(handles.filter_bs,'Visible','

41、off'); else if(input=0) set(handles.filter_lp,'Visible','on'); set(handles.filter_bp,'Visible','on'); set(handles.filter_bs,'Visible','on'); set(handles.filter_hp,'Visible','on'); set(handles.filter_stopf,'visible','on&#

42、39;); set(handles.filter_startf,'visible','on'); end endfunction filter_bs_Callback(hObject, eventdata, handles) input=get(handles.filter_bs,'Value');%读取此时设计的滤波器的类型,“Howpass、Lowpass、Bandpass、Bandstop”%当选择Lowpass或者Highpass,屏蔽相应的临界频率的显示 if(input=1) set(handles.filter_stopf,'

43、;visible','on'); set(handles.filter_startf,'visible','on'); set(handles.filter_lp,'Visible','off'); set(handles.filter_bp,'Visible','off'); set(handles.filter_hp,'Visible','off'); else if(input=0) set(handles.filter_lp,'

44、Visible','on'); set(handles.filter_bp,'Visible','on'); set(handles.filter_bs,'Visible','on'); set(handles.filter_hp,'Visible','on'); set(handles.filter_stopf,'visible','on'); set(handles.filter_startf,'visible','

45、on'); end endfunction showing_Callback(hObject, eventdata, handles) showing_value=get(handles.showing,'Value'); if(showing_value=1)% fs=44100; %语音信号采样频率为44100 % x=audioread('C:Documents and SettingsCYJ-714My DocumentsMATLABmeiname.wav'); %读取语音信号的数据,赋给变量x% x_1=x(:,2);%抽取一声道% globa

46、l song_length;% song_length=length(x_1); global song_start; % global File_name;% x1=audioread(filename,song_start:song_start+10*fs); global fs; global File_name; x11=audioread(File_name,song_start (song_start+10*fs); x1=x11(:,1); t=(0:length(x1)-1)/fs; f=fs*(0:511)/1024; X1=fft(x1,1024); %对信号做FFT变 a

47、xes(handles.m_signal_be); plot(t,x1); title('原始语音信号');xlabel('time');ylabel('magnitude'); axes(handles.m_fft_be); plot(f,abs(X1(1:512); title('原始语音信号频谱');xlabel('frequency');ylabel('magnitude'); global xx1;%从整个音频中截取出的一段信号 xx1=x1; end% wavwrite(s1,44100

48、,'C:Documents and SettingsCYJ-714My DocumentsMATLABflanger.wav'); guidata(hObject,handles);function song_slider_Callback(hObject, eventdata, handles)% function song_slider_CreateFcn(hObject, eventdata, handles)% % % Hint: slider controls usually have a light gray background.% if isequal(get(

49、hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')% set(hObject,'BackgroundColor',.9 .9 .9);% endfunction set_start_Callback(hObject, eventdata, handles)%load chuandi.mat% x Fs=audioread(filename); %读取语音信号的数据,赋给变量x load chuandi.mat; global File_name; File_name=filename; x Fs=audioread(File_name,'native

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论