【语音处理】基于matlab实现语音基频检测

简介: 【语音处理】基于matlab实现语音基频检测

 1 简介

随着智能化设备的广泛普及,语音信号作为智能化设备的一个重要的交互语言显得尤为重要,语音信号处理被广泛地应用在语音识别,智能控制,身份识别,智能家居等领域,MATLAB仿真软件具有强大的信号处理功能,能对语音信号进行平移,尺度变换,系统分析,时频转换和滤波等操作,文章借助MATLAB软件对语音信号进行处理,实现对语音信号的音效处理,时频分析,滤波处理等功能.

2 部分代码

function varargout = zuoye(varargin)% ZUOYE MATLAB code for zuoye.fig%      ZUOYE, by itself, creates a new ZUOYE or raises the existing%      singleton*.%%      H = ZUOYE returns the handle to a new ZUOYE or the handle to%      the existing singleton*.%%      ZUOYE('CALLBACK',hObject,eventData,handles,...) calls the local%      function named CALLBACK in ZUOYE.M with the given input arguments.%%      ZUOYE('Property','Value',...) creates a new ZUOYE or raises the%      existing singleton*.  Starting from the left, property value pairs are%      applied to the GUI before zuoye_OpeningFcn gets called.  An%      unrecognized property name or invalid value makes property application%      stop.  All inputs are passed to zuoye_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 zuoye% Last Modified by GUIDE v2.5 03-May-2020 17:00:59% Begin initialization code - DO NOT EDITgui_Singleton = 1;gui_State = struct('gui_Name',       mfilename, ...                   'gui_Singleton',  gui_Singleton, ...                   'gui_OpeningFcn', @zuoye_OpeningFcn, ...                   'gui_OutputFcn',  @zuoye_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{:});else    gui_mainfcn(gui_State, varargin{:});end% End initialization code - DO NOT EDIT% --- Executes just before zuoye is made visible.function zuoye_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 zuoye (see VARARGIN)% Choose default command line output for zuoyehandles.output = hObject;% Update handles structureguidata(hObject, handles);% UIWAIT makes zuoye wait for user response (see UIRESUME)% uiwait(handles.figure1);% --- Outputs from this function are returned to the command line.function varargout = zuoye_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 structurevarargout{1} = handles.output;% --- Executes on selection change in popupmenu1.function popupmenu1_Callback(hObject, eventdata, handles)% hObject    handle to popupmenu1 (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA)% Hints: contents = cellstr(get(hObject,'String')) returns popupmenu1 contents as cell array%        contents{get(hObject,'Value')} returns selected item from popupmenu1% --- Executes during object creation, after setting all properties.function popupmenu1_CreateFcn(hObject, eventdata, handles)% hObject    handle to popupmenu1 (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    empty - handles not created until after all CreateFcns called% Hint: popupmenu 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 on button press in pushbutton1.function pushbutton1_Callback(hObject, eventdata, handles)% hObject    handle to 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 bits;global file;clear sound;if nargin<1;action='initialized';end;[fname,pname]=uigetfile('*.wav','Open Wave File');file=[pname,fname];[x,fs,bits]=wavread(file);       % 读入声音文件(*.wav)      sound(x,fs);set(handles.edit1,'string',fs); % --- 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)%画原信号时域波形global x;global w;global fs;axes(handles.axes1);N=length(x);t=[0:1:N-1]/fs;plot(t,x);xlabel('时间t')ylabel('幅值')n=[0:N-1]';w=2*n*pi/N;% --- Executes on button press in pushbutton3.function pushbutton3_Callback(hObject, eventdata, handles)% hObject    handle to 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 w;X=fft(x);axes(handles.axes2);plot(w/pi,abs(X))axis([0,2,0,500])xlabel('归一化')ylabel('幅值')% --- Executes on button press in pushbutton4.% --- Executes on button press in pushbutton5.function pushbutton5_Callback(hObject, eventdata, handles)% hObject    handle to pushbutton5 (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA)global pitchglobal nFramesaxes(handles.axes2);xt=1:nFrames;xt=20*xt;plot(xt,pitch)xlim([0,3]);axis([xt(1) xt(nFrames) 0 max(pitch)+50]);ylabel('基音频率/HZ');xlabel('时间');% --- Executes on button press in pushbutton6.function pushbutton6_Callback(hObject, eventdata, handles)% hObject    handle to pushbutton6 (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA)global ybiansu;global fs;axes(handles.axes1);N=length(ybiansu);t=[0:1:N-1]/fs;plot(t,ybiansu);xlabel('时间t')ylabel('幅值')% --- Executes on button press in pushbutton7.function pushbutton7_Callback(hObject, eventdata, handles)% hObject    handle to pushbutton7 (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA)global ybiansu;NS=length(ybiansu);nS=[0:NS-1]';wS=2*nS*pi/NS;YH=fft(ybiansu);axes(handles.axes2);plot(wS/pi,abs(YH))axis([0,2,0,500])xlabel('归一化')ylabel('幅值')% --- Executes on button press in pushbutton8.function pushbutton8_Callback(hObject, eventdata, handles)% hObject    handle to pushbutton8 (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;axes(handles.axes1);N=length(x2);t=[0:1:N-1]/fs;plot(t,x2);xlabel('时间t')ylabel('幅值')% --- Executes on button press in pushbutton9.function pushbutton9_Callback(hObject, eventdata, handles)% hObject    handle to pushbutton9 (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA)global x2;X2=fft(x2);NS=length(x2);nS=[0:NS-1]';wS=2*nS*pi/NS;axes(handles.axes2);plot(wS/pi,abs(X2))axis([0,2,0,500])xlabel('归一化')ylabel('幅值')function edit1_Callback(hObject, eventdata, handles)% hObject    handle to edit1 (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 edit1 as text%        str2double(get(hObject,'String')) returns contents of edit1 as a double% --- Executes during object creation, after setting all properties.function edit1_CreateFcn(hObject, eventdata, handles)% hObject    handle to edit1 (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 on button press in pushbutton10.function pushbutton10_Callback(hObject, eventdata, handles)% hObject    handle to pushbutton10 (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 pitch;global nFrames;xn=x;meen=mean(xn);xn= xn - meen;%去均值fRate=floor(40*fs/1000);%帧长40ms 一共640个点   floor不大于x的最大整数updRate=floor(20*fs/1000);%帧移20msn_samples=length(xn);%语音长度nFrames=floor(n_samples/updRate)-1; %帧数k=1;pitch=zeros(1,nFrames);%处理后基频矩阵f0=zeros(1,nFrames);%基频矩阵LF=floor(fs/500);%设置基音搜索的范围  点数HF=floor(fs/70);%设置基音搜索的范围  点数m=1;avgF0=0;for t=1:nFrames        yin=xn(k:k+fRate-1);%当前帧数据        frameSize=length(yin);        yin2=yin.*hamming(frameSize);  % 加hamming窗        cn1=rceps(yin2);        cn=cn1(LF:HF);%求倒谱        [mx_cep ind]=max(cn);%求倒谱最大值        if mx_cep > 0.08 & ind >LF%设置门限,找到峰值位置           a= fs/(LF+ind);        else            a=0;        end         f0(t)=a;        if t>2 & nFrames>3              z=f0(t-2:t);           md=median(z);%中值滤波对基音轨迹图进行平滑           pitch(t-2)=md;           if md > 0             avgF0=avgF0+md;             m=m+1;           end        else            if nFrames<=3            pitch(t)=a;            avgF0=avgF0+a;            m=m+1;           end         end     k=k+updRate;endMypitch = max(pitch);set(handles.edit2,'string',Mypitch); Myt=1/Mypitch;set(handles.edit5,'string',Myt); function edit2_Callback(hObject, eventdata, handles)% hObject    handle to 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 edit2 as text%        str2double(get(hObject,'String')) returns contents of edit2 as a double% --- Executes during object creation, after setting all properties.function edit2_CreateFcn(hObject, eventdata, handles)% hObject    handle to 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 on button press in pushbutton11.function pushbutton11_Callback(hObject, eventdata, handles)% hObject    handle to pushbutton11 (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 ybiansuclear sound;vv=str2double(get(handles.edit3,'String'))%读取变速的倍数N=length(x)n1=0:N-1;n2=0:vv:N-1;ybiansu=interp1(n1,x,n2,'nearest');sound(ybiansu,fs)function edit3_Callback(hObject, eventdata, handles)% hObject    handle to edit3 (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 edit3 as text%        str2double(get(hObject,'String')) returns contents of edit3 as a double% --- Executes during object creation, after setting all properties.function edit3_CreateFcn(hObject, eventdata, handles)% hObject    handle to edit3 (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 on button press in pushbutton12.function pushbutton12_Callback(hObject, eventdata, handles)% hObject    handle to 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 fs;global x2;clear sound;fs2=str2double(get(handles.edit4,'String'));function edit5_Callback(hObject, eventdata, handles)% hObject    handle to edit5 (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 edit5 as text%        str2double(get(hObject,'String')) returns contents of edit5 as a double% --- Executes during object creation, after setting all properties.function edit5_CreateFcn(hObject, eventdata, handles)% hObject    handle to edit5 (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

3 仿真结果

image.gif编辑

image.gif编辑

4 参考文献

[1]周代勇, 曾妍萍, 蔡燕. 基于Matlab的语音识别端点检测算法研究与实现[J]. 内江科技, 2013, 34(9):2.

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

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

代码

相关文章
|
2月前
|
机器学习/深度学习 算法 数据安全/隐私保护
基于MSER和HOG特征提取的SVM交通标志检测和识别算法matlab仿真
### 算法简介 1. **算法运行效果图预览**:展示算法效果,完整程序运行后无水印。 2. **算法运行软件版本**:Matlab 2017b。 3. **部分核心程序**:完整版代码包含中文注释及操作步骤视频。 4. **算法理论概述**: - **MSER**:用于检测显著区域,提取图像中稳定区域,适用于光照变化下的交通标志检测。 - **HOG特征提取**:通过计算图像小区域的梯度直方图捕捉局部纹理信息,用于物体检测。 - **SVM**:寻找最大化间隔的超平面以分类样本。 整个算法流程图见下图。
|
1月前
|
运维 算法
基于Lipschitz李式指数的随机信号特征识别和故障检测matlab仿真
本程序基于Lipschitz李式指数进行随机信号特征识别和故障检测。使用MATLAB2013B版本运行,核心功能包括计算Lipschitz指数、绘制指数曲线、检测故障信号并标记异常区域。Lipschitz指数能够反映信号的局部动态行为,适用于机械振动分析等领域的故障诊断。
|
1月前
|
机器学习/深度学习 算法 数据安全/隐私保护
基于GA-PSO-SVM算法的混沌背景下微弱信号检测matlab仿真
本项目基于MATLAB 2022a,展示了SVM、PSO、GA-PSO-SVM在混沌背景下微弱信号检测中的性能对比。核心程序包含详细中文注释和操作步骤视频。GA-PSO-SVM算法通过遗传算法和粒子群优化算法优化SVM参数,提高信号检测的准确性和鲁棒性,尤其适用于低信噪比环境。
|
3月前
|
监控 算法 数据安全/隐私保护
基于视觉工具箱和背景差法的行人检测,行走轨迹跟踪,人员行走习惯统计matlab仿真
该算法基于Matlab 2022a,利用视觉工具箱和背景差法实现行人检测与轨迹跟踪,通过构建背景模型(如GMM),对比当前帧与模型差异,识别运动物体并统计行走习惯,包括轨迹、速度及停留时间等特征。演示三维图中幅度越大代表更常走的路线。完整代码含中文注释及操作视频。
|
4月前
|
机器学习/深度学习 数据采集 算法
基于深度学习网络的USB摄像头实时视频采集与火焰检测matlab仿真
本项目使用MATLAB2022a实现基于YOLOv2的火焰检测系统。通过USB摄像头捕捉火焰视频,系统实时识别并标出火焰位置。核心流程包括:视频采集、火焰检测及数据预处理(图像标准化与增强)。YOLOv2模型经特定火焰数据集训练,能快速准确地识别火焰。系统含详细中文注释与操作指南,助力快速上手。
|
4月前
|
机器学习/深度学习 监控 算法
基于深度学习网络的人员行为视频检测系统matlab仿真,带GUI界面
本仿真展示了基于GoogLeNet的人员行为检测系统在Matlab 2022a上的实现效果,无水印。GoogLeNet采用创新的Inception模块,高效地提取视频中人员行为特征并进行分类。核心程序循环读取视频帧,每十帧执行一次分类,最终输出最频繁的行为类别如“乐队”、“乒乓球”等。此技术适用于智能监控等多个领域。
70 4
|
4月前
|
存储 Serverless
【matlab】matlab实现倒谱法基音频率检测和共振峰检测(源码+音频文件)【独一无二】
【matlab】matlab实现倒谱法基音频率检测和共振峰检测(源码+音频文件)【独一无二】
|
4月前
|
算法
基于IEEE802.11g标准的OFDM信号帧检测matlab仿真
此项目旨在应对无线信号识别挑战,利用MATLAB/Simulink开发IEEE 802.11g OFDM信号识别算法。通过对标准的深入研究,设计并计算PLCP前导码数据,采用信号相关性进行信号鉴定。项目构建了完整的发射机模型,在AWGN信道下评估性能。通过生成特定的短训和长训序列,实现帧头检测,并模拟真实信号传输。测试使用MATLAB 2022a版本,展示了信号生成与识别的关键步骤及结果。
|
5月前
|
监控
基于偏微分方程离散化计算的地下换热器建模与温度检测matlab仿真
**摘要:** 探索地下换热器的建模与温度检测,使用MATLAB2022a进行系统仿真,关注传热过程的热传导、对流和辐射。通过离散化偏微分方程建立数值模型,模拟温度场,考虑地质特性和水流影响。建模以网格单元描述温度变化,采用热电偶、红外和光纤测温技术验证模型并监控温度,各具优缺点。光纤测温法提供高精度和抗干扰的分布式监测。
|
6月前
|
机器学习/深度学习 算法 计算机视觉
基于深度学习网络的USB摄像头实时视频采集与人脸检测matlab仿真
**摘要 (Markdown格式):** ```markdown - 📹 使用USB摄像头(Tttttttttttttt666)实时视频检测,展示基于YOLOv2在MATLAB2022a的实施效果: ``` Tttttttttttttt1111111111------------5555555555 ``` - 📺 程序核心利用MATLAB视频采集配置及工具箱(Dddddddddddddd),实现图像采集与人脸定位。 - 🧠 YOLOv2算法概览:通过S×S网格预测边界框(B个/网格),含坐标、类别概率和置信度,高效检测人脸。