自数字信号处理实验8音频频谱分析仪设计与实现.docx

上传人:b****5 文档编号:4525384 上传时间:2022-12-01 格式:DOCX 页数:36 大小:549.70KB
下载 相关 举报
自数字信号处理实验8音频频谱分析仪设计与实现.docx_第1页
第1页 / 共36页
自数字信号处理实验8音频频谱分析仪设计与实现.docx_第2页
第2页 / 共36页
自数字信号处理实验8音频频谱分析仪设计与实现.docx_第3页
第3页 / 共36页
自数字信号处理实验8音频频谱分析仪设计与实现.docx_第4页
第4页 / 共36页
自数字信号处理实验8音频频谱分析仪设计与实现.docx_第5页
第5页 / 共36页
点击查看更多>>
下载资源
资源描述

自数字信号处理实验8音频频谱分析仪设计与实现.docx

《自数字信号处理实验8音频频谱分析仪设计与实现.docx》由会员分享,可在线阅读,更多相关《自数字信号处理实验8音频频谱分析仪设计与实现.docx(36页珍藏版)》请在冰豆网上搜索。

自数字信号处理实验8音频频谱分析仪设计与实现.docx

自数字信号处理实验8音频频谱分析仪设计与实现

信号处理实验

 

实验八:

音频频谱分析仪设计与实现

 

一、实验名称:

音频频谱分析仪设计与实现

二、实验原理:

MATLAB是一个数据信息和处理功能十分强大的工程实用软件,其数据采集工具箱为实现数据的输入和输出提供了十分方便的函数和命令。

本实验可以用MATLAB进行音频信号频谱分析仪的设计与实现。

1、信号频率、幅值和相位估计

(1)频率(周期)检测

对周期信号来说,可以用时域波形分析来确定信号的周期,也就是计算相邻的两个信号波峰的时间差、或过零点的时间差。

这里采用过零点(ti)的时间差T(周期)。

频率即为f =1/T,由于能够求得多个T值(ti有多个),故采用它们的平均值作为周期的估计值。

(2)幅值检测

在一个周期内,求出信号最大值ymax与最小值ymin的差的一半,即A=(ymax-ymin)/2,同样,也会求出多个A值,但第1个A值对应的ymax和ymin不是在一个周期内搜索得到的,故以除第1个以外的A值的平均作为幅值的估计值。

(3)相位检测

采用过零法,即通过判断与同频零相位信号过零点时刻,计算其时间差,然后换成相应的相位差。

φ=2π(1-ti/T),{x}表示x的小数部分,同样,以φ的平均值作为相位的估计值。

频率、幅值和相位估计的流程如图所示。

其中tin表示第n个过零点,yi为第i个采样点的值,Fs为采样频率。

2、数字信号统计量估计

(1)峰值P的估计

在样本数据x中找出最大值与最小值,其差值为双峰值,双峰值的一半即为峰值。

P=0.5[max(yi)-min(yi)]

(2)均值估计

式中,N为样本容量,下同。

(3)均方值估计

(4)方差估计

2、频谱分析原理

时域分析只能反映信号的幅值随时间的变化情况,除单频率分量的简单波形外,很难明确提示信号的频率组成和各频率分量大小,而频谱分析能很好的解决此问题。

(1)DFT与FFT

对于给定的时域信号y,可以通过Fourier变换得到频域信息Y。

Y可按下式计算

式中,N为样本容量,Δt=1/Fs为采样间隔。

采样信号的频谱是一个连续的频谱,不可能计算出所有的点的值,故采用离散Fourier变换(DFT),即

式中,Δf=Fs/N。

但上式的计算效率很低,因为有大量的指数(等价于三角函数)运算,故实际中多采用快速Fourier变换(FFT)。

其原理即是将重复的三角函数算计的中间结果保存起来,以减少重复三角函数计算带来的时间浪费。

由于三角函数计算的重复量相当大,故FFT能极大地提高运算效率。

(2)频率、周期的估计

对于Y(kΔf),如果当kΔf= 时,Y(kΔf)取最大值,则为频率的估计值,由于采样间隔的误差,也存在误差,其误差最大为Δf /2。

周期T=1/f。

从原理上可以看出,如果在标准信号中混有噪声,用上述方法仍能够精确地估计出原标准信号的频率和周期,这个将在下一章做出验证

3、频谱图

为了直观地表示信号的频率特性,工程上常常将Fourier变换的结果用图形的方式表示,即频谱图。

以频率f为横坐标,|Y(f)|为纵坐标,可以得到幅值谱;

以频率f为横坐标,argY(f)为纵坐标,可以得到相位谱;

以频率f为横坐标,ReY(f)为纵坐标,可以得到实频谱;

以频率f为横坐标,ImY(f)为纵坐标,可以得到虚频谱。

根据采样定理,只有频率不超过Fs/2的信号才能被正确采集,即Fourier变换的结果中频率大于Fs/2的部分是不正确的部分,故不在频谱图中显示。

即横坐标f∈[0,Fs/2]

4、模块划分

模块化就是把程序划分成独立命名且可独立访问的模块,每个模块完成一个子功能,把这些模块集成起来构成一个整体,可以完成指定的功能满足用户需求。

根据人类解决一般问题的经验,如果一个问题由两个问题组合而成,那么它的复杂程度大于分别考虑每个问题时的复杂程度之和,也就是说把复杂的问题分解成许多容易解决的小问题,原来的问题也就容易解决了。

这就是模块化的根据。

在模块划分时应遵循如下规则:

改进软件结构提高模块独立性;模块规模应该适中;深度、宽度、扇出和扇入都应适当;模块的作用域应该在控制域之内;力争降低模块接口的复杂程度;设计单入口单出口的模块;模块功能应该可以预测。

三、实验要求:

参考以上原理,查阅相关资料,构建交互界面,设计一个音频频谱分析仪,实现一下功能:

(1)音频信号信号输入,从声卡输入、从WAV文件输入、从标准信号发生器输入;

(2)信号波形分析,包括幅值、频率、周期、相位的估计,以及统计量峰值、均值、均方值和方差的计算;

(3)信号频谱分析,频率、周期的估计,图形显示幅值谱、相位谱、实频谱、虚频谱和功率谱的曲线。

四、实验界面及程序

程序:

functionvarargout =yinpin(varargin)

 %YINPIN M-yinpin.fig

% YINPIN,byitself,createsanewYINPINorraises the existing

%singleton*.

 %

% H= YINPINreturnsthehandletoanewYINPINorthehandle to

%  the existingsingleton*.

%

 %   YINPIN('CALLBACK',hObject,eventData,handles,...)callsthelocal

 %  functionnamed CALLBACKinYINPIN.Mwiththegiveninputarguments.

%YINPIN('Property','Value',...)createsanewYINPIN orraises the

 % existing singleton*.Startingfrom theleft,propertyvaluepairs are

 %   applied totheGUIbefore yinpin_OpeningFunctiongets called.An

%  unrecognizedproperty name orinvalid valuemakespropertyapplication

% stop.Allinputsarepassedtoyinpin_OpeningFcn viavarargin.

  %

 % *SeeGUIOptionsonGUIDE'sTools menu. Choose"GUIallowsonlyone

  %instancetorun(singleton)".

  %See also:

GUIDE,GUIDATA,GUIHANDLES

   %Edit theabove text tomodifytheresponsetohelpyinpin

%LastModifiedbyGUIDEv2.5 07-Nov-201217:

08:

53

 % Begininitializationcode-DONOTEDIT

gui_Singleton=1;

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

     'gui_Singleton',gui_Singleton,...

      'gui_OpeningFcn', @yinpin_OpeningFcn, ...

     'gui_OutputFcn',@yinpin_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

%Endinitialization code -DONOTEDIT

 

%---Executes justbefore yinpinis made visible.

 functionyinpin_OpeningFcn(hObject, eventdata,handles, varargin)

%Thisfunction has nooutputargs, seeOutputFcn.

 % hObjecthandle tofigure

  % eventdatareserved -tobe definedinafutureversionofMATLAB

   %handlesstructurewithhandles and userdata(seeGUIDATA)

%varargincommandline argumentstoyinpin(seeVARARGIN)

 %Choosedefault commandlineoutput foryinpin

handles.output =hObject;

%Updatehandlesstructure

guidata(hObject,handles);

 %UIWAITmakes yinpinwaitforuser response(seeUIRESUME)

% uiwait(handles.figure1);

 

 %---Outputsfromthisfunctionarereturnedto thecommandline.

functionvarargout=yinpin_OutputFcn(hObject, eventdata, handles)

% varargout cell array forreturningoutputargs(seeVARARGOUT);

 %hObject handleto figure

 %eventdatareserved-to bedefinedina future version ofMATLAB

  % handles structurewithhandlesanduserdata(seeGUIDATA)

 %Getdefaultcommandlineoutputfromhandles structure

 varargout{1}= handles.output;

 % --- Executesduringobjectcreation, aftersettingallproperties.

   functionedit1_CreateFcn(hObject,eventdata, handles)

 %hObjecthandletoedit1(see GCBO)

%eventdatareserved- tobe definedinafutureversionof MATLAB

%handlesempty-handles notcreated untilafterallCreateFcnscalled

 %Hint:

editcontrolsusuallyhave awhitebackgroundonWindows.

 %   SeeISPCandCOMPUTER.

 ifispc&&isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))

 set(hObject,'BackgroundColor','white');

 end

 %---Executesduring objectcreation,after settingall properties.

 functioncaiyangpinlv_CreateFcn(hObject, eventdata,handles)

 %hObject handletocaiyangpinlv(seeGCBO)

    %eventdatareserved- tobedefinedinafuture version of MATLAB

%handlesempty -handlesnotcreated untilafterallCreateFcnscalled

%Hint:

editcontrols usuallyhave awhitebackgroundonWindows.

 %    See ISPC and COMPUTER.

  ifispc&&isequal(get(hObject,'BackgroundColor'),get(0,'defaultUicontrolBackgroundColor'))

set(hObject,'BackgroundColor','white');

end

  %---Executesduringobjectcreation,aftersetting all properties.

  functioncaiyangdianshu_CreateFcn(hObject,eventdata,handles)

  %hObject handle to caiyangdianshu(seeGCBO)

%eventdatareserved-tobedefined inafutureversion ofMATLAB

 %handles empty-handles notcreateduntilafterallCreateFcnscalled

% Hint:

editcontrols usuallyhaveawhitebackgroundon Windows.

%    SeeISPCandCOMPUTER.

 ifispc&&isequal(get(hObject,'BackgroundColor'),get(0,'defaultUicontrolBackgroundColor'))

  set(hObject,'BackgroundColor','white');

  end

  % --- Executesonbuttonpressinluyin.

 functionluyin_Callback(hObject,eventdata,handles)

 %hObjecthandleto luyin(seeGCBO)

 %eventdata reserved -to be definedin afuture version ofMATLAB

  %handlesstructure withhandlesanduserdata(seeGUIDATA)

  %Hint:

 get(hObject,'Value') returns togglestateofluyin

 set(handles.luyin,'value',1);

set(handles.wavfile,'value',0);

 set(handles.xinhaofasheng,'value',0);

 h=findobj('Tag','recordtime');ﻩ

  set(h,'enable','on');

 h=findobj('Tag','kaishiluyin');

 set(h,'enable','on');

h=findobj('Tag','wavname');

set(h,'enable','off');

h=findobj('Tag','liulan');

 set(h,'enable','off');

h=findobj('Tag','inwave');

  set(h,'enable','off');

 h=findobj('Tag','infudu');

 set(h,'enable','off');

h=findobj('Tag','infre');

set(h,'enable','off');

 h=findobj('Tag','inphase');

set(h,'enable','off');

h=findobj('Tag','mix');

set(h,'enable','off');

h=findobj('Tag','shengchengboxing');

  set(h,'enable','off');

 

 % ---Executeson buttonpressinwavfile.

 function wav(hObject, eventdata,handles)

% hObject  handleto wavfile(seeGCBO)

% eventdata reserved-tobedefinedinafutureversionofMATLAB

% handlesstructurewith handlesanduser data (seeGUIDATA)

 % Hint:

get(hObject,'Value')returnstogglestateofwavfile

 set(handles.luyin,'value',0);

set(handles.wavfile,'value',1);

  set(handles.xinhaofasheng,'value',0);

 h=findobj('Tag','recordtime');ﻩ

  set(h,'enable','off');

h=findobj('Tag','kaishiluyin');

  set(h,'enable','off');

  h=findobj('Tag','wavname');

set(h,'enable','on');

 h=findobj('Tag','liulan');

 set(h,'enable','on');

 h=findobj('Tag','inwave');

 set(h,'enable','off');

 h=findobj('Tag','infudu');

set(h,'enable','off');

 h=findobj('Tag','infre');

 set(h,'enable','off');

 h=findobj('Tag','inphase');

  set(h,'enable','off');

h=findobj('Tag','mix');

set(h,'enable','off');

h=findobj('Tag','shengchengboxing');

set(h,'enable','off');

 

 %---Executesonbuttonpressinxinhaofasheng.

 functionxinhaofasheng_Callback(hObject,eventdata,handles)

 % hObject handletoxinhaofasheng(seeGCBO)

% eventdatareserved-to bedefined inafutureversionofMATLAB

  %handles  structurewith handlesanduserdata(seeGUIDATA)

 % Hint:

get(hObject,'Value')returnstogglestateof xinhaofasheng

  set(handles.luyin,'value',0);

  set(handles.wavfile,'value',0);

 set(handles.xinhaofasheng,'value',1);

h=findobj('Tag','recordtime');

 set(h,'enable','off');

 h=findobj('Tag','kaishiluyin');

 set(h,'enable','off');

h=findobj('Tag','wavname');

  set(h,'enable','off');

   h=findobj('Tag','liulan');

  set(h,'enable','off');

h=findobj('Tag','inwave');

 set(h,'enable','on');

 h=findobj('Tag','infudu');

  set(h,'enable','on');

 h=findobj('Tag','infre');

 set(h,'enable','on');

 h=findobj('Tag','inphase');

set(h,'enable','on');

 h=findobj('Tag','mix');

 set(h,'enable','on');

  h=findobj('Tag','shengchengboxing');

 set(h,'enable','on');

 %---Executes duringobjectcreation, after settingallproperties.

 functionrecordtime_CreateFcn(hObject, eventdata,handles)

 %hObject  handle to recordtime (seeGCBO)

%eventdata reserved-tobedefinedin afutureversionofMATLAB

 %handlesempty -handlesnot created untilafteral

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 高中教育 > 高中教育

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1