0
点赞
收藏
分享

微信扫一扫

【语音去噪】基于FIR滤波器实现音频去噪含Matlab源码

1 简介

结合数字滤波器的理论基础和设计方法,在MATLAB程序语言环境下,设计出有限长单位脉冲响应(FIR)数字滤波器,同时利用GUI界面设计FIR数字滤波器人机交互平台,该系统平台界面直观、操作简单且功能齐全,可实现对加噪语音信号的去噪滤波功能.平台主要包括语音信号、加噪信号、FIR数字滤波器设计和去噪信号四个模块,用户可根据读入的语音信号及噪声信号特点调整滤波器技术指标,实现滤波器的优化设计,最终达到FIR数字滤波器对语音信号的去噪处理效果.​

2 部分代码

function varargout = yanshou(varargin)

% YANSHOU M-file for yanshou.fig

%      YANSHOU, by itself, creates a new YANSHOU or raises the existing

%      singleton*.

%

%      H = YANSHOU returns the handle to a new YANSHOU or the handle to

%      the existing singleton*.

%

%      YANSHOU('CALLBACK',hObject,eventData,handles,...) calls the local

%      function named CALLBACK in YANSHOU.M with the given input arguments.

%

%      YANSHOU('Property','Value',...) creates a new YANSHOU or raises the

%      existing singleton*.  Starting from the left, property value pairs are

%      applied to the GUI before yanshou_OpeningFcn gets called.  An

%      unrecognized property name or invalid value makes property application

%      stop.  All inputs are passed to yanshou_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 yanshou

% Last Modified by GUIDE v2.5 23-Apr-2020 14:20:34

% Begin initialization code - DO NOT EDIT

gui_Singleton = 1;

gui_State = struct('gui_Name',       mfilename, ...

                   'gui_Singleton',  gui_Singleton, ...

                   'gui_OpeningFcn', @yanshou_OpeningFcn, ...

                   'gui_OutputFcn',  @yanshou_OutputFcn, ...

                   'gui_LayoutFcn',  [] , ...

                   'gui_Callback',   []);

if nargin && ischar(varargin{1})

    gui_State.gui_Callback = str2func(varargin{1});

    plot(w/pi*Fs/2,20*log(abs(h))); 

    x1=fftfilt(b2,x1);

    elseif get(handles.radiobutton6,'value')

   b2=fir1(30, [fp/Fs fs/Fs],'stop', triang(31)); 

    axes(handles.axes3);

    [h,w]=freqz(b2, 1,512); 

    plot(w/pi*Fs/2,20*log(abs(h))); 

    x1=fftfilt(b2,x1);

    elseif get(handles.radiobutton7,'value')

    b2=fir1(30, [fp/Fs fs/Fs], 'stop',hanning(31)); 

    axes(handles.axes3);

    [h,w]=freqz(b2, 1,512); 

    plot(w/pi*Fs/2,20*log(abs(h))); 

    x1=fftfilt(b2,x1);

    elseif get(handles.radiobutton8,'value')

    b2=fir1(30, [fp/Fs fs/Fs], 'stop',blackman(31)); 

    axes(handles.axes3);

    [h,w]=freqz(b2, 1,512); 

    plot(w/pi*Fs/2,20*log(abs(h))); 

    x1=fftfilt(b2,x1);

    elseif get(handles.radiobutton9,'value')

    b2=fir1(30, [fp/Fs fs/Fs],'stop',kaiser(31)); 

    axes(handles.axes3);

    [h,w]=freqz(b2, 1,512); 

    plot(w/pi*Fs/2,20*log(abs(h))); 

    x1=fftfilt(b2,x1);

end;

axes(handles.axes5);

plot(tl,x1);

title('滤除噪声后语音时域波形');

xlabel('时间/s');

N=length(x1);

df=Fs/N;

w=[0:df:df*(N-1)] - Fs/2; %频率尺度

X=fft(x1);

X=fftshift(X);

