www.pudn.com > dspproject.rar > untitled.m, change:2016-10-20,size:4525b


function varargout = untitlded(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 20-Oct-2016 09:24:02

% 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 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)
[filename, pathname] = uigetfile( ...
    {'*.wav;*.flac;*.mp4','All Image Files';...
    '*.*','All Files' },...
    '打开文件', ...
    'MultiSelect', 'on');
if isequal(filename,0)
   disp('User selected Cancel')
else
   disp(['User selected', fullfile(pathname, filename)])
end

[xx,fs]=audioread(fullfile(pathname, filename));                    % 读入数据文件

xx=xx(:,1);


xx=xx-mean(xx);                         % mean:求矩阵各列均值 消除直流分量
x=xx/max(abs(xx));                      % 幅值归一化

N=length(x);                            % 信号长度
time=(0:N-1)/fs;                        % 设置时间

IS=.15;                                 % 设置IS
% 调用WienerScalart96m_2函数做维纳滤波
output=WienerScalart96m_2(xx,fs,IS,0.12);
ol=length(output);                      % 把output补到与x等长
if ol<N
    output=[output; zeros(N-ol,1)];
end
snr=SNR_singlech(x,output);            % 计算维纳滤波后的信噪比

fp1=1200;
fs1=2000;
wp1=2*fp1/fs;%设定低通滤波器通带截止频率和阻带截止频率
ws1=2*fs1/fs;
rp=1;
as=100;
[N1,wp1]=ellipord(wp1,ws1,rp,as);%计算椭圆低通模拟滤波器的阶数和通带边界频率
[B,A]=ellip(N1,rp,as,wp1);%计算低通滤波器模拟滤波器系统函数系数 
output1=filter(B,A,output);
subplot(2,2,1)
plot(time,x,'k'); grid; axis tight;
title('噪音语音波形'); ylabel('幅值'); xlabel('时间/s');
subplot(2,2,2)
plot(time,output,'r'); grid; axis tight;
title('去噪后语音波形'); ylabel('幅值'); xlabel('时间/s');

sound(output1,fs);