% 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 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 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. function 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 ISPC 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) % hObject handle to timeanalyse (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
Fs=str2double(get(findobj('Tag','caiyangpinlv'),'String')); 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(get(handles.pointto,'String')); if from<1 | to-from<5;
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)>=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;
15 / 21
% 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 ymax if ymin>handles.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(handles.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(handles.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 (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); 16 / 21 ysize=size(handles.y); set(handles.samplenum,'String',num2str(ysize(1))); set(handles.samplefre,'string',Fs); h=waitbar(0,'pleas wait...'); for i=1:10000 waitbar(i/10000,h) end close(h) % --- Executes on button press in freqanalyse. function freqanalyse_Callback(hObject, eventdata, handles) % hObject handle to freqanalyse (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) Fs=str2double(get(findobj('Tag','caiyangpinlv'),'String')); N=str2double(get(findobj('Tag','caiyangdianshu'),'String')); if handles.inputtype==0 msgbox('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)); if(handles.inputtype==1||handles.inputtype==2||handles.inputtype==4) set(handles.foutt,'String','非周期'); set(handles.foutfreq,'String','非周期'); end if(handles.inputtype==3) set(handles.foutt,'String',1/f(I)); set(handles.foutfreq,'String',f(I)); end Y=Y(1:(to-from+1)/2); plot(handles.fuzhipu,f,2*sqrt(Y.*conj(Y))); plot(handles.xiangweipu,f,angle(Y)); plot(handles.shipin,f,real(Y)); plot(handles.xupin,f,imag(Y)); plot(handles.gonglvpu,f,abs(Y).^2); xlabel(handles.fuzhipu,'freqency(Hz)'); xlabel(handles.xiangweipu,'freqency(Hz)'); xlabel(handles.shipin,'freqency(Hz)'); xlabel(handles.xupin,'freqency(Hz)'); xlabel(handles.gonglvpu,'freqency(Hz)'); ylabel(handles.fuzhipu,'amplitude'); ylabel(handles.xiangweipu,'phase(rad)'); ylabel(handles.shipin,'real'); ylabel(handles.xupin,'Imaginary'); ylabel(handles.gonglvpu,'power'); 五、音频频谱分析仪运行结果 17 / 21 1. 声卡输入 声卡输入的录音是非周期的,故时域分析和频域分析结果都是“非周期”。 2. wav文件输入 由于wav文件是非周期的,故时域分析和频域分析结果都是“非周期”。 3. 信号发生器 18 / 21 (1) 正弦波 (2) 方波 19 / 21 百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库数字信号处理实验8音频频谱分析仪设计与实现(4)在线全文阅读。
相关推荐: