一、案例简介

1 内容简介
利用MATLAB GUI设计平台,用窗函数法设计FIR数字滤波器,对所给出的含有噪声的声音信号进行数字滤波处理,得到降噪的声音信号,进行时域频域分析,同时分析不同窗函数的效果。

2 函数使用
读取.wav音频文件函数:audioread();(老版本为wavread)
MATLAB播放音乐函数:sound();
MATLAB停止播放音乐:clear sound
写入.wav音频文件函数:audiowrite();(老版本为audiowrite)
加入白噪声:noise=(max(x(:,1))/5)*randn(x,2);
y=x+noise;
频谱分析: fft();
fftshift();
Fir滤波: fir1(n,Wn,ftype,window);
窗函数选择: 梯形窗boxcar
三角窗triang
海明窗hamming
汉宁窗hanning
布莱克曼窗blackman
凯塞窗kaiser

3 实现功能
3.1 打开文件
选择路径打开wav格式的音频文件,自动生成音频的原始波形与频谱。

3.2 加入噪声
有两种噪声可以选择加入,一种是白噪声,其频率蔓延整个频谱;一种是特定频率的噪声,可通过输入频率加入单一频率的噪声。加入噪声后自动绘制加入噪声后的波形与频谱。

3.3 滤波处理
首先输入滤波器通/阻带的开始频率与截止频率(若为低/高通类型滤波,则只需输入开始频率;若为带通/阻类型,则开始与截止都要输入;输入频率值为真实频率值,可根据频谱图进行判断 ),之后选取窗函数和滤波类型,将会生成滤波处理后的波形与频谱。

3.4 音频播放/停止
可随时播放/停止原始、加噪、滤波处理后的音频。

3.5 图片导出
将波形、频谱图片一张张导出保存,可选的格式有jpg、png、bmp、eps。

3.6 保存文件
将加躁/滤波后的音频导出保存。

