音频频谱分析仪设计与实现_第1页
音频频谱分析仪设计与实现_第2页
音频频谱分析仪设计与实现_第3页
音频频谱分析仪设计与实现_第4页
音频频谱分析仪设计与实现_第5页
已阅读5页,还剩16页未读 继续免费阅读

下载本文档

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

文档简介

1、实验八音频频谱分析仪设计与实现一、实验原理MATLAB是一个数据分析和处理功能十分强大的工程实用软件,其数据采集工具箱为 实现数据的输入和输出提供了十分方便的函数和指令。本实验基于声卡与 MATLAB实现音频信号频谱分析仪。1、频率(周期)检测对周期信号来说,可以用时域波形分析来确定信号的周期,也就是计算相邻两个信号 波峰的时间差或过零点的时间差。采用过零点( ti)的时间差T (周期)。频率即为f=1/T, 由于能够求得多个T值,故采用他们的平均值作为周期的估计值。2、峰值检测在一个周期内,求出信号最大值ymax与最小值ymin的差得一半记为 A,同样得到多个A值,但第一个A值对应的ymax

2、和Ymin不是在一个周期内搜索得到的,故以除第一个以外 的A值的平均作为幅值的估计值。3、相位检测采用过零法,即通过判断与同频零相位信号过零点时刻,计算其时间差,然后换成相 应的相位差。中=2冗(1-ti/T),同样以中的平均值作为相位的估计值。4、数字信号统计量估计(1)峰值P的估计在样本数据x中找出最大值与最小值,其差为双峰值,双峰值的一半即为峰值。(2)均值估计i r E(y)=y=N为样本谷量。N(3)均方值估计21:2E(y r工厂(4)方差估计_ 1三“I(yE(y)25、频谱分析原理时域分析只能反映信号的幅值随时间的变化情况,除但频率分量的简单波形外,很难明确提示信号的频率组成和

3、各频率分量大小,而频谱分析能很好的解决此问题。(1) DFT 与 FFT对于给定的日域信号 y,可以通过Fourier变换得到频域信息 Y。Y可按下式计算耨-1N-1r(/)=8。*/的 +*侬。w 00式中,N为样本容量,A t = 1/Fs为采样间隔。采样信号的频谱是一个连续的频谱,不可能计算出所有的点的值,故采用离散Fourier变换(DFT),即理-1了我的=邓如皿所演=0,12, Q式中,Af =Fs/N。但上式的计算效率很低,因为有大量的指数(等价于三角函数)运算,故实际中多采用快速 Fourier变换(FFT)。其原理即是将重复的三角函数算计的中间结果保存起来,以减少重复三角函数

4、计算带来的时间浪费。由于三角函数计算的重复量相当大,故FFT能极大地提高运算效率。(2)频率、周期的估计对于Y(kAf),如果当kAf = f时,Y(kAf)取最大值,则f为频率的估计值,由于采样间隔的误差,f也存在误差,其误差最大为Af/ 2。周期T=1/fo从原理上可以看出,如果在标准信号中混有噪声,用上述方法仍能够精确地估计出原标 准信号的频率和周期。(3)频谱图为了直观地表示信号的频率特性,工程上常常将 Fourier变换的结果用图形的方式表示,即频谱图。以频率f为横坐标, 以频率f为横坐标, 以频率f为横坐标, 以频率f为横坐标,|Y(f)|为纵坐标,可以得到幅值谱; arg Y(f

5、)为纵坐标,可以得到相位谱; Re Y为纵坐标,可以得到实频谱; Im Y(f)为纵坐标,可以得到虚频谱。根据采样定理,只有频率不超过Fs/2的信号才能被正确采集,即 Fourier变换的结果中频率大于Fs/2的部分是不正确的部分,故不在频谱图中显示。即横坐标 f 0, Fs/2 6、模块划分模块化就是把程序划分成独立命名且可独立访问的模块,每个模块完成一个子功能,把这些模块集成起来构成一个整体,可以完成制定的功能,满足用户需求。二、实验内容设计一个音频频谱分析仪,功能包括:(1)音频信号输入,从声卡输入、从 WAV文件输入、从标准信号发生器输入;(2)信号波形分析,包括幅值、频率、周期、相位

6、的估计,以及统计量峰值、均值。均方值和方差的计算。(3)信号频谱分析,频率、周期的估计,图形显示幅值谱、相位谱、时频谱、虚频谱和功率谱的曲线。三.实验结果1.声卡输入(1)正弦波声音信号频谱分析仪下者l里文帕2tHitI白山了-为折时复M第1 .克利留1024匹口分析所营口时续分行幅垣3节间及打所的用川窜m豹血峰值加与9的揖军5 口 M密均0.04的1能Ufl99 965B的万杭4M7.36相悦a 5方建S0O2.212樊续也寸析的用口中口 01的圜期军皿皿他*A.-* q a ii sanipEialt! 5120总挣点瞪产卡 开雎录音 InwetoifliMa10245如工件铁嶷正缶宣任弋

7、茂生嘉5a四方。 Ffll*和依1000.5打开文件生立波黑-1,立麟杆位电M特性eie irm 1Q(2)方波声音信号频谱分析仪存香,气文HMU11002201廿甘疔以第1京到案1024 口分折断前萧w R- K- JU 1UBI MO J1U时用力状朝燧舟折用第0 口 1的占的峰值100W54?师均立0.15315Ufl100由力值1QODO相检Qgg方强10009.7Unwenh力时摒守析的申场出*三折的果 因卬UBI的蒯 朝军WHH 口samptetenla51 的一采样点质1。24尸卡开始录昔住号养生曷1KImwrc川MM M 北 HK % 海 1ttj IHd m J Bffl H

8、 i卜 LEM生成波强由文件餐引耳塞打开文件D4Y1 m L4W1 HEC(3)三角波声音信号频谱分析仪场培耀粉精培思相m0 0199黑军5(1间西随雅0.019054fl9.22斯平50.0409均使-D.0&S5111幅M.0913埼方3334.62相推5,2124方建33&Whmenh甘hfc坤析弟Ji相抵照性M鞋三由苻信号澳生井打开文件力所计置 M1* H作者,痴D11函如?案科电规f、-J- -Uwrpitrtfi, 5120卡 开始录音 nnwrecwd lit他朝节-nrf*1英茹特性HI 1Ei KW 却X!(4)锯齿波声音信号频谱分析仪怕立 范文同加11%必7分时时票4第1吉

9、到第10M萩口分析所书点甘窿普培旦用西0.019&605Q9.9O2250.040S均值).100131幅,M.0225坤方悯33MlMi相也3.S41S方圣3纲也23学堤蹴8忻茎 罔期0019W3 项率$009窿iM盘性(5)白噪声声音信号频谱分析仪蚱者r范文tftRHIQfPKJT分析时就U第1点生僮1也4 JS 存析所有点时ti将麻匕-马雷 0323016峥值99.9543刿甲304部仍均-0 通 17637修区85.5165的方值3534.2B相粗26571方果3537.56IIM*l!l:rill眼埸分析培里颉喈域分析结累国1JUU(的&12Q-采祥点看W24口声卡 行蜡录音 Imr

10、azciECWM成件送鬃闩埠产9 1SSISX3打开文件.W3-,声a 7期里 晤H 相相ie gj| oSS生成渡彩卜*林楸1福斯相捏 UtMiHi 制 2H MH tHMKiffld程序function varargout = fanwenhan(varargin)gui_Singleton = 1; TOC o 1-5 h z gui_State = struct(gui_Name , mfilename,.gui_Singleton , gui_Singleton,.gui_OpeningFcn , fanwenhan_OpeningFcn,.gui_OutputFcn , fanwe

11、nhan_OutputFcn,.gui_LayoutFcn , 口,.gui_Callback ,);if nargin & ischar(varargin1)gui_State.gui_Callback = str2func(varargin1); endif nargoutvarargout1:nargout = gui_mainfcn(gui_State, varargin:); elsegui_mainfcn(gui_State, varargin:);endfunction fanwenhan_OpeningFcn(hObject, eventdata, handles, varar

12、gin) handles.inputtype=0; TOC o 1-5 h z xlabel(handles.plot1,freqency(Hz);xlabel(handles.plot2,freqency(Hz);xlabel(handles.plot3,freqency(Hz);xlabel(handles.plot4,freqency(Hz);xlabel(handles.plot5,freqency(Hz);ylabel(handles.plot1,amplitude );ylabel(handles.plot2,phase(rad) );ylabel(handles.plot3,re

13、al );ylabel(handles.plot4,Imaginary);ylabel(handles.plot5,power );handles.output = hObject;functionvarargout = fanwenhan_OutputFcn(hObject, eventdata, handles)varargout1 = handles.output;functionfigure1_CreateFcn(hObject, eventdata, handles)function timeanalyse_Callback(hObject, eventdata, handles)F

14、s=str2double(get(findobj(Tag , samplerate ), String );N=str2double(get(findobj(Tag , samplenum ), String );if handles.inputtype=0msgbox( No wave exist! Please choose a input type!);return ; end n=1;ymax=max(handles.y(1) handles.y(2);ymin=min(handles.y(1) handles.y(2);from=str2double(get(handles.poin

15、tfrom,String );to=str2double(get(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)0if handles.y(i)=0 ti(n)=i;elseti(n)=i-handles.y(i)/(handles.y(i)-handles.y(i-1); end amp(n)=(ymax-ymin)/2;ymax=

16、0;ymin=0;n=n+1; elseif ymaxhandles.y(i) ymin=handles.y(i);endend end n=n-1;for i=1:n-1T(i)=ti(i+1)-ti(i);endfreq=Fs/mean(T); set(handles.outt, set(handles.outfreq,StringString,1/freq);,num2str(freq);set(handles.outamp,String,num2str(mean(amp(2:n-1);phase=2*pi*(1-(ti(1:n-1)-1)./T+f100r(ti(1:n-1)-1)./

17、T);set(handles.outphase,Stringset(handles.outpeak,Stringrom:to)/2); set(handles.outmean,Stringset(handles.outmeansquare, set(handles.outs, String,num2str(mean(phase);,(max(handles.y(from:to)-min(handles.y(f,mean(handles.y(from:to);String,mean(handles.y(from:to).A2);,std(handles.y(from:to)A2);functio

18、n WAVfile_Callback(hObject, eventdata, handles) h=findobj( Tag , filename );set(h, enable , on); TOC o 1-5 h z h=findobj( Tag , freq ); set(h,enable,off);h=findobj(Tag, amp);set(h,enable,off);h=findobj(Tag, phase);set(h,enable,off);set(findobj(Tag,recordtime),enable , offset(handles.channel,enable,o

19、n);set(handles.fileopen,enable,on);set(handles.gensig,enable ,off);set(handles.wavetype,enable,off);set(handles.add,enable , off);set(handles.startrecord,enable , off );functionsoundcard_Callback(hObject, eventdata, handles)set(findobj(Tag,recordtime),enable , onh=findobj(Tagfilename);set(h, enable

20、,off);h=findobj(Tagfreq );set(h, enable ,off);h=findobj(Tagamp);set(h, enable ,off);h=findobj(Tagphase );set(h, enable ,off);set(handles.channel,enable,off);set(handles.fileopen,enable,off);set(handles.gensig,enable ,off);set(handles.wavetype,enable,off); TOC o 1-5 h z set(handles.add, enable , off

21、);set(handles.startrecord,enable , on);function generator_Callback(hObject, eventdata, handles) h=findobj(Tag,filename);set(h,enable,off);h=findobj( Tag , freq ); set(h,enable,on);h=findobj(Tag,amp);set(h,enable,on);h=findobj(Tag,phase);set(h,enable,on);set(findobj( Tag , recordtime ), enable , off

22、); set(handles.channel,enable , off );set(handles.fileopen,enable, off );set(handles.gensig,enable , on);set(handles.wavetype,enable, on);set(handles.add, enable , on);set(handles.startrecord,enable,off);functionfilename_Callback(hObject, eventdata, handles)functionfilename_CreateFcn(hObject, eventd

23、ata, handles)if ispcset(hObject, BackgroundColor , white ); elseset(hObject, BackgroundColor ,get(0, defaultUicontrolBackgroundColor ); endfunctionfreq_Callback(hObject, eventdata, handles)functionfreq_CreateFcn(hObject, eventdata, handles)if ispcset(hObject, BackgroundColor , white ); elseset(hObje

24、ct, BackgroundColor ,get(0, defaultUicontrolBackgroundColor ); endfunctionamp_Callback(hObject, eventdata, handles)functionamp_CreateFcn(hObject, eventdata, handles)if ispcset(hObject, BackgroundColor , white );elseset(hObject, BackgroundColor ,get(0, defaultUicontrolBackgroundColor);endfunctionphas

25、e_Callback(hObject, eventdata, handles)functionphase_CreateFcn(hObject, eventdata, handles)if ispcset(hObject, BackgroundColor , white );elseset(hObject, BackgroundColor ,get(0, defaultUicontrolBackgroundColor);endfunctionsamplerate_Callback(hObject, eventdata, handles)functionsamplerate_CreateFcn(h

26、Object, eventdata, handles)if ispcset(hObject, BackgroundColor , white ); elseset(hObject, BackgroundColor ,get(0, defaultUicontrolBackgroundColor ); endfunctionsamplenum_Callback(hObject, eventdata, handles)functionsamplenum_CreateFcn(hObject, eventdata, handles)if ispcset(hObject, BackgroundColor

27、, white ); elseset(hObject, BackgroundColor ,get(0, defaultUicontrolBackgroundColor ); endfunctionampfreq_CreateFcn(hObject, eventdata, handles)functionrecordtime_Callback(hObject, eventdata, handles)functionrecordtime_CreateFcn(hObject, eventdata, handles)if ispcset(hObject, BackgroundColor , white

28、 ); elsefunctionset(hObject, BackgroundColor ,get(0, defaultUicontrolBackgroundColor ); endstartrecord_Callback(hObject, eventdata, handles)Fs=str2double(get(findobj(Tag , samplerate ), String );),Strinhandles.y=wavrecord(str2double(get(findobj(Tag , recordtimeg )*Fs, Fs, int16);handles.inputtype=1;

29、 guidata(hObject,handles); plot(handles.time,handles.y); title( WAVE); ysize=size(handles.y) set(handles.samplenum,String ,num2str(ysize(1);function fileopen_Callback(hObject, eventdata, handles) temp = wavread(get(findobj(Tag , filename ), String );channel=str2double(get(handles.channel,String );ha

30、ndles.y=temp(:,channel); handles.inputtype=2; guidata(hObject,handles); plot(handles.time,handles.y); title( WAVE); ysize=size(handles.y) set(handles.samplenum,String ,num2str(ysize(1);function gensig_Callback(hObject, eventdata, handles) Fs=str2double(get(findobj(Tag , samplerate ), String );N=str2

31、double(get(findobj(Tag , samplenum ), String );x=linspace(0,N/Fs,N); soundtype=get(handles.wavetype,Value);frequency=str2double(get(handles.freq,String );amp=str2double(get(handles.amp,String );phase=str2double(get(handles.phase,String );switch soundtype case 1 y=amp*sin(2*pi*x*frequency+phase); cas

32、e 2 y=amp*sign(sin(2*pi*x*frequency+phase); case 3 y=amp*sawtooth(2*pi*x*frequency+phase,0.5); case 4 y=amp*sawtooth(2*pi*x*frequency+phase); case 5 y=amp*(2*rand(size(x)-1); otherwise errordlg(Illegal wave type, Choose errer );end if get(handles.add, Value 尸=0.0 handles.y=y;elsehandles.y=handles.y+

33、y;endhandles.inputtype=3;guidata(hObject,handles);plot(handles.time,handles.y);title( WAVE);axis(0 N -str2double(get(handles.amp,String )str2double(get(handles.amp,String );functionoutfreq_Callback(hObject, eventdata, handles)functionoutfreq_CreateFcn(hObject, eventdata, handles)if ispcset(hObject,

34、BackgroundColor , white ); elseset(hObject, BackgroundColor ,get(0, defaultUicontrolBackgroundColor ); endfunctionoutamp_Callback(hObject, eventdata, handles)functionoutamp_CreateFcn(hObject, eventdata, handles)if ispcset(hObject, BackgroundColor , white ); elseset(hObject, BackgroundColor ,get(0, d

35、efaultUicontrolBackgroundColor ); endfunctionoutphase_Callback(hObject, eventdata, handles)functionoutphase_CreateFcn(hObject, eventdata, handles)if ispcset(hObject, BackgroundColor , white ); elseset(hObject, );BackgroundColor,get(0, defaultUicontrolBackgroundColorendfunctionoutpeak_Callback(hObjec

36、t, eventdata, handles)functionoutpeak_CreateFcn(hObject, eventdata, handles)if ispcset(hObject, BackgroundColor , white ); elseset(hObject, BackgroundColor ,get(0, defaultUicontrolBackgroundColor ); endfunctionoutmean_Callback(hObject, eventdata, handles)functionoutmean_CreateFcn(hObject, eventdata,

37、 handles)if ispcset(hObject, BackgroundColor , white ); elseset(hObject, BackgroundColor ,get(0, defaultUicontrolBackgroundColor ); endfunctionoutmeansquare_Callback(hObject, eventdata, handles)functionoutmeansquare_CreateFcn(hObject, eventdata, handles)if ispcset(hObject, BackgroundColor , white );

38、 elseset(hObject, BackgroundColor ,get(0, defaultUicontrolBackgroundColor ); endfunctionouts_Callback(hObject, eventdata, handles)functionouts_CreateFcn(hObject, eventdata, handles)if ispcset(hObject, BackgroundColor , white );else set(hObject, BackgroundColor ,get(0, defaultUicontrolBackgroundColor

39、);endfunctionfoutfreq_Callback(hObject, eventdata, handles)functionfoutfreq_CreateFcn(hObject, eventdata, handles)if ispcset(hObject, BackgroundColor , white ); elseset(hObject, BackgroundColor ,get(0, defaultUicontrolBackgroundColor ); endfunctionfoutamp_Callback(hObject, eventdata, handles)functio

40、nfoutamp_CreateFcn(hObject, eventdata, handles)if ispcset(hObject, BackgroundColor , white ); elseset(hObject, BackgroundColor ,get(0, defaultUicontrolBackgroundColor ); endfunctionfoutphase_Callback(hObject, eventdata, handles)functionfoutphase_CreateFcn(hObject, eventdata, handles)if ispcset(hObje

41、ct, BackgroundColor , white ); elseset(hObject, BackgroundColor ,get(0, defaultUicontrolBackgroundColor ); endfunction function if ispcedit18_Callback(hObject, eventdata, handles)edit18_CreateFcn(hObject, eventdata, handles)set(hObject, BackgroundColor , white ); elseset(hObject, BackgroundColor ,ge

42、t(0, defaultUicontrolBackgroundColor ); endfunctionedit19_Callback(hObject, eventdata, handles)functionedit19_CreateFcn(hObject, eventdata, handles)if ispcset(hObject, BackgroundColor , white ); elseset(hObject, BackgroundColor ,get(0, defaultUicontrolBackgroundColor ); endfunctionedit20_Callback(hO

43、bject, eventdata, handles)functionedit20_CreateFcn(hObject, eventdata, handles)if ispcset(hObject, BackgroundColor , white ); elseset(hObject, BackgroundColor ,get(0, defaultUicontrolBackgroundColor ); endfunctionedit21_Callback(hObject, eventdata, handles)functionedit21_CreateFcn(hObject, eventdata

44、, handles)if ispcset(hObject, BackgroundColor , white ); elseset(hObject, );BackgroundColor,get(0, defaultUicontrolBackgroundColorendfunction freqanalyse_Callback(hObject, eventdata, handles) Fs=str2double(get(findobj(Tag , samplerate ), String );N=str2double(get(findobj(Tag , samplenum ), String );

45、if handles.inputtype=0msgbox( No wave exist! Please choose a input type!);return ; end from=str2double(get(handles.pointfrom,String );to=str2double(get(handles.pointto,String );sample=handles.y(from:to); f=linspace(0,Fs/2,(to-from+1)/2); Y=fft(sample,to-from+1); C,I=max(abs(Y); set(handles.foutt,Str

46、ing ,1/f(I);set(handles.foutfreq,String ,f(I);Y=Y(1:(to-from+1)/2); plot(handles.plot1,f,2*sqrt(Y.*conj(Y); plot(handles.plot2,f,angle(Y); plot(handles.plot3,f,real(Y); plot(handles.plot4,f,imag(Y); plot(handles.plot5,f,abs(Y).A2); xlabel(handles.plot1,freqency(Hz); TOC o 1-5 h z xlabel(handles.plot

47、2,freqency(Hz);xlabel(handles.plot3,freqency(Hz);xlabel(handles.plot4,freqency(Hz);xlabel(handles.plot5,freqency(Hz);ylabel(handles.plot1,amplitude );ylabel(handles.plot2,phase(rad) );ylabel(handles.plot3,real );ylabel(handles.plot4,Imaginary);ylabel(handles.plot5,power );functionpointfrom_Callback(

48、hObject, eventdata, handles)functionpointfrom_CreateFcn(hObject, eventdata, handles)if ispc set(hObject, BackgroundColor , white ); else set(hObject, BackgroundColor ,get(0, defaultUicontrolBackgroundColor ); endfunctionfunctionpointto_Callback(hObject, eventdata, handles)pointto_CreateFcn(hObject,

49、eventdata, handles) if ispcset(hObject, BackgroundColor , white ); elseset(hObject, BackgroundColor ,get(0, defaultUicontrolBackgroundColor ); end function play_Callback(hObject, eventdata, handles)Fs=str2double(get(findobj(Tag , samplerate ), String );wavplay(handles.y,Fs);function scale_Callback(h

50、Object, eventdata, handles)val=get(hObject, value );val=10A(val*5+1);x=get(handles.xmove, Value )*str2double(get(handles.samplenum,String);axis(handles.time,x val+x min(handles.y) max(handles.y);function scale_CreateFcn(hObject, eventdata, handles) usewhitebg = 1; if usewhitebgset(hObject, Backgroun

51、dColor ,.9 .9 .9); elseset(hObject, BackgroundColor ,get(0, defaultUicontrolBackgroundColor ); end function scale2_Callback(hObject, eventdata, handles) val=get(hObject, value );val=10A(val*5+1);xlim(handles.plot1,0 val);xlim(handles.plot2,0 val);xlim(handles.plot3,0 val);xlim(handles.plot4,0 val);f

52、unction scale2_CreateFcn(hObject, eventdata, handles) usewhitebg = 1;if usewhitebgset(hObject, BackgroundColor ,.9 .9 .9); elseset(hObject, BackgroundColor ,get(0, defaultUicontrolBackgroundColor ); endfunctionchannel_Callback(hObject, eventdata, handles)functionchannel_CreateFcn(hObject, eventdata, handles)if ispcset(hObject, BackgroundColor , white ); elseset(hObject, BackgroundColor ,get(0, defaultUicontrolBackgroundColor ); endfunctionwavetype_Callback(hObject, eventdata, handles)functionwavetyp

温馨提示

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

评论

0/150

提交评论