语音处理基于matlab GUI录音与音频时域+频域+倒谱+功率谱分析含Matlab源码 070期
Posted 海神之光
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了语音处理基于matlab GUI录音与音频时域+频域+倒谱+功率谱分析含Matlab源码 070期相关的知识,希望对你有一定的参考价值。
一、语音处理简介
1 语音信号的特点
通过对大量语音信号的观察和分析发现,语音信号主要有下面两个特点:
①在频域内,语音信号的频谱分量主要集中在300~3400Hz的范围内。利用这个特点,可以用一个防混迭的带通滤波器将此范围内的语音信号频率分量取出,然后按8kHz的采样率对语音信号进行采样,就可以得到离散的语音信号。
②在时域内,语音信号具有“短时性”的特点,即在总体上,语音信号的特征是随着时间而变化的,但在一段较短的时间间隔内,语音信号保持平稳。在浊音段表现出周期信号的特征,在清音段表现出随机噪声的特征。
2 语音信号的采集
在将语音信号进行数字化前,必须先进行防混叠预滤波,预滤波的目的有两个:①抑制输入信导各领域分量中频率超出fs/2的所有分量(fs为采样频率),以防止混叠干扰。②抑制50Hz的电源工频干扰。这样,预滤波器必须是一个带通滤波器,设其上、下截止颜率分别是fH和fL,则对于绝人多数语音编译码器,fH=3400Hz、fL=60~100Hz、采样率为fs=8kHz;而对丁语音识别而言,当用于电话用户时,指标与语音编译码器相同。当使用要求较高或很高的场合时fH=4500Hz或8000Hz、fL=60Hz、fs=10kHz或20kHz。
为了将原始模拟语音信号变为数字信号,必须经过采样和量化两个步骤,从而得到时间和幅度上均为离散的数字语音信号。采样也称抽样,是信号在时间上的离散化,即按照一定时间间隔△t在模拟信号x(t)上逐点采取其瞬时值。采样时必须要注意满足奈奎斯特定理,即采样频率fs必须以高于受测信号的最高频率两倍以上的速度进行取样,才能正确地重建波它是通过采样脉冲和模拟信号相乘来实现的。
在采样的过程中应注意采样间隔的选择和信号混淆:对模拟信号采样首先要确定采样间隔。如何合理选择△t涉及到许多需要考虑的技术因素。一般而言,采样频率越高,采样点数就越密,所得离散信号就越逼近于原信号。但过高的采样频率并不可取,对固定长度(T)的信号,采集到过大的数据量(N=T/△t),给计算机增加不必要的计算工作量和存储空间;若数据量(N)限定,则采样时间过短,会导致一些数据信息被排斥在外。采样频率过低,采样点间隔过远,则离散信号不足以反映原有信号波形特征,无法使信号复原,造成信号混淆。根据采样定理,当采样频率大于信号的两倍带宽时,采样过程不会丢失信息,利用理想滤波器可从采样信号中不失真地重构原始信号波形。量化是对幅值进行离散化,即将振动幅值用二进制量化电平来表示。量化电平按级数变化,实际的振动值是连续的物理量。具体振值用舍入法归到靠近的量化电平上。
语音信号经过预滤波和采样后,由A/D变换器变换为二址制数字码。这种防混叠滤波通常与模数转换器做在一个集成块内,因此目前来说,语音信号的数字化的质量还是有保证的。
采集到语音信号之后,需要对语音信号进行分析,如语音信号的时域分析、频谱分析、语谱图分析以及加噪滤波等处理。
3 语音信号分析技术
语音信号分析是语音信号处理的前提和基础,只有分析出可表示语音信号本质特征的参数,才有可能利用这些参数进行高效的语音通信、语音合成和语音识别等处理[8]。而且,语音合成的音质好坏,语音识别率的高低,也都取决于对语音信号分桥的准确性和精确性。因此语音信号分析在语音信号处理应用中具有举足轻重的地位。
贯穿于语音分析全过程的是“短时分析技术”。因为,语音信号从整体来看其特性及表征其本质特征的参数均是随时间而变化的,所以它是一个非乎稳态过程,不能用处理乎稳信号的数字信号处理技术对其进行分析处理。但是,由于不同的语音是由人的口腔肌肉运动构成声道某种形状而产生的响应,而这种口腔肌肉运动相对于语音频率来说是非常缓慢的,所以从另一方面看,虽然语音倍号具有时变特性,但是在一个短时间范围内(一般认为在10~30ms的短时间内),其特性基本保持不变即相对稳定,因面可以将其看作是一个准稳态过程,即语音信号具有短时平稳性。所以任何语音信号的分析和处理必须建立在“短时”的基础上.即进行“短时分析”,将语音信号分为一段一段来分析其特征参数,其中每一段称为一“帧”,帧长一般取为10~30ms。这样,对于整体的语音信号来讲,分析出的是由每一帧特征参数组成的特征参数时间序列。
根据所分析出的参数的性质的不同,可将语音信号分析分为时域分析、频域分析、倒领域分析等;时域分析方法具有简单、计算量小、物理意义明确等优点,但由于语音信号最重要的感知特性反映在功率谱中,而相位变化只起着很小的作用,所以相对于时域分析来说频域分析更为重要。
4 语音信号的时域分析
语音信号的时域分析就是分析和提取语音信号的时域参数。进行语音分析时,最先接触到并且也是最直观的是它的时域波形。语音信号本身就是时域信号,因而时域分析是最早使用,也是应用最广泛的一种分析方法,这种方法直接利用语音信号的时域波形。时域分析通常用于最基本的参数分析及应用,如语音的分割、预处理、大分类等。这种分析方法的特点是:①表示语音信号比较直观、物理意义明确。②实现起来比较简单、运算且少。③可以得到语音的一些重要的参数。④只使用示波器等通用设备,使用较为简单等。
语音信号的时域参数有短时能量、短时过零率、短时白相关函数和短时平均幅度差函数等,这是语音信号的一组最基本的短时参数,在各种语音信号数字处理技术中都要应用[6]。在计算这些参数时使用的一般是方窗或汉明窗。
5 语音信号的频域分析
语音信号的频域分析就是分析语音信号的频域持征。从广义上讲,语音信号的频域分析包括语音信号的频谱、功率谱、倒频谱、频谱包络分析等,而常用的频域分析方法有带通滤波器组法、傅里叶变换法、线件预测法等几种。
二、部分源代码
function varargout = MainSigany(varargin)
% MAINSIGANY M-file for MainSigany.fig
% MAINSIGANY, by itself, creates a new MAINSIGANY or raises the existing
% singleton*.
%
% H = MAINSIGANY returns the handle to a new MAINSIGANY or the handle to
% the existing singleton*.
%
% MAINSIGANY('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in MAINSIGANY.M with the given input arguments.
%
% MAINSIGANY('Property','Value',...) creates a new MAINSIGANY or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before sigany_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to MainSigany_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 MainSigany
% Last Modified by GUIDE v2.5 13-May-2022 12:46:18
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @MainSigany_OpeningFcn, ...
'gui_OutputFcn', @MainSigany_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin1)
gui_State.gui_Callback = str2func(varargin1);
end
if nargout
[varargout1:nargout] = gui_mainfcn(gui_State, varargin:);
else
gui_mainfcn(gui_State, varargin:);
end
% End initialization code - DO NOT EDIT
% --- Executes just before MainSigany is made visible.
function MainSigany_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 MainSigany (see VARARGIN)
% hstartshow=figure;
% imshow('start.jpg');
% pause(3);
% Choose default command line output for MainSigany
handles.output = hObject;
handles.time=str2double(get(handles.time,'String')); % ù±
handles.sample=str2double(get(handles.sample,'String')); % ù
handles.filename=get(handles.name,'String'); % ±
axes(handles.axes1); %
set(gcf,'doublebuffer','on') %Reduce plot flicker
P = plot(zeros(1000,1)); % ú
xlabel('Samples'), axis([0 1000 -1 1]), grid on
title('采样数据实时波形');
handles.P=P; % ±±ú
handles.data=[]; % ó
% AI = analoginput('winsound'); % ù¨è±
% addchannel(AI,1); % íù
% handles.AI=AI; % ±ù¨è±
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes MainSigany wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% close(hstartshow);
% --- Outputs from this function are returned to the command line.
function varargout = MainSigany_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
varargout1 = handles.output;
% --- Executes on button press in start.
function start_Callback(hObject, eventdata, handles)
% hObject handle to start (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% AI = analoginput('winsound');
% addchannel(AI,1);
AI=handles.AI;
duration = handles.time; % èù±
AI.SampleRate=handles.sample; % èù
ActualRate = get(AI,'SampleRate'); % ù
set(AI,'SamplesPerTrigger',duration*ActualRate) % è·ù
handles.AI=AI; % ±ù¨è±è
guidata(hObject, handles);
P=handles.P; % ±ú
start(AI) %
i = 1;
while AI.SamplesAcquired < AI.SamplesPerTrigger % 1000ùü
if strcmp(AI.Running, 'On') % ÷stopò·
while AI.SamplesAcquired < 1000*i
end
data = peekdata(AI,1000);
set(P,'ydata',data);
drawnow
i = i + 1;
else
break;
end
end
[handles.data handles.t] = getdata(AI,AI.SamplesAcquired); %±ùà±
% handles.AI=AI;
% length(handles.data)
guidata(hObject, handles);
stop(AI); % ù
function time_Callback(hObject, eventdata, handles)
% hObject handle to time (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 time as text
% str2double(get(hObject,'String')) returns contents of time as a double
handles.time=str2double(get(hObject,'String')); % ù±
guidata(hObject, handles);
% --- Executes during object creation, after setting all properties.
function time_CreateFcn(hObject, eventdata, handles)
% hObject handle to time (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
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
function sample_Callback(hObject, eventdata, handles)
% hObject handle to sample (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 sample as text
% str2double(get(hObject,'String')) returns contents of sample as a double
handles.sample=str2double(get(hObject,'String')); % ù
guidata(hObject, handles);
% --- Executes during object creation, after setting all properties.
function sample_CreateFcn(hObject, eventdata, handles)
% hObject handle to sample (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
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
% --- Executes on button press in stop.
function stop_Callback(hObject, eventdata, handles)
% hObject handle to stop (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% wavwrite(handles.data,'mywav.wav');
AI=handles.AI;
stop(AI); % ù
% handles.AI=AI;
guidata(hObject, handles);
% --- Executes on button press in save.
function save_Callback(hObject, eventdata, handles)
% hObject handle to save (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
d=handles.data;
name=handles.filename; % ±
wavwrite(d,name); % ±
function name_Callback(hObject, eventdata, handles)
% hObject handle to name (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 name as text
% str2double(get(hObject,'String')) returns contents of name as a double
handles.filename=get(hObject,'String'); % ±
guidata(hObject, handles);
% --- Executes during object creation, after setting all properties.
function name_CreateFcn(hObject, eventdata, handles)
% hObject handle to name (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
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
% --- Executes on button press in wavepos.
function wavepos_Callback(hObject, eventdata, handles)
% hObject handle to wavepos (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
y=handles.data; % ù
axes(handles.axes2); % èúò
plot(handles.t,y); % ±ò¨
ylabel('signal Magnitude ');
xlabel('time(s)');
title('时域波形');
三、运行结果
四、matlab版本及参考文献
1 matlab版本
2014a
2 参考文献
[1]韩纪庆,张磊,郑铁然.语音信号处理(第3版)[M].清华大学出版社,2019.
[2]柳若边.深度学习:语音识别技术实践[M].清华大学出版社,2019.
[3]宋云飞,姜占才,魏中华.基于MATLAB GUI的语音处理界面设计[J].科技信息. 2013,(02)
以上是关于语音处理基于matlab GUI录音与音频时域+频域+倒谱+功率谱分析含Matlab源码 070期的主要内容,如果未能解决你的问题,请参考以下文章
语音处理基于matlab GUI语音信号处理与滤波含Matlab源码 1663期
基于MATLAB的GUI(Graphical User Interface)音频实时显示设计
语音处理基于matlab GUI数字音频分析与处理系统含Matlab源码 1739期