axes(handles.axes6);

plot(w,abs(X)/max(abs(X)));

axis([-10000,10000,0,1]);

title('滤除噪声后语音频谱');

xlabel('频率/Hz');

grid on;

x2=x1;

% --- Executes on button press in radiobutton1.

function radiobutton1_Callback(hObject, eventdata, handles)

% hObject    handle to radiobutton1 (see GCBO)

% eventdata  reserved - to be defined in a future version of MATLAB

% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of radiobutton1

% --- Executes on button press in radiobutton2.

function radiobutton2_Callback(hObject, eventdata, handles)

% hObject    handle to radiobutton2 (see GCBO)

% eventdata  reserved - to be defined in a future version of MATLAB

% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of radiobutton2

% --- Executes on button press in invert_pushbutton12.

function invert_pushbutton12_Callback(hObject, eventdata, handles)

% hObject    handle to invert_pushbutton12 (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 x2;

N=length(x);

for i=1:1:N

    x2(i)= x(N-i+1);

end;

            case 1

建一个不可见的figure

    new_axes=copyobj(handles.axes5,new_f_handle); %axes1是GUI界面内要保存图线的Tag,将其copy到不可见的figure中

    set(new_axes,'Units','normalized','Position',[0.1 0.1 0.8 0.8]);%将图线缩放

    [filename pathname fileindex]=uiputfile({'*.png';'*.bmp';'*.jpg';'*.eps';},'图片保存为');

    if  filename~=0%未点“取消”按钮或未关闭

        file=strcat(pathname,filename);

        switch fileindex %根据不同的选择保存为不同的类型        

            case 1

                print(new_f_handle,'-dpng',file);% print(new_f_handle,'-dpng',filename);效果一样,将图像打印到指定文件中

                fprintf('>>已保存到:%s\n',file);

            case 2

                print(new_f_handle,'-dbmp',file);

                fprintf('>>已保存到:%s\n',file);

            case 3

                print(new_f_handle,'-djpeg',file);

                fprintf('>>已保存到:%s\n',file);

            case 4

                print(new_f_handle,'-depsc',file);

                fprintf('>>已保存到:%s\n',file);

        end 

        msgbox('          图线已成功保存!','完成!');

    end

    new_f_handle=figure('visible','off'); %新建一个不可见的figure

    new_axes=copyobj(handles.axes6,new_f_handle); %axes1是GUI界面内要保存图线的Tag,将其copy到不可见的figure中

    set(new_axes,'Units','normalized','Position',[0.1 0.1 0.8 0.8]);%将图线缩放

    [filename pathname fileindex]=uiputfile({'*.png';'*.bmp';'*.jpg';'*.eps';},'图片保存为');

    if  filename~=0%未点“取消”按钮或未关闭

        file=strcat(pathname,filename);

        switch fileindex %根据不同的选择保存为不同的类型        

            case 1

                print(new_f_handle,'-dpng',file);% print(new_f_handle,'-dpng',filename);效果一样,将图像打印到指定文件中

                fprintf('>>已保存到:%s\n',file);

            case 2

                print(new_f_handle,'-dbmp',file);

                fprintf('>>已保存到:%s\n',file);

            case 3

                print(new_f_handle,'-djpeg',file);

                fprintf('>>已保存到:%s\n',file);

            case 4

                print(new_f_handle,'-depsc',file);

                fprintf('>>已保存到:%s\n',file);

        end 

        msgbox('          图线已成功保存!','完成!');

    end

3 仿真结果

4 参考文献

[1]冯浩. 基于MATLAB GUI的FIR数字滤波器语音信号去噪处理[J]. 菏泽学院学报, 2016, 38(5):5.

博主简介:擅长智能优化算法、神经网络预测、信号处理、元胞自动机、图像处理、路径规划、无人机等多种领域的Matlab仿真,相关matlab代码问题可私信交流。

部分理论引用网络文献,若有侵权联系博主删除。

举报

相关推荐

0 条评论