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

下載本文檔

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

文檔簡(jiǎn)介

實(shí)驗(yàn)八:音頻頻譜分析儀設(shè)計(jì)與實(shí)現(xiàn)一、實(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)頻譜分析儀的設(shè)計(jì)原理與實(shí)現(xiàn),功能包括:(1)音頻信號(hào)輸入,從聲卡輸入,從WAV文件輸入,從標(biāo)準(zhǔn)信號(hào)發(fā)生器輸入;(2)信號(hào)波形分析,包括幅值,頻率,周期,相位的估計(jì),以及統(tǒng)計(jì)量峰值,均值,均方值和方差的計(jì)算;(3)信號(hào)頻譜分析,頻率,周期的估計(jì),圖形顯示幅值譜,相位譜,實(shí)頻譜,虛頻譜和功率譜的曲線。1.頻率(周期)檢測(cè)對(duì)周期信號(hào)來說,可以用時(shí)域波形分析來確定信號(hào)的周期,也就是計(jì)算相鄰的兩個(gè)信號(hào)波峰的時(shí)間差,或過零點(diǎn)的時(shí)間差。這里采用過零點(diǎn)(t)的時(shí)間差T(周期)。頻率即為頻率即為f=1/T,由于能夠求得多個(gè)T值,故采用他們的平均值作為周期的估計(jì)值。2.幅值檢測(cè)在一個(gè)周期內(nèi),求出信號(hào)最大值與最小值的差得一半記為A,同樣得到多個(gè)A值,但第一個(gè)A值對(duì)應(yīng)的和不是在一個(gè)周期內(nèi)搜索得到的,故以除第一個(gè)以外的A值的平均作為幅值的估計(jì)值。3.相位檢測(cè)采用過零法,即通過判斷與同頻零相位信號(hào)過零點(diǎn)時(shí)刻,計(jì)算其時(shí)間差,然后換成相應(yīng)的相位差。,同樣以的平均值作為相位的估計(jì)值。4.數(shù)字信號(hào)統(tǒng)計(jì)量估計(jì) (1)峰值P的估計(jì) 在樣本數(shù)據(jù)x中找出最大值與最小值,其差為雙峰值,雙峰值的一半即為峰值。 P=0.5max(y)-min(y) (2)均值估計(jì) N為樣本容量。 (3)均方值估計(jì) (4)方差估計(jì) 5.頻譜分析原理時(shí)域分析只能反映信號(hào)的幅值隨時(shí)間的變化情況,除但頻率分量的簡(jiǎn)單波形外,很難明確提示信號(hào)的頻率組成和各頻率分量大小,而頻譜分析能很好的解決此問題。(1)DFT與FFT對(duì)于給定的時(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ì)對(duì)于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/2(4)模塊劃分模塊化就是把程序劃分成獨(dú)立命名且可獨(dú)立訪問的模塊,每個(gè)模塊完成一個(gè)子功能,把這些模塊集成起來構(gòu)成一個(gè)整體,可以完成制定的功能,滿足用戶需求。在模塊分化時(shí)應(yīng)遵循如下原則:改進(jìn)軟件結(jié)構(gòu)提高模塊獨(dú)立性;模塊規(guī)模應(yīng)該適中;深度、寬度、扇出和扇入都應(yīng)適當(dāng);模塊的作用域應(yīng)該在控制域之內(nèi);力爭(zhēng)降低模塊接口的復(fù)雜程度;設(shè)計(jì)單入口單出口的模塊;模塊功能應(yīng)該可以預(yù)測(cè)。二、實(shí)驗(yàn)內(nèi)容:參考給定的代碼,構(gòu)建交互界面,設(shè)計(jì)一個(gè)音頻頻譜分析儀,實(shí)現(xiàn)相應(yīng)的功能。程序文本:function varargout = GGfig(varargin)% GGFIG M-file for GGfig.fig% GGFIG, by itself, creates a new GGFIG or raises the existing% singleton*.% H = GGFIG returns the handle to a new GGFIG or the handle to% the existing singleton*.% GGFIG(CALLBACK,hObject,eventData,handles,.) calls the local% function named CALLBACK in GGFIG.M with the given input arguments.% GGFIG(Property,Value,.) creates a new GGFIG or raises the% existing singleton*. Starting from the left, property value pairs are% applied to the GUI before GGfig_OpeningFunction gets called. An% unrecognized property name or invalid value makes property application% stop. All inputs are passed to GGfig_OpeningFcn via varargin.% *See GUI Options on GUIDEs Tools menu. Choose GUI allows only one% instance to run (singleton).% See also: GUIDE, GUIDATA, GUIHANDLES % Edit the above text to modify the response to help GGfig % Last Modified by GUIDE v2.5 26-Dec-2014 21:19:45 % Begin initialization code - DO NOT EDITgui_Singleton = 1;gui_State = struct(gui_Name, mfilename, . gui_Singleton, gui_Singleton, . gui_OpeningFcn, GGfig_OpeningFcn, . gui_OutputFcn, GGfig_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% End initialization code - DO NOT EDIT % - Executes just before GGfig is made visible.function GGfig_OpeningFcn(hObject, eventdata, handles, varargin)% This function has no output args, see OutputFcn.% hObject handle to figure% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% varargin command line arguments to GGfig (see VARARGIN) % Choose default command line output for GGfighandles.output = hObject; % Update handles structureguidata(hObject, handles); % UIWAIT makes zhaiqi wait for user response (see UIRESUME)% uiwait(handles.figure1); % - Outputs from this function are returned to the command line.function varargout = GGfig_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT);% hObject handle to figure% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA) % Get default command line output from handles structurevarargout1 = handles.output; % - Executes on button press in inputradiobutton.function inputradiobutton_Callback(hObject, eventdata, handles)% hObject handle to inputradiobutton (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA) % Hint: get(hObject,Value) returns toggle state of inputradiobuttonfunction filename_Callback(hObject, eventdata, handles)% hObject handle to filename (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,String) returns contents of filename as text% str2double(get(hObject,String) returns contents of filename as a double % - Executes during object creation, after setting all properties.function filename_CreateFcn(hObject, eventdata, handles)% hObject handle to filename (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), get(0,defaultUicontrolBackgroundColor) set(hObject,BackgroundColor,white);end % - Executes on button press in pushbutton1.function pushbutton1_Callback(hObject, eventdata, handles)filename,pathname=uigetfile(*.wav);set(handles.filename,String,filename);% hObject handle to pushbutton1 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)temp = wavread(get(findobj(Tag,filename),String);channel = str2double(get(handles.channelinput,String);handles.y = temp(:,channel);plot(handles.axes3,0:length(handles.y)-1,handles.y);%波形title(波形);guidata(hObject, handles);ysize = size(handles.y);set(handles.edit4,String,num2str(ysize(1);set(handles.edit20,String,num2str(ysize(1); function channelinput_Callback(hObject, eventdata, handles)% hObject handle to channelinput (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,String) returns contents of channelinput as text% str2double(get(hObject,String) returns contents of channelinput as a double % - Executes during object creation, after setting all properties.function channelinput_CreateFcn(hObject, eventdata, handles)% hObject handle to channelinput (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), get(0,defaultUicontrolBackgroundColor) set(hObject,BackgroundColor,white);end function edit3_Callback(hObject, eventdata, handles)% hObject handle to edit3 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,String) returns contents of edit3 as text% str2double(get(hObject,String) returns contents of edit3 as a double % - Executes during object creation, after setting all properties.function edit3_CreateFcn(hObject, eventdata, handles)% hObject handle to edit3 (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), get(0,defaultUicontrolBackgroundColor) set(hObject,BackgroundColor,white);end function edit4_Callback(hObject, eventdata, handles)% hObject handle to edit4 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,String) returns contents of edit4 as text% str2double(get(hObject,String) returns contents of edit4 as a double % - Executes during object creation, after setting all properties.function edit4_CreateFcn(hObject, eventdata, handles)% hObject handle to edit4 (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), get(0,defaultUicontrolBackgroundColor) set(hObject,BackgroundColor,white);end% - Executes on mouse press over axes background.function axes2_ButtonDownFcn(hObject, eventdata, handles)% hObject handle to axes2 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA) % - Executes on button press in pushbutton3.function pushbutton3_Callback(hObject, eventdata, handles)% hObject handle to pushbutton3 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)from = str2double(get(findobj(Tag,edit19),String);to = str2double(get(findobj(Tag,edit20),String);Fs = str2double(get(findobj(Tag,edit3),String);temp2 = handles.y(from:to);H = fft(temp2,to-from+1);L = ceil(length(H)/2);n = 0:L-1; C,I = max(abs(H);set(handles.edit13,String,1/(n(I)/L*pi*Fs/2/pi);set(handles.edit14,String,(n(I)/L*pi*Fs/2/pi);if(I = 1)set(handles.edit13,String,無限長); set(handles.edit14,String,直流);end %guo ling jian cen=1;ymax=max(handles.y(1) handles.y(2);ymin=min(handles.y(1) handles.y(2);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);% x1=i-1;% y1=handles.y(i-1);% x2=i;% y2=handles.y(i);% a=handles.y(i)-handles.y(i-1);% b=a*x1-y1;% ti(n)=b/a; 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;%freqence and periodicityfor i=1:n-1 T(i)=ti(i+1)-ti(i);endfreq = Fs/mean(T);%計(jì)算頻率set(handles.edit5,String,1/freq);%周期set(handles.edit6,String,num2str(freq);%頻率%幅值set(handles.edit7,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.edit8,String,num2str(mean(phase);%峰值set(handles.edit9,String,(max(handles.y(from:to)-min(handles.y(from:to)/2);%均值set(handles.edit10,String,mean(handles.y(from:to);%均方值set(handles.edit11,String,mean(handles.y(from:to).2);%半方差set(handles.edit12,String,std(handles.y(from:to)2);function pushbutton8_Callback(hObject, eventdata, handles)% hObject handle to pushbutton3 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)from = str2double(get(findobj(Tag,edit19),String);to = str2double(get(findobj(Tag,edit20),String);Fs = str2double(get(findobj(Tag,edit3),String);temp2 = handles.y(from:to);H = fft(temp2,to-from+1);L = ceil(length(H)/2);n = 0:L-1;plot(handles.axes2,n/L*Fs/2/1000,2*sqrt(H(1:L).*conj(H(1:L);%幅度譜grid;plot(handles.axes4,n/L*Fs/2/1000,angle(H(1:L);%相位譜plot(handles.axes5,n/L*Fs/2/1000,real(H(1:L);%實(shí)頻plot(handles.axes6,n/L*Fs/2/1000,imag(H(1:L);%虛頻plot(handles.axes7,n/L*Fs/2/1000,abs(H(1:L).2);%功率譜 C,I = max(abs(H);set(handles.edit13,String,1/(n(I)/L*pi*Fs/2/pi);set(handles.edit14,String,(n(I)/L*pi*Fs/2/pi);if(I = 1)set(handles.edit13,String,無限長); set(handles.edit14,String,直流);end %guo ling jian cen=1;ymax=max(handles.y(1) handles.y(2);ymin=min(handles.y(1) handles.y(2);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);% x1=i-1;% y1=handles.y(i-1);% x2=i;% y2=handles.y(i);% a=handles.y(i)-handles.y(i-1);% b=a*x1-y1;% ti(n)=b/a; 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;%freqence and periodicityfor i=1:n-1 T(i)=ti(i+1)-ti(i);endfunction edit5_Callback(hObject, eventdata, handles)% hObject handle to edit5 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,String) returns contents of edit5 as text% str2double(get(hObject,String) returns contents of edit5 as a double % - Executes during object creation, after setting all properties.function edit5_CreateFcn(hObject, eventdata, handles)% hObject handle to edit5 (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), get(0,defaultUicontrolBackgroundColor) set(hObject,BackgroundColor,white);end function edit6_Callback(hObject, eventdata, handles)% hObject handle to edit6 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,String) returns contents of edit6 as text% str2double(get(hObject,String) returns contents of edit6 as a double % - Executes during object creation, after setting all properties.function edit6_CreateFcn(hObject, eventdata, handles)% hObject handle to edit6 (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), get(0,defaultUicontrolBackgroundColor) set(hObject,BackgroundColor,white);end function edit7_Callback(hObject, eventdata, handles)% hObject handle to edit7 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,String) returns contents of edit7 as text% str2double(get(hObject,String) returns contents of edit7 as a double % - Executes during object creation, after setting all properties.function edit7_CreateFcn(hObject, eventdata, handles)% hObject handle to edit7 (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), get(0,defaultUicontrolBackgroundColor) set(hObject,BackgroundColor,white);end function edit8_Callback(hObject, eventdata, handles)% hObject handle to edit8 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,String) returns contents of edit8 as text% str2double(get(hObject,String) returns contents of edit8 as a double % - Executes during object creation, after setting all properties.function edit8_CreateFcn(hObject, eventdata, handles)% hObject handle to edit8 (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), get(0,defaultUicontrolBackgroundColor) set(hObject,BackgroundColor,white);end function edit9_Callback(hObject, eventdata, handles)% hObject handle to edit9 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handl

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(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ǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論