【语音去噪】FIR窗函数音频去噪【含GUI Matlab源码 875期】

✅博主简介:热爱科研的Matlab仿真开发者,修心和技术同步精进,Matlab项目合作可私信。
🍎个人主页:海神之光
🏆代码获取方式:
海神之光Matlab王者学习之路—代码获取方式
⛳️座右铭:行百里者,半于九十。

更多Matlab仿真内容点击👇
Matlab图像处理(进阶版)
路径规划(Matlab)
神经网络预测与分类(Matlab)
优化求解(Matlab)
语音处理(Matlab)
信号处理(Matlab)
车间调度(Matlab)

⛄一、案例简介

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});
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 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’)
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;

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=Aucos(2pifnt)'; %噪声为频率
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 = 2fp/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/piFs/2,20log(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/piFs/2,20log(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/piFs/2,20log(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/piFs/2,20log(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/piFs/2,20log(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/piFs/2,20log(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.

3 备注
简介此部分摘自互联网,仅供参考,若侵权,联系删除

🍅 仿真咨询
1 各类智能优化算法改进及应用

生产调度、经济调度、装配线调度、充电优化、车间调度、发车优化、水库调度、三维装箱、物流选址、货位优化、公交排班优化、充电桩布局优化、车间布局优化、集装箱船配载优化、水泵组合优化、解医疗资源分配优化、设施布局优化、可视域基站和无人机选址优化

2 机器学习和深度学习方面
卷积神经网络(CNN)、LSTM、支持向量机(SVM)、最小二乘支持向量机(LSSVM)、极限学习机(ELM)、核极限学习机(KELM)、BP、RBF、宽度学习、DBN、RF、RBF、DELM、XGBOOST、TCN实现风电预测、光伏预测、电池寿命预测、辐射源识别、交通流预测、负荷预测、股价预测、PM2.5浓度预测、电池健康状态预测、水体光学参数反演、NLOS信号识别、地铁停车精准预测、变压器故障诊断

3 图像处理方面
图像识别、图像分割、图像检测、图像隐藏、图像配准、图像拼接、图像融合、图像增强、图像压缩感知

4 路径规划方面
旅行商问题(TSP)、车辆路径问题(VRP、MVRP、CVRP、VRPTW等)、无人机三维路径规划、无人机协同、无人机编队、机器人路径规划、栅格地图路径规划、多式联运运输问题、车辆协同无人机路径规划、天线线性阵列分布优化、车间布局优化

5 无人机应用方面
无人机路径规划、无人机控制、无人机编队、无人机协同、无人机任务分配

6 无线传感器定位及布局方面
传感器部署优化、通信协议优化、路由优化、目标定位优化、Dv-Hop定位优化、Leach协议优化、WSN覆盖优化、组播优化、RSSI定位优化

7 信号处理方面
信号识别、信号加密、信号去噪、信号增强、雷达信号处理、信号水印嵌入提取、肌电信号、脑电信号、信号配时优化

8 电力系统方面
微电网优化、无功优化、配电网重构、储能配置

9 元胞自动机方面
交通流 人群疏散 病毒扩散 晶体生长

10 雷达方面
卡尔曼滤波跟踪、航迹关联、航迹融合

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值