MATLAB 音频降噪 GUI 应用 - 基于小波变换的降噪算法
function varargout = untitled(varargin) % UNTITLED MATLAB code for untitled.fig % UNTITLED, by itself, creates a new UNTITLED or raises the existing % singleton*. % % H = UNTITLED returns the handle to a new UNTITLED or the handle to % the existing singleton*. % % UNTITLED('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in UNTITLED.M with the given input arguments. % % UNTITLED('Property','Value',...) creates a new UNTITLED or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before untitled_OpeningFcn gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to untitled_OpeningFcn via varargin. % % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one % instance to run (singleton)". % % See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help untitled
% Last Modified by GUIDE v2.5 10-Mar-2023 20:37:30
% Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @untitled_OpeningFcn, ... 'gui_OutputFcn', @untitled_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 untitled is made visible. function untitled_OpeningFcn(hObject, eventdata, handles, varargin) % This function has no output args, see 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 untitled (see VARARGIN)
% Choose default command line output for untitled handles.output = hObject;
% Update handles structure guidata(hObject, handles);
% UIWAIT makes untitled wait for user response (see UIRESUME) % uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line. function varargout = untitled_OutputFcn(hObject, eventdata, handles) % varargout 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 structure varargout{1} = handles.output;
% --- Executes on button press in pushbutton1. function pushbutton1_Callback(hObject, eventdata, handles) % hObject handle to pushbutton1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) recObj=audiorecorder; disp('Start recording.'); recordblocking(recObj,5);%从麦克风录取20s音频 disp('End of recording.'); play(recObj); y=getaudiodata(recObj); filename='D:\graduation design\Recorded audio\recording.wav'; audiowrite(filename,y,12000); [Y,FS]=audioread(filename); player=audioplayer(Y,FS); info=audioinfo(filename);
% --- Executes on button press in pushbutton2. function pushbutton2_Callback(hObject, eventdata, handles) % hObject handle to pushbutton2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global x; %文件 global Fs; %采样频率 global tl; global x2; [filename, pathname] = uigetfile('*.wav', '选择音频文件'); if isequal(filename,0) disp('User selected Cancel') else path = fullfile(pathname, filename); [handles.x,handles.Fs]=audioread(path); x=handles.x; Fs=handles.Fs; axes(handles.axes1); tl=[0:1/Fs:(length(handles.x)-1)/Fs]; %时间尺度 plot(tl,handles.x); title('语音时域波形'); xlabel('时间/s'); grid on; %player=audioplayer(x,Fs);
N=length(handles.x); df=Fs/N; w=[0:df:df*(N-1)] - Fs/2; %频率尺度 X=fft(handles.x); X=fftshift(X); %axes(handles.axes2); %plot(w,abs(X)/max(abs(X))); %axis([-10000,10000,0,1]); %title('语音频谱'); %xlabel('频率/Hz'); %grid on; %x2=x;
%二、小波降噪wden函数 具体参数选取 原理+结合人耳试听 %wname = 'coif5';'db2';'sym4' [Y,FS]=audioread(path); %将声音放到matlab中 info=audioinfo(path); %得到声音的格式、数位、频率等 T=1/FS; %采样时间 t=(0:length(Y)-1)*T;%时间 yz=Y(:,1);%左声道 lev=15;
xdDWT= wden(yz,'heursure','h','mln',lev,'db3'); player=audioplayer(xdDWT,Fs); %[dnsig4s,c4,l4,threshold_heursure] = wden(yz,'heursure','h','mln',lev,wname); axes(handles.axes2); plot(t,xdDWT); title('降噪后波形');
end
% --- Executes on button press in pushbutton3. function pushbutton3_Callback(hObject, eventdata, handles) % hObject handle to pushbutton3 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global player; global xdDWT; global Fs;
% 检查音频数据是否为空 if ~isempty(xdDWT) player=audioplayer(xdDWT,Fs); play(player); end
% --- Executes on button press in pushbutton4. function pushbutton4_Callback(hObject, eventdata, handles) % hObject handle to pushbutton4 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global player; global x; global Fs;
pause(player);
% --- Executes on button press in pushbutton5. function pushbutton5_Callback(hObject, eventdata, handles) % hObject handle to pushbutton5 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global player; global x; global Fs;
stop(player); %clear sound;
% --- 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) global player; global x; global Fs;
resume(player);
原文地址: https://www.cveoy.top/t/topic/nG6k 著作权归作者所有。请勿转载和采集!