




已閱讀5頁,還剩14頁未讀, 繼續(xù)免費閱讀
版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
實驗八 音頻頻譜分析儀設計與實現1、 實驗原理MATLAB是一個數據分析和處理功能十分強大的工程實用軟件,其數據采集工具箱為實現數據的輸入和輸出提供了十分方便的函數和指令。本實驗基于聲卡與MATLAB實現音頻信號頻譜分析儀。 1、頻率(周期)檢測 對周期信號來說,可以用時域波形分析來確定信號的周期,也就是計算相鄰兩個信號波峰的時間差或過零點的時間差。采用過零點(ti)的時間差T(周期)。頻率即為f=1/T,由于能夠求得多個T值,故采用他們的平均值作為周期的估計值。 2、峰值檢測 在一個周期內,求出信號最大值與最小值的差得一半記為A,同樣得到多個A值,但第一個A值對應的和不是在一個周期內搜索得到的,故以除第一個以外的A值的平均作為幅值的估計值。 3、相位檢測 采用過零法,即通過判斷與同頻零相位信號過零點時刻,計算其時間差,然后換成相應的相位差。,同樣以的平均值作為相位的估計值。 4、數字信號統(tǒng)計量估計 (1)峰值P的估計 在樣本數據x中找出最大值與最小值,其差為雙峰值,雙峰值的一半即為峰值。 (2)均值估計 ,N為樣本容量。 (3)均方值估計 (4)方差估計 5、頻譜分析原理 時域分析只能反映信號的幅值隨時間的變化情況,除但頻率分量的簡單波形外,很難明確提示信號的頻率組成和各頻率分量大小,而頻譜分析能很好的解決此問題。(1)DFT與FFT對于給定的時域信號y,可以通過Fourier變換得到頻域信息Y。Y可按下式計算式中,N為樣本容量,t = 1/Fs為采樣間隔。采樣信號的頻譜是一個連續(xù)的頻譜,不可能計算出所有的點的值,故采用離散Fourier變換(DFT),即式中,f = Fs/N。但上式的計算效率很低,因為有大量的指數(等價于三角函數)運算,故實際中多采用快速Fourier變換(FFT)。其原理即是將重復的三角函數算計的中間結果保存起來,以減少重復三角函數計算帶來的時間浪費。由于三角函數計算的重復量相當大,故FFT能極大地提高運算效率。(2) 頻率、周期的估計 對于Y(kf),如果當kf = 時,Y(kf)取最大值,則為頻率的估計值,由于采樣間隔的誤差,也存在誤差,其誤差最大為f / 2。周期T=1/f。從原理上可以看出,如果在標準信號中混有噪聲,用上述方法仍能夠精確地估計出原標準信號的頻率和周期。 (3)頻譜圖為了直觀地表示信號的頻率特性,工程上常常將Fourier變換的結果用圖形的方式表示,即頻譜圖。以頻率f為橫坐標,|Y(f)|為縱坐標,可以得到幅值譜;以頻率f為橫坐標,arg Y(f)為縱坐標,可以得到相位譜;以頻率f為橫坐標,Re Y(f)為縱坐標,可以得到實頻譜;以頻率f為橫坐標,Im Y(f)為縱坐標,可以得到虛頻譜。根據采樣定理,只有頻率不超過Fs/2的信號才能被正確采集,即Fourier變換的結果中頻率大于Fs/2的部分是不正確的部分,故不在頻譜圖中顯示。即橫坐標f 0, Fs/26、 模塊劃分 模塊化就是把程序劃分成獨立命名且可獨立訪問的模塊,每個模塊完成一個子功能,把這些模塊集成起來構成一個整體,可以完成制定的功能,滿足用戶需求。2、 實驗內容設計一個音頻頻譜分析儀,功能包括:(1) 音頻信號輸入,從聲卡輸入、從WAV文件輸入、從標準信號發(fā)生器輸入;(2) 信號波形分析,包括幅值、頻率、周期、相位的估計,以及統(tǒng)計量峰值、均值。均方值和方差的計算。(3) 信號頻譜分析,頻率、周期的估計,圖形顯示幅值譜、相位譜、時頻譜、虛頻譜和功率譜的曲線。3 實驗結果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)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 摩托車發(fā)動機燃油噴射器清洗方法考核試卷
- 職業(yè)中介服務在解決就業(yè)問題中的作用考核試卷
- 森林改培對水土流失的防治措施考核試卷
- 水產品市場的消費者行為與購買習慣分析考核試卷
- 山東省武城縣2025年初三年級下學期期末質量檢測試題化學試題含解析
- 四川文軒職業(yè)學院《英語語言能力與測試(B)》2023-2024學年第一學期期末試卷
- 武漢商學院《空間設計》2023-2024學年第二學期期末試卷
- 培黎職業(yè)學院《健身健美》2023-2024學年第一學期期末試卷
- 山東科技職業(yè)學院《中文工具書使用與社科信息檢索》2023-2024學年第一學期期末試卷
- 山東文化產業(yè)職業(yè)學院《廣告學概論》2023-2024學年第二學期期末試卷
- 2025年內蒙古中煤蒙大新能源化工有限公司招聘筆試參考題庫附帶答案詳解
- 年產16.6萬噸工業(yè)涂料用樹脂、2.8萬噸裝配式建筑用硅烷改性膠粘劑用樹脂、2萬噸高性能防水涂料用樹脂項目(一期)公眾參與說明
- “4 組織環(huán)境-4.2理解相關方的需求和期望”專業(yè)深度解讀與應用指導材料(雷澤佳編制-2025C1)
- 插畫版權授權協(xié)議書
- 湖北省第十屆湖北省高三(4月)調研模擬考試數學試題及答案
- 五一勞動節(jié)前安全檢查重點
- 地理西亞+課件-2024-2025學年七年級地理下冊人教版
- 診所醫(yī)療質量相關管理制度
- CHINET2024年全年細菌耐藥監(jiān)測結果
- 膀胱癌健康宣教課件
- DBJ50T-284-2018 工程勘察信息模型設計標準
評論
0/150
提交評論