二、部分源代码

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});
endif nargout[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
elsegui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT% --- Executes just before yanshou is made visible.
function yanshou_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 yanshou (see VARARGIN)% Choose default command line output for yanshou
handles.output = hObject;% Update handles structure
guidata(hObject, handles);% UIWAIT makes yanshou wait for user response (see UIRESUME)
% uiwait(handles.figure1);% --- Outputs from this function are returned to the command line.
function varargout = yanshou_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 open_pushbutton1.
function open_pushbutton1_Callback(hObject, eventdata, handles)
% hObject    handle to open_pushbutton1 (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')
elsepath = 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;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;
end% --- Executes on button press in play_pushbutton2.
function play_pushbutton2_Callback(hObject, eventdata, handles)
% hObject    handle to play_pushbutton2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global x2;
global Fs;
sound(x2,Fs);% --- Executes on button press in add_pushbutton3.
function add_pushbutton3_Callback(hObject, eventdata, handles)
% hObject    handle to add_pushbutton3 (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;
axes(handles.axes1);
size(x);
t=0:1/Fs:(length(x)-1)/Fs;%将所加噪声信号的点数调整到与原始信号相同
Au=0.07;
fn =  get(handles.noise_edit2,'string');       %噪声频率
fn = str2double(fn);
noise=Au*cos(2*pi*fn*t)';     %噪声为频率
x=x+noise;
plot(tl,x);
title('加入噪声后语音时域波形');
xlabel('时间/s');
grid on;
N=length(x);
df=Fs/N;
w=[0:df:df*(N-1)] - Fs/2; %频率尺度
X=fft(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;% --- Executes on button press in low_pushbutton5.
function low_pushbutton5_Callback(hObject, eventdata, handles)
% hObject    handle to low_pushbutton5 (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;x1=x;
% fp=1000;
% fs = 1000;
% Wp = 2*fp/Fs;
% Ws = 2*fs/Fs;
% if(Wp >= 1)
%     Wp = 0.99;
% end
% if(Ws >= 1)
%     Ws = 0.99;
% end
fp =  get(handles.edit3,'string');
fp = str2double(fp)*2;
if get(handles.radiobutton1,'value')[n, Wn]=buttord(Wp,Ws, 2, 15);[b, a]=butter(n, Wn,'low');axes(handles.axes3);[h,w]=freqz(b,a);plot(w/pi*Fs/2,abs(h)); x1=filter(b,a,x1);        %调用函数滤波
elseif get(handles.radiobutton4,'value')b2=fir1(30, fp/Fs, boxcar(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.radiobutton5,'value')b2=fir1(30, fp/Fs, 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.radiobutton6,'value')b2=fir1(30, fp/Fs, hamming(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, 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, 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, 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 during object creation, after setting all properties.
function low_pushbutton5_CreateFcn(hObject, eventdata, handles)
% hObject    handle to low_pushbutton5 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called% --- Executes on button press in pushbutton6.function noise_edit2_Callback(hObject, eventdata, handles)
% hObject    handle to noise_edit2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)% Hints: get(hObject,'String') returns contents of noise_edit2 as text
%        str2double(get(hObject,'String')) returns contents of noise_edit2 as a double% --- Executes during object creation, after setting all properties.
function noise_edit2_CreateFcn(hObject, eventdata, handles)
% hObject    handle to noise_edit2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))set(hObject,'BackgroundColor','white');
end% --- Executes during object creation, after setting all properties.
function add_pushbutton3_CreateFcn(hObject, eventdata, handles)
% hObject    handle to add_pushbutton3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called% --- Executes on button press in guass_pushbutton8.
function guass_pushbutton8_Callback(hObject, eventdata, handles)
% hObject    handle to guass_pushbutton8 (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;
N=length(x);
axes(handles.axes1);
%x = awgn(x,15);
noise=(max(x(:,1))/5)*randn(N,2);
x=x+noise;
plot(tl,x);
title('加入噪声后语音时域波形');
xlabel('时间/s');
grid on;

三、运行结果

四、matlab版本及参考文献

1 matlab版本
2014a

2 参考文献
[1]韩纪庆,张磊,郑铁然.语音信号处理(第3版)[M].清华大学出版社,2019.
[2]柳若边.深度学习:语音识别技术实践[M].清华大学出版社,2019.

【语音去噪】基于matlab GUI FIR窗函数音频去噪【含Matlab源码 875期】相关推荐

  1. 【数据分析】基于matlab GUI齿轮箱振动数据分析【含Matlab源码 2122期】

    一.获取代码方式 获取代码方式1: 完整代码已上传我的资源:[数据分析]基于matlab GUI齿轮箱振动数据分析[含Matlab源码 2122期] 点击上面蓝色字体,直接付费下载,即可. 获取代码方 ...

  2. 【运动学】基于matlab GUI三体运动模拟【含Matlab源码 871期】

    ⛄一.获取代码方式 获取代码方式1: 完整代码已上传我的资源:[运动学]基于matlab GUI三体运动模拟[含Matlab源码 871期] 点击上面蓝色字体,直接付费下载,即可. 获取代码方式2: ...

  3. 【音乐播放】基于matlab GUI动感音乐播放【含Matlab源码 778期】

    ⛄一.获取代码方式 获取代码方式1: 完整代码已上传我的资源:[音乐播放]基于matlab GUI动感音乐播放[含Matlab源码 778期] 点击上面蓝色字体,直接付费下载,即可. 获取代码方式2: ...

  4. 【雷达通信】基于matlab GUI相控阵雷达方向图【含Matlab源码 1048期】

    ⛄一.获取代码方式 获取代码方式1: 完整代码已上传我的资源:[雷达通信]基于matlab GUI相控阵雷达方向图[含Matlab源码 1048期] 点击上面蓝色字体,直接付费下载,即可. 获取代码方 ...

  5. 【光学】基于matlab GUI维达尔之眼计算【含Matlab源码 2545期】

    ⛄一.获取代码方式 获取代码方式1: 完整代码已上传我的资源:[光学]基于matlab GUI维达尔之眼计算[含Matlab源码 2545期] 点击上面蓝色字体,直接付费下载,即可. 获取代码方式2: ...

  6. 【光学】基于matlab GUI双孔干涉【含Matlab源码 2119期】

    ⛄一.获取代码方式 获取代码方式1: 完整代码已上传我的资源:[光学]基于matlab GUI双孔干涉[含Matlab源码 2119期] 点击上面蓝色字体,直接付费下载,即可. 获取代码方式2: 付费 ...

  7. 【光学】基于matlab GUI双缝干涉和牛顿环【含Matlab源码 2165期】

    ⛄一.获取代码方式 获取代码方式1: 完整代码已上传我的资源:[光学]基于matlab GUI双缝干涉和牛顿环[含Matlab源码 2165期] 点击上面蓝色字体,直接付费下载,即可. 获取代码方式2 ...

  8. 【数字信号】基于matlab GUI电话按键识别【含Matlab源码 2382期】

    ⛄一.获取代码方式 获取代码方式1: 完整代码已上传我的资源:[数字信号]基于matlab GUI电话按键识别[含Matlab源码 2382期] 点击上面蓝色字体,直接付费下载,即可. 获取代码方式2 ...

  9. Matlab GUI/APP 浅谈(附计算器源码)

    Matlab GUI/APP 浅谈(附计算器源码) 今天没有什么段子,也没有心灵鸡汤.毒鸡汤啥的,纯粹聊一聊这些年从有关MATLAB GUI/APP开发中悟出的一点道理,顺便把计算器的源代码给大家. ...

  10. 【课程设计】基于java GUI实现学生个人信息管理系统(源码+论文+ppt+视频)

    源码资料 免费下载 不经常在线,需要源码和资料的留言私信我,主页有联系方式 技术架构 开发语言 主要用的是Java语言中的GUI(图形用户界面)和AWT(抽象窗口工具包)编程. (1) GUI 图形用 ...

最新文章

  1. 千万级并发HAproxy均衡负载系统介绍
  2. nginx 访问控制之 认证
  3. Spark写Redis+Spark资源配置总结
  4. redis——数据结构(整数集合,压缩列表)
  5. linux的常用操作——lftp、nfs、ssh和scp
  6. linux用户组500,Linux用户及用户组权限
  7. 【ARM】2410裸机系列-中断处理
  8. 1000套微信小程序源码模板分享下载,各种类型任意选择
  9. 2022年水果市场调查报告分析
  10. 关于程序员抵制996的一些想法
  11. 小组取什么名字好_学习小组起什么名字比较好
  12. 不同型号阵列卡相关工具的使用简介
  13. 技术、商业和创新的彼岸:“被折叠”的三星
  14. java控制台如何输入一段代码
  15. wpf 的 Window或UserControl绑定自己后台属性
  16. 商业贷款和公积金贷款差多少?一组数据告诉你!
  17. 100首经典英文歌曲
  18. Ogre个人初步学习总结
  19. SSM整合开发学习笔记
  20. 地图坐标格式转换工具

热门文章

  1. VIm中Python自动补全插件Pydiction
  2. sublim插件(待续)
  3. 清北学堂模拟赛d1t5 拍照(photo)
  4. python 比较两文件夹的内容,具有通用性。
  5. 【万里征程——Windows App开发】如何使用粘贴板
  6. Arcgis Android 基本概念 - 浅谈
  7. 怕忘记了。记录一下要采购的元件----1
  8. ASP.NET 服务端GZIP压缩
  9. installanywhere's LAX Properties
  10. Python 学习笔记:class