信号处理实验音频频谱分析仪设计_第1页
信号处理实验音频频谱分析仪设计_第2页
信号处理实验音频频谱分析仪设计_第3页
信号处理实验音频频谱分析仪设计_第4页
信号处理实验音频频谱分析仪设计_第5页
已阅读5页,还剩13页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、信号处理实验实验八:音频频谱分析仪设计与实现实验名称:音频频谱分析仪设计与实现实验原理:MATLAB是一个数据信息和处理功能十分强大的工程实用软件,其数据采集工具箱为实现数据的输入和输出提供了十分方便的函数和命令。本实验可以用MATLAB进行音频信号频谱分析仪的设计与实现。1、信号频率、幅值和相位估计(1)频率(周期)检测对周期信号来说,可以用时域波形分析来确定信号的周期,也就是计算相邻的两个信号波峰的时间差、或过零点的时间差。这里采用过零点(ti)的时间差T(周期)。频率即为f = 1/T,由于能够求得多个T值(ti有多个),故采用它们的平均值作为周期的估计值。(2)幅值检测在一个周期内,求

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中找出最大值与最小值,其差值为双峰值,双峰

3、值的一半即为峰值。P=0.5max(yi)-min(yi)(2)均值估计式中,N为样本容量,下同。(3) 均方值估计方差估计频谱分析原理时域分析只能反映信号的幅值随时间的变化情况,除单频率分量的简单波形外,很难明确提示信号的频率组成和各频率分量大小,而频谱分析能很好的解决此问题。(1)DFT与FFT对于给定的时域信号y,可以通过Fourier变换得到频域信息Y。Y可按下式计算式中,N为样本容量,t = 1/Fs为采样间隔。采样信号的频谱是一个连续的频谱,不可能计算出所有的点的值,故采用离散Fourier变换(DFT),即式中,f = Fs/N。但上式的计算效率很低,因为有大量的指数(等价于三角

4、函数)运算,故实际中多采用快速Fourier变换(FFT)。其原理即是将重复的三角函数算计的中间结果保存起来,以减少重复三角函数计算带来的时间浪费。由于三角函数计算的重复量相当大,故FFT能极大地提高运算效率。(2)频率、周期的估计对于Y(kf),如果当kf = 时,Y(kf)取最大值,则为频率的估计值,由于采样间隔的误差,也存在误差,其误差最大为f / 2。周期T=1/f。从原理上可以看出,如果在标准信号中混有噪声,用上述方法仍能够精确地估计出原标准信号的频率和周期,这个将在下一章做出验证3、频谱图为了直观地表示信号的频率特性,工程上常常将Fourier变换的结果用图形的方式表示,即频谱图。

5、以频率f为横坐标,|Y(f)|为纵坐标,可以得到幅值谱;以频率f为横坐标,arg Y(f)为纵坐标,可以得到相位谱;以频率f为横坐标,Re Y(f)为纵坐标,可以得到实频谱;以频率f为横坐标,Im Y(f)为纵坐标,可以得到虚频谱。根据采样定理,只有频率不超过Fs/2的信号才能被正确采集,即Fourier变换的结果中频率大于Fs/2的部分是不正确的部分,故不在频谱图中显示。即横坐标f 0, Fs/24、模块划分模块化就是把程序划分成独立命名且可独立访问的模块,每个模块完成一个子功能,把这些模块集成起来构成一个整体,可以完成指定的功能满足用户需求。根据人类解决一般问题的经验,如果一个问题由两个问

6、题组合而成,那么它的复杂程度大于分别考虑每个问题时的复杂程度之和,也就是说把复杂的问题分解成许多容易解决的小问题,原来的问题也就容易解决了。这就是模块化的根据。在模块划分时应遵循如下规则:改进软件结构提高模块独立性;模块规模应该适中;深度、宽度、扇出和扇入都应适当;模块的作用域应该在控制域之内;力争降低模块接口的复杂程度;设计单入口单出口的模块;模块功能应该可以预测。实验要求:参考以上原理,查阅相关资料,构建交互界面,设计一个音频频谱分析仪,实现一下功能:音频信号信号输入,从声卡输入、从WAV文件输入、从标准信号发生器输入;信号波形分析,包括幅值、频率、周期、相位的估计,以及统计量峰值、均值、

7、均方值和方差的计算;信号频谱分析,频率、周期的估计,图形显示幅值谱、相位谱、实频谱、虚频谱和功率谱的曲线。实验界面及程序程序: function varargout = yinpin(varargin) % YINPIN M-file for yinpin.fig % YINPIN, by itself, creates a new YINPIN or raises the existing % singleton*. % % H = YINPIN returns the handle to a new YINPIN or the handle to % the existing single

8、ton*. % % YINPIN(CALLBACK,hObject,eventData,handles,.) calls the local % function named CALLBACK in YINPIN.M with the given input arguments. % % YINPIN(Property,Value,.) creates a new YINPIN or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI be

9、fore yinpin_OpeningFunction gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to yinpin_OpeningFcn via varargin. % % *See GUI Options on GUIDEs Tools menu. Choose GUI allows only one % instance to run (singleton). % % See also: GUI

10、DE, GUIDATA, GUIHANDLES % Edit the above text to modify the response to help yinpin % Last Modified by GUIDE v2.5 07-Nov-2012 17:08:53 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct(gui_Name, mfilename, . gui_Singleton, gui_Singleton, . gui_OpeningFcn, yinpin_Opening

11、Fcn, . gui_OutputFcn, yinpin_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 function yinpin_OpeningFcn(hObj

12、ect, eventdata, handles, varargin) handles.output = hObject; guidata(hObject, handles); function varargout = yinpin_OutputFcn(hObject, eventdata, handles) varargout1 = handles.output; function edit1_CreateFcn(hObject, eventdata, handles) if ispc & isequal(get(hObject,BackgroundColor), get(0,defaultU

13、icontrolBackgroundColor) set(hObject,BackgroundColor,white); end function caiyangpinlv_CreateFcn(hObject, eventdata, handles) if ispc & isequal(get(hObject,BackgroundColor), get(0,defaultUicontrolBackgroundColor) set(hObject,BackgroundColor,white); end function caiyangdianshu_CreateFcn(hObject, even

14、tdata, handles) if ispc & isequal(get(hObject,BackgroundColor), get(0,defaultUicontrolBackgroundColor) set(hObject,BackgroundColor,white); end function luyin_Callback(hObject, eventdata, handles) set(handles.luyin,value,1); set(handles.wavfile,value,0); set(handles.xinhaofasheng,value,0); h=findobj(

15、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

16、(Tag,inphase); set(h,enable,off); h=findobj(Tag,mix); set(h,enable,off); h=findobj(Tag,shengchengboxing); set(h,enable,off); function wavfile_Callback(hObject, eventdata, handles) set(handles.luyin,value,0); set(handles.wavfile,value,1); set(handles.xinhaofasheng,value,0); h=findobj(Tag,recordtime);

17、 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); s

18、et(h,enable,off); h=findobj(Tag,mix); set(h,enable,off); h=findobj(Tag,shengchengboxing); set(h,enable,off); function xinhaofasheng_Callback(hObject, eventdata, handles) set(handles.luyin,value,0); set(handles.wavfile,value,0); set(handles.xinhaofasheng,value,1); h=findobj(Tag,recordtime); set(h,ena

19、ble,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

20、,on); h=findobj(Tag,mix); set(h,enable,on); h=findobj(Tag,shengchengboxing); set(h,enable,on); function recordtime_CreateFcn(hObject, eventdata, handles) if ispc & isequal(get(hObject,BackgroundColor), get(0,defaultUicontrolBackgroundColor) set(hObject,BackgroundColor,white); end function kaishiluyi

21、n_Callback(hObject, eventdata, handles) Fs=str2double(get(handles.caiyangpinlv,String); N=str2double(get(handles.recordtime,String)*Fs; handles.y=wavrecord(N, Fs,double); handles.inputtype=1; guidata(hObject,handles); plot(handles.fenxiduixiang,handles.y); ysize=size(handles.y); set(handles.caiyangd

22、ianshu,String,num2str(ysize(1); function wavname_CreateFcn(hObject, eventdata, handles) if ispc & isequal(get(hObject,BackgroundColor), get(0,defaultUicontrolBackgroundColor) set(hObject,BackgroundColor,white); end function liulan_Callback(hObject, eventdata, handles) filename,filepath=uigetfile(*.w

23、av,wavfile); set(handles.wavname,string,filename); handles.y,Fs,bit=wavread(filename); handles.inputtype=2; guidata(hObject,handles); plot(handles.fenxiduixiang,(1:length(handles.y)/10)/Fs,handles.y(1:length(handles.y)/10); ysize=size(handles.y); set(handles.caiyangdianshu,String,num2str(ysize(1); s

24、et(handles.caiyangpinlv,string,Fs); function listbox2_CreateFcn(hObject, eventdata, handles) if ispc & isequal(get(hObject,BackgroundColor), get(0,defaultUicontrolBackgroundColor) set(hObject,BackgroundColor,white); end function inwave_CreateFcn(hObject, eventdata, handles) if ispc & isequal(get(hOb

25、ject,BackgroundColor), get(0,defaultUicontrolBackgroundColor) set(hObject,BackgroundColor,white); end function infudu_CreateFcn(hObject, eventdata, handles) if ispc & isequal(get(hObject,BackgroundColor), get(0,defaultUicontrolBackgroundColor) set(hObject,BackgroundColor,white); end function infre_C

26、reateFcn(hObject, eventdata, handles) if ispc & isequal(get(hObject,BackgroundColor), get(0,defaultUicontrolBackgroundColor) set(hObject,BackgroundColor,white); end function inphase_CreateFcn(hObject, eventdata, handles) if ispc & isequal(get(hObject,BackgroundColor), get(0,defaultUicontrolBackgroun

27、dColor) set(hObject,BackgroundColor,white); end function shengchengboxing_Callback(hObject, eventdata, handles) Fs=str2double(get(findobj(Tag,caiyangpinlv),String); N=str2double(get(findobj(Tag,caiyangdianshu),String); x=linspace(0,N/Fs,N); soundtype=get(handles.inwave,Value); frequency=str2double(g

28、et(handles.infre,String); amp=str2double(get(handles.infudu,String); phase=str2double(get(handles.inphase,String); switch soundtype case 1 y=amp*sin(2*pi*x*frequency+phase); handles.inputtype=3; case 2 y=amp*sign(sin(2*pi*x*frequency+phase); handles.inputtype=3; case 3 y=amp*sawtooth(2*pi*x*frequenc

29、y+phase,0.5); handles.inputtype=3; case 4 y=amp*sawtooth(2*pi*x*frequency+phase); handles.inputtype=3; case 5 y=amp*(2*rand(size(x)-1); handles.inputtype=4; end if get(handles.mix,Value)=0.0 handles.y=y; else handles.y=handles.y+y; end guidata(hObject,handles); plot(handles.fenxiduixiang,handles.y);

30、 title(WAVE); axis(0 N -str2double(get(handles.infudu,String) str2double(get(handles.infudu,String); function edit11_CreateFcn(hObject, eventdata, handles) if ispc & isequal(get(hObject,BackgroundColor), get(0,defaultUicontrolBackgroundColor) set(hObject,BackgroundColor,white); end function edit12_C

31、reateFcn(hObject, eventdata, handles) if ispc & isequal(get(hObject,BackgroundColor), get(0,defaultUicontrolBackgroundColor) set(hObject,BackgroundColor,white); end function popupmenu3_CreateFcn(hObject, eventdata, handles) if ispc & isequal(get(hObject,BackgroundColor), get(0,defaultUicontrolBackgr

32、oundColor) set(hObject,BackgroundColor,white); end function edit13_CreateFcn(hObject, eventdata, handles) if ispc & isequal(get(hObject,BackgroundColor), get(0,defaultUicontrolBackgroundColor) set(hObject,BackgroundColor,white); end function edit14_CreateFcn(hObject, eventdata, handles) if ispc & is

33、equal(get(hObject,BackgroundColor), get(0,defaultUicontrolBackgroundColor) set(hObject,BackgroundColor,white); end function edit15_CreateFcn(hObject, eventdata, handles) if ispc & isequal(get(hObject,BackgroundColor), get(0,defaultUicontrolBackgroundColor) set(hObject,BackgroundColor,white); end fun

34、ction edit9_CreateFcn(hObject, eventdata, handles) if ispc & isequal(get(hObject,BackgroundColor), get(0,defaultUicontrolBackgroundColor) set(hObject,BackgroundColor,white); end function edit10_CreateFcn(hObject, eventdata, handles) if ispc & isequal(get(hObject,BackgroundColor), get(0,defaultUicont

35、rolBackgroundColor) set(hObject,BackgroundColor,white); end function circle_CreateFcn(hObject, eventdata, handles) if ispc & isequal(get(hObject,BackgroundColor), get(0,defaultUicontrolBackgroundColor) set(hObject,BackgroundColor,white); end function outfreq_CreateFcn(hObject, eventdata, handles) if

36、 ispc & isequal(get(hObject,BackgroundColor), get(0,defaultUicontrolBackgroundColor) set(hObject,BackgroundColor,white); end function outamp_CreateFcn(hObject, eventdata, handles) if ispc & isequal(get(hObject,BackgroundColor), get(0,defaultUicontrolBackgroundColor) set(hObject,BackgroundColor,white

37、); end function outphase_CreateFcn(hObject, eventdata, handles) if ispc & isequal(get(hObject,BackgroundColor), get(0,defaultUicontrolBackgroundColor) set(hObject,BackgroundColor,white); end % - Executes during object creation, after setting all properties. function outpeak_CreateFcn(hObject, eventd

38、ata, handles) % hObject handle to outpeak (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

39、(get(hObject,BackgroundColor), get(0,defaultUicontrolBackgroundColor) set(hObject,BackgroundColor,white); end % - Executes during object creation, after setting all properties. function outmean_CreateFcn(hObject, eventdata, handles) % hObject handle to outmean (see GCBO) % eventdata reserved - to be

40、 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

41、,BackgroundColor,white); end % - Executes during object creation, after setting all properties. function edit24_CreateFcn(hObject, eventdata, handles) % hObject handle to edit24 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until

42、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

43、 properties. function outminus_CreateFcn(hObject, eventdata, handles) % hObject handle to outminus (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 backgrou

44、nd 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 foutt_CreateFcn(hObject, eventdata, handles) % hObject ha

45、ndle to foutt (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

46、), get(0,defaultUicontrolBackgroundColor) set(hObject,BackgroundColor,white); end % - Executes during object creation, after setting all properties. function foutfreq_CreateFcn(hObject, eventdata, handles) % hObject handle to foutfreq (see GCBO) % eventdata reserved - to be defined in a future versi

47、on 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); e

48、nd % - Executes during object creation, after setting all properties. function pointfrom_CreateFcn(hObject, eventdata, handles) % hObject handle to pointfrom (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns

49、 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. functio

50、n pointto_CreateFcn(hObject, eventdata, handles) % hObject handle to pointto (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 I

51、SPC and COMPUTER. if ispc & isequal(get(hObject,BackgroundColor), get(0,defaultUicontrolBackgroundColor) set(hObject,BackgroundColor,white); end % - Executes on button press in timeanalyse. function timeanalyse_Callback(hObject, eventdata, handles) Fs=str2double(get(findobj(Tag,caiyangpinlv),String)

52、; N=str2double(get(findobj(Tag,caiyangdianshu),String); if handles.inputtype=0 msgbox(No wave exist! Please choose a input type!); return; end %guo ling jian ce n=1; ymax=max(handles.y(1) handles.y(2); ymin=min(handles.y(1) handles.y(2); from=str2double(get(handles.pointfrom,String); to=str2double(g

53、et(handles.pointto,String); if from1 | to-from5; msgbox(Error range!); return; end for i=from+2:to-1; if handles.y(i-1)0 & handles.y(i-2)=0 & handles.y(i+1)0 if handles.y(i)=0 ti(n)=i; else ti(n)=i-handles.y(i)/(handles.y(i)-handles.y(i-1); end amp(n)=(ymax-ymin)/2; ymax=0; ymin=0; n=n+1; else if ym

54、axhandles.y(i) ymin=handles.y(i); end end end n=n-1; %freqence and periodicity for i=1:n-1 T(i)=ti(i+1)-ti(i); end freq=Fs/mean(T); if (handles.inputtype=1|handles.inputtype=2|handles.inputtype=4) set(handles.circle,String,非周期); set(handles.outfreq,String,非周期); end if(handles.inputtype=3) set(handle

55、s.circle,String,1/freq); set(handles.outfreq,String,num2str(freq); end set(handles.outamp,String,num2str(mean(amp(2:n-1); %phase phase=2*pi*(1-(ti(1:n-1)-1)./T+floor(ti(1:n-1)-1)./T); set(handles.outphase,String,num2str(mean(phase); %peak set(handles.outpeak,String,(max(handles.y(from:to)-min(handle

56、s.y(from:to)/2); %mean set(handles.outmean,String,mean(handles.y(from:to); %meansquare set(handles.outmeansquare,String,mean(handles.y(from:to).2); %s set(handles.outminus,String,std(handles.y(from:to)2); % - function uipanel18_ButtonDownFcn(hObject, eventdata, handles) % hObject handle to uipanel18

57、 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) filename,filepath=uigetfile(*.wav,wavfile); set(handles.wavname,string,filename); handles.y,Fs,bit=wavread(filename); handles.inputtype=2; guidata(hObject,handles); plot(handles.axes1,(1:length(handles.y)/Fs,handles.y); ysize=size(handles.y); set(handles.samplenum,String

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论