音頻頻譜分析儀設(shè)計(jì)與實(shí)現(xiàn).doc_第1頁
音頻頻譜分析儀設(shè)計(jì)與實(shí)現(xiàn).doc_第2頁
音頻頻譜分析儀設(shè)計(jì)與實(shí)現(xiàn).doc_第3頁
音頻頻譜分析儀設(shè)計(jì)與實(shí)現(xiàn).doc_第4頁
音頻頻譜分析儀設(shè)計(jì)與實(shí)現(xiàn).doc_第5頁
已閱讀5頁,還剩14頁未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

實(shí)驗(yàn)八 音頻頻譜分析儀設(shè)計(jì)與實(shí)現(xiàn)1、 實(shí)驗(yàn)原理MATLAB是一個(gè)數(shù)據(jù)分析和處理功能十分強(qiáng)大的工程實(shí)用軟件,其數(shù)據(jù)采集工具箱為實(shí)現(xiàn)數(shù)據(jù)的輸入和輸出提供了十分方便的函數(shù)和指令。本實(shí)驗(yàn)基于聲卡與MATLAB實(shí)現(xiàn)音頻信號(hào)頻譜分析儀。 1、頻率(周期)檢測 對周期信號(hào)來說,可以用時(shí)域波形分析來確定信號(hào)的周期,也就是計(jì)算相鄰兩個(gè)信號(hào)波峰的時(shí)間差或過零點(diǎn)的時(shí)間差。采用過零點(diǎn)(ti)的時(shí)間差T(周期)。頻率即為f=1/T,由于能夠求得多個(gè)T值,故采用他們的平均值作為周期的估計(jì)值。 2、峰值檢測 在一個(gè)周期內(nèi),求出信號(hào)最大值與最小值的差得一半記為A,同樣得到多個(gè)A值,但第一個(gè)A值對應(yīng)的和不是在一個(gè)周期內(nèi)搜索得到的,故以除第一個(gè)以外的A值的平均作為幅值的估計(jì)值。 3、相位檢測 采用過零法,即通過判斷與同頻零相位信號(hào)過零點(diǎn)時(shí)刻,計(jì)算其時(shí)間差,然后換成相應(yīng)的相位差。,同樣以的平均值作為相位的估計(jì)值。 4、數(shù)字信號(hào)統(tǒng)計(jì)量估計(jì) (1)峰值P的估計(jì) 在樣本數(shù)據(jù)x中找出最大值與最小值,其差為雙峰值,雙峰值的一半即為峰值。 (2)均值估計(jì) ,N為樣本容量。 (3)均方值估計(jì) (4)方差估計(jì) 5、頻譜分析原理 時(shí)域分析只能反映信號(hào)的幅值隨時(shí)間的變化情況,除但頻率分量的簡單波形外,很難明確提示信號(hào)的頻率組成和各頻率分量大小,而頻譜分析能很好的解決此問題。(1)DFT與FFT對于給定的時(shí)域信號(hào)y,可以通過Fourier變換得到頻域信息Y。Y可按下式計(jì)算式中,N為樣本容量,t = 1/Fs為采樣間隔。采樣信號(hào)的頻譜是一個(gè)連續(xù)的頻譜,不可能計(jì)算出所有的點(diǎn)的值,故采用離散Fourier變換(DFT),即式中,f = Fs/N。但上式的計(jì)算效率很低,因?yàn)橛写罅康闹笖?shù)(等價(jià)于三角函數(shù))運(yùn)算,故實(shí)際中多采用快速Fourier變換(FFT)。其原理即是將重復(fù)的三角函數(shù)算計(jì)的中間結(jié)果保存起來,以減少重復(fù)三角函數(shù)計(jì)算帶來的時(shí)間浪費(fèi)。由于三角函數(shù)計(jì)算的重復(fù)量相當(dāng)大,故FFT能極大地提高運(yùn)算效率。(2) 頻率、周期的估計(jì) 對于Y(kf),如果當(dāng)kf = 時(shí),Y(kf)取最大值,則為頻率的估計(jì)值,由于采樣間隔的誤差,也存在誤差,其誤差最大為f / 2。周期T=1/f。從原理上可以看出,如果在標(biāo)準(zhǔn)信號(hào)中混有噪聲,用上述方法仍能夠精確地估計(jì)出原標(biāo)準(zhǔn)信號(hào)的頻率和周期。 (3)頻譜圖為了直觀地表示信號(hào)的頻率特性,工程上常常將Fourier變換的結(jié)果用圖形的方式表示,即頻譜圖。以頻率f為橫坐標(biāo),|Y(f)|為縱坐標(biāo),可以得到幅值譜;以頻率f為橫坐標(biāo),arg Y(f)為縱坐標(biāo),可以得到相位譜;以頻率f為橫坐標(biāo),Re Y(f)為縱坐標(biāo),可以得到實(shí)頻譜;以頻率f為橫坐標(biāo),Im Y(f)為縱坐標(biāo),可以得到虛頻譜。根據(jù)采樣定理,只有頻率不超過Fs/2的信號(hào)才能被正確采集,即Fourier變換的結(jié)果中頻率大于Fs/2的部分是不正確的部分,故不在頻譜圖中顯示。即橫坐標(biāo)f 0, Fs/26、 模塊劃分 模塊化就是把程序劃分成獨(dú)立命名且可獨(dú)立訪問的模塊,每個(gè)模塊完成一個(gè)子功能,把這些模塊集成起來構(gòu)成一個(gè)整體,可以完成制定的功能,滿足用戶需求。2、 實(shí)驗(yàn)內(nèi)容設(shè)計(jì)一個(gè)音頻頻譜分析儀,功能包括:(1) 音頻信號(hào)輸入,從聲卡輸入、從WAV文件輸入、從標(biāo)準(zhǔn)信號(hào)發(fā)生器輸入;(2) 信號(hào)波形分析,包括幅值、頻率、周期、相位的估計(jì),以及統(tǒng)計(jì)量峰值、均值。均方值和方差的計(jì)算。(3) 信號(hào)頻譜分析,頻率、周期的估計(jì),圖形顯示幅值譜、相位譜、時(shí)頻譜、虛頻譜和功率譜的曲線。3 實(shí)驗(yàn)結(jié)果1.聲卡輸入(1) 正弦波 (2)方波(3) 三角波(4) 鋸齒波(5) 白噪聲程序function varargout = fanwenhan(varargin)gui_Singleton = 1;gui_State = struct(gui_Name, mfilename, . gui_Singleton, gui_Singleton, . gui_OpeningFcn, fanwenhan_OpeningFcn, . gui_OutputFcn, fanwenhan_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:);endfunction fanwenhan_OpeningFcn(hObject, eventdata, handles, varargin)handles.inputtype=0;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,real);ylabel(handles.plot4,Imaginary);ylabel(handles.plot5,power);handles.output = hObject;function varargout = fanwenhan_OutputFcn(hObject, eventdata, handles) varargout1 = handles.output;function figure1_CreateFcn(hObject, eventdata, handles)function timeanalyse_Callback(hObject, eventdata, handles)Fs=str2double(get(findobj(Tag,samplerate),String);N=str2double(get(findobj(Tag,samplenum),String);if handles.inputtype=0 msgbox(No wave exist! Please choose a input type!); return;endn=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(get(handles.pointto,String);if from1 | to-from5; msgbox(Error range!); return;endfor 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 ymaxhandles.y(i) ymin=handles.y(i); end endendn=n-1;for i=1:n-1 T(i)=ti(i+1)-ti(i);endfreq=Fs/mean(T);set(handles.outt,String,1/freq);set(handles.outfreq,String,num2str(freq);set(handles.outamp,String,num2str(mean(amp(2:n-1);phase=2*pi*(1-(ti(1:n-1)-1)./T+floor(ti(1:n-1)-1)./T);set(handles.outphase,String,num2str(mean(phase);set(handles.outpeak,String,(max(handles.y(from:to)-min(handles.y(from:to)/2);set(handles.outmean,String,mean(handles.y(from:to);set(handles.outmeansquare,String,mean(handles.y(from:to).2);set(handles.outs,String,std(handles.y(from:to)2);function WAVfile_Callback(hObject, eventdata, handles)h=findobj(Tag,filename);set(h,enable,on);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,off);set(handles.channel,enable,on);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);function soundcard_Callback(hObject, eventdata, handles)set(findobj(Tag,recordtime),enable,on);h=findobj(Tag,filename);set(h,enable,off);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(handles.channel,enable,off);set(handles.fileopen,enable,off);set(handles.gensig,enable,off);set(handles.wavetype,enable,off);set(handles.add,enable,off);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);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); function filename_Callback(hObject, eventdata, handles)function filename_CreateFcn(hObject, eventdata, handles)if ispc set(hObject,BackgroundColor,white);else set(hObject,BackgroundColor,get(0,defaultUicontrolBackgroundColor);end function freq_Callback(hObject, eventdata, handles)function freq_CreateFcn(hObject, eventdata, handles)if ispc set(hObject,BackgroundColor,white);else set(hObject,BackgroundColor,get(0,defaultUicontrolBackgroundColor);end function amp_Callback(hObject, eventdata, handles)function amp_CreateFcn(hObject, eventdata, handles)if ispc set(hObject,BackgroundColor,white);else set(hObject,BackgroundColor,get(0,defaultUicontrolBackgroundColor);end function phase_Callback(hObject, eventdata, handles)function phase_CreateFcn(hObject, eventdata, handles)if ispc set(hObject,BackgroundColor,white);else set(hObject,BackgroundColor,get(0,defaultUicontrolBackgroundColor);end function samplerate_Callback(hObject, eventdata, handles)function samplerate_CreateFcn(hObject, eventdata, handles)if ispc set(hObject,BackgroundColor,white);else set(hObject,BackgroundColor,get(0,defaultUicontrolBackgroundColor);end function samplenum_Callback(hObject, eventdata, handles)function samplenum_CreateFcn(hObject, eventdata, handles)if ispc set(hObject,BackgroundColor,white);else set(hObject,BackgroundColor,get(0,defaultUicontrolBackgroundColor);end function ampfreq_CreateFcn(hObject, eventdata, handles)function recordtime_Callback(hObject, eventdata, handles)function recordtime_CreateFcn(hObject, eventdata, handles)if ispc set(hObject,BackgroundColor,white);else set(hObject,BackgroundColor,get(0,defaultUicontrolBackgroundColor);end function startrecord_Callback(hObject, eventdata, handles)Fs=str2double(get(findobj(Tag,samplerate),String);handles.y=wavrecord(str2double(get(findobj(Tag,recordtime),String)*Fs, Fs,int16);handles.inputtype=1;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);handles.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=str2double(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); case 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);endif get(handles.add,Value)=0.0 handles.y=y;else handles.y=handles.y+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); function outfreq_Callback(hObject, eventdata, handles)function outfreq_CreateFcn(hObject, eventdata, handles)if ispc set(hObject,BackgroundColor,white);else set(hObject,BackgroundColor,get(0,defaultUicontrolBackgroundColor);end function outamp_Callback(hObject, eventdata, handles)function outamp_CreateFcn(hObject, eventdata, handles)if ispc set(hObject,BackgroundColor,white);else set(hObject,BackgroundColor,get(0,defaultUicontrolBackgroundColor);end function outphase_Callback(hObject, eventdata, handles)function outphase_CreateFcn(hObject, eventdata, handles)if ispc set(hObject,BackgroundColor,white);else set(hObject,BackgroundColor,get(0,defaultUicontrolBackgroundColor);end function outpeak_Callback(hObject, eventdata, handles)function outpeak_CreateFcn(hObject, eventdata, handles)if ispc set(hObject,BackgroundColor,white);else set(hObject,BackgroundColor,get(0,defaultUicontrolBackgroundColor);end function outmean_Callback(hObject, eventdata, handles)function outmean_CreateFcn(hObject, eventdata, handles)if ispc set(hObject,BackgroundColor,white);else set(hObject,BackgroundColor,get(0,defaultUicontrolBackgroundColor);end function outmeansquare_Callback(hObject, eventdata, handles)function outmeansquare_CreateFcn(hObject, eventdata, handles)if ispc set(hObject,BackgroundColor,white);else set(hObject,BackgroundColor,get(0,defaultUicontrolBackgroundColor);end function outs_Callback(hObject, eventdata, handles)function outs_CreateFcn(hObject, eventdata, handles)if ispc set(hObject,BackgroundColor,white);else set(hObject,BackgroundColor,get(0,defaultUicontrolBackgroundColor);end function foutfreq_Callback(hObject, eventdata, handles)function foutfreq_CreateFcn(hObject, eventdata, handles)if ispc set(hObject,BackgroundColor,white);else set(hObject,BackgroundColor,get(0,defaultUicontrolBackgroundColor);end function foutamp_Callback(hObject, eventdata, handles)function foutamp_CreateFcn(hObject, eventdata, handles)if ispc set(hObject,BackgroundColor,white);else set(hObject,BackgroundColor,get(0,defaultUicontrolBackgroundColor);end function foutphase_Callback(hObject, eventdata, handles)function foutphase_CreateFcn(hObject, eventdata, handles)if ispc set(hObject,BackgroundColor,white);else set(hObject,BackgroundColor,get(0,defaultUicontrolBackgroundColor);end function edit18_Callback(hObject, eventdata, handles)function edit18_CreateFcn(hObject, eventdata, handles)if ispc set(hObject,BackgroundColor,white);else set(hObject,BackgroundColor,get(0,defaultUicontrolBackgroundColor);end function edit19_Callback(hObject, eventdata, handles)function edit19_CreateFcn(hObject, eventdata, handles)if ispc set(hObject,BackgroundColor,white);else set(hObject,BackgroundColor,get(0,defaultUicontrolBackgroundColor);end function edit20_Callback(hObject, eventdata, handles)function edit20_CreateFcn(hObject, eventdata, handles)if ispc set(hObject,BackgroundColor,white);else set(hObject,BackgroundColor,get(0,defaultUicontrolBackgroundColor);end function edit21_Callback(hObject, eventdata, handles)function edit21_CreateFcn(hObject, eventdata, handles)if ispc set(hObject,BackgroundColor,white);else set(hObject,BackgroundColor,get(0,defaultUicontrolBackgroundColor);end function freqanalyse_Callback(hObject, eventdata, handles)Fs=str2double(get(findobj(Tag,samplerate),String);N=str2double(get(findobj(Tag,samplenum),String);if handles.inputtype=0 msgbox(No wave exist! Please choose a input type!); return;endfrom=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,String,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).2);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,real);ylabel(handles.plot4,Imaginary);ylabel(handles.plot5,power); function pointfrom_Callback(hObject, eventdata, handles)function pointfrom_CreateFcn(hObject, eventdata, handles)if ispc set(hObject,BackgroundColor,white);else set(hObject,BackgroundColor,get(0,defaultUicontrolBackgroundColor);end function pointto_Callback(hObject, eventdata, handles)function pointto_CreateFcn(hObject, eventdata, handles)if ispc set(hObject,BackgroundColor,white);else set(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(hObject, eventdata, handles)val=get(hObject,value);val=10(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 usewhitebg set(hObject,BackgroundColor,.9 .9 .9);else set(hObject,BackgroundColor,get(0,defaultUicontrolBackgroundColor);end function scale2_Callback(hObject, eventdata, handles)val=get(hObject,value);val=10(val*5+1);xlim(handles.plot1,0 val);xlim(handles.plot2,0 val);xlim(handles.plot3,0 val);xlim(handles.plot4,0 val);function scale2_CreateFcn(hObject, eventdata, handles)usewhitebg = 1;if usewhitebg set(hObject,BackgroundColor,.9 .9 .9);else set(hObject,BackgroundColor,get(0,defaultUicontrolBackgroundColor);end function channel_Callback(hObject, eventdata, handles)function channel_CreateFcn(hObject, eventdata, handles)if ispc set(hObject,BackgroundColor,white);else set(hObject,BackgroundColor,get(0,defaultUicontrolBackgroundColor);end function wavetype_Callback(hObject, eventdata, handles)function wavetype_CreateFcn(hObject, eventdata, handles)if ispc set(hObject,BackgroundColor,white);else set(hObject,BackgroundColor,get(0,defaultUicont

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論