数字信号处理实验8音频频谱分析仪设计与实现
更新时间:2024-06-12 04:42:01 阅读量: 综合文库 文档下载
- 数字信号处理频谱泄露推荐度:
- 相关推荐
信号处理实验
实验八:音频频谱分析仪设计与实现
一、实验名称:音频频谱分析仪设计与实现 二、实验原理:
MATLAB是一个数据信息和处理功能十分强大的工程实用软件,其数据采集工具箱为实现数据的输入和输出提供了十分方便的函数和命令。本实验可以用MATLAB进行音频信号频谱分析仪的设计与实现。 1、信号频率、幅值和相位估计 (1)频率(周期)检测 对周期信号来说,可以用时域波形分析来确定信号的周期,也就是计算相邻的两个信号波峰的时间差、或过零点的时间差。这里采用过零点(ti)的时间差T(周期)。频率即为f = 1/T,由于能够求得多个T值(ti有多个),故采用它们的平均值作为周期的估计值。
(2)幅值检测 在一个周期内,求出信号最大值ymax与最小值ymin的差的一半,即A = (ymax - ymin)/2,同样,也会求出多个A值,但第1个A值对应的ymax和ymin不是在一个周期内搜索得到的,故以除第1个以外的A值的平均作为幅值的估计值。
(3)相位检测
采用过零法,即通过判断与同频零相位信号过零点时刻,计算其时间差,然后换成相应的相位差。φ=2π(1-ti/T),{x}表示x的小数部分,同样,以φ的平均值作为相位的估计值。
频率、幅值和相位估计的流程如图所示。
1 / 21
其中tin表示第n个过零点,yi为第i个采样点的值,Fs为采样频率。 2、数字信号统计量估计 (1) 峰值P的估计
在样本数据x中找出最大值与最小值,其差值为双峰值,双峰值的一半即为峰值。 P=0.5[max(yi)-min(yi)] (2)均值估计
式中,N为样本容量,下同。 (3) 均方值估计
2 / 21
(4) 方差估计
2、频谱分析原理
时域分析只能反映信号的幅值随时间的变化情况,除单频率分量的简单波形外,很难明确提示信号的频率组成和各频率分量大小,而频谱分析能很好的解决此问题。
(1)DFT与FFT
对于给定的时域信号y,可以通过Fourier变换得到频域信息Y。Y可按下式计算
式中,N为样本容量,Δt = 1/Fs为采样间隔。
采样信号的频谱是一个连续的频谱,不可能计算出所有的点的值,故采用离散Fourier变换(DFT),即
式中,Δf = Fs/N。但上式的计算效率很低,因为有大量的指数(等价于三角函数)运算,故实际中多采用快速Fourier变换(FFT)。其原理即是将重复的三角函数算计的中间结果保存起来,以减少重复三角函数计算带来的时间浪费。由于三角函数计算的重复量相当大,故FFT能极大地提高运算效率。
(2)频率、周期的估计
对于Y(kΔf),如果当kΔf = 时,Y(kΔf)取最大值,则为频率的估计值,由于采样间隔的误差,也存在误差,其误差最大为Δ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/2]
4、模块划分
模块化就是把程序划分成独立命名且可独立访问的模块,每个模块完成一个子功能,把这些模块集成起来构成一个整体,可以完成指定的功能满足用户需求。根据人类解决一般问题的经验,如果一个问题由两个问题组合而成,那么它的复杂程度大于分别考虑每个问题时的复杂程度之和,也就是说把复杂的问题分解成许多容易解决的小问题,原来的问题也就容
3 / 21
易解决了。这就是模块化的根据。
在模块划分时应遵循如下规则:改进软件结构提高模块独立性;模块规模应该适中;深度、宽度、扇出和扇入都应适当;模块的作用域应该在控制域之内;力争降低模块接口的复杂程度;设计单入口单出口的模块;模块功能应该可以预测。
三、实验要求:
参考以上原理,查阅相关资料,构建交互界面,设计一个音频频谱分析仪,实现一下功能:
(1) 音频信号信号输入,从声卡输入、从WAV文件输入、从标准信号发生器输入;
(2) 信号波形分析,包括幅值、频率、周期、相位的估计,以及统计量峰值、均值、均方值和方差的计算;
(3) 信号频谱分析,频率、周期的估计,图形显示幅值谱、相位谱、实频谱、虚频谱和功率谱的曲线。
四、实验界面及程序
4 / 21
程序:
function varargout = yinpin(varargin) % YINPIN M-file for yinpin.fig
% YINPIN, by itself, creates a new YINPIN or raises the existing % singleton*. %
% H = YINPIN returns the handle to a new YINPIN or the handle to % the existing singleton*. %
% YINPIN('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in YINPIN.M with the given input arguments. %
% YINPIN('Property','Value',...) creates a new YINPIN or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before yinpin_OpeningFunction gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to yinpin_OpeningFcn via varargin. %
% *See GUI Options on GUIDE's Tools menu. Choose \ % instance to run (singleton)\ %
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help yinpin
% Last Modified by GUIDE v2.5 07-Nov-2012 17:08:53
% Begin initialization code - DO NOT EDIT gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @yinpin_OpeningFcn, ... 'gui_OutputFcn', @yinpin_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []); if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1}); end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else
gui_mainfcn(gui_State, varargin{:}); end
% End initialization code - DO NOT EDIT
% --- Executes just before yinpin is made visible.
function yinpin_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 yinpin (see VARARGIN)
% Choose default command line output for yinpin handles.output = hObject;
5 / 21
% Update handles structure guidata(hObject, handles);
% UIWAIT makes yinpin wait for user response (see UIRESUME) % uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line. function varargout = yinpin_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 structure varargout{1} = handles.output;
% --- Executes during object creation, after setting all properties. function edit1_CreateFcn(hObject, eventdata, handles) % hObject handle to edit1 (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 caiyangpinlv_CreateFcn(hObject, eventdata, handles) % hObject handle to caiyangpinlv (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 caiyangdianshu_CreateFcn(hObject, eventdata, handles) % hObject handle to caiyangdianshu (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 luyin.
function luyin_Callback(hObject, eventdata, handles) % hObject handle to luyin (see GCBO)
6 / 21
% 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 luyin set(handles.luyin,'value',1); set(handles.wavfile,'value',0);
set(handles.xinhaofasheng,'value',0); h=findobj('Tag','recordtime'); set(h,'enable','on');
h=findobj('Tag','kaishiluyin'); set(h,'enable','on');
h=findobj('Tag','wavname'); set(h,'enable','off');
h=findobj('Tag','liulan'); set(h,'enable','off');
h=findobj('Tag','inwave'); set(h,'enable','off');
h=findobj('Tag','infudu'); set(h,'enable','off'); h=findobj('Tag','infre'); set(h,'enable','off');
h=findobj('Tag','inphase'); set(h,'enable','off'); h=findobj('Tag','mix'); set(h,'enable','off');
h=findobj('Tag','shengchengboxing'); set(h,'enable','off');
% --- Executes on button press in wavfile.
function wavfile_Callback(hObject, eventdata, handles) % hObject handle to wavfile (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 wavfile set(handles.luyin,'value',0); set(handles.wavfile,'value',1);
set(handles.xinhaofasheng,'value',0); h=findobj('Tag','recordtime'); set(h,'enable','off');
h=findobj('Tag','kaishiluyin'); set(h,'enable','off');
h=findobj('Tag','wavname'); set(h,'enable','on');
h=findobj('Tag','liulan'); set(h,'enable','on');
h=findobj('Tag','inwave'); set(h,'enable','off');
h=findobj('Tag','infudu'); set(h,'enable','off'); h=findobj('Tag','infre'); set(h,'enable','off');
h=findobj('Tag','inphase'); set(h,'enable','off'); h=findobj('Tag','mix'); set(h,'enable','off');
7 / 21
h=findobj('Tag','shengchengboxing'); set(h,'enable','off');
% --- Executes on button press in xinhaofasheng.
function xinhaofasheng_Callback(hObject, eventdata, handles) % hObject handle to xinhaofasheng (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 xinhaofasheng set(handles.luyin,'value',0); set(handles.wavfile,'value',0);
set(handles.xinhaofasheng,'value',1); h=findobj('Tag','recordtime'); set(h,'enable','off');
h=findobj('Tag','kaishiluyin'); set(h,'enable','off');
h=findobj('Tag','wavname'); set(h,'enable','off');
h=findobj('Tag','liulan'); set(h,'enable','off');
h=findobj('Tag','inwave'); set(h,'enable','on');
h=findobj('Tag','infudu'); set(h,'enable','on'); h=findobj('Tag','infre'); set(h,'enable','on');
h=findobj('Tag','inphase'); set(h,'enable','on'); h=findobj('Tag','mix'); set(h,'enable','on');
h=findobj('Tag','shengchengboxing'); set(h,'enable','on');
% --- Executes during object creation, after setting all properties. function recordtime_CreateFcn(hObject, eventdata, handles) % hObject handle to recordtime (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 kaishiluyin.
function kaishiluyin_Callback(hObject, eventdata, handles) % hObject handle to kaishiluyin (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 kaishiluyin Fs=str2double(get(handles.caiyangpinlv,'String')); N=str2double(get(handles.recordtime,'String'))*Fs; handles.y=wavrecord(N, Fs,'double'); handles.inputtype=1;
8 / 21
guidata(hObject,handles);
plot(handles.fenxiduixiang,handles.y); ysize=size(handles.y);
set(handles.caiyangdianshu,'String',num2str(ysize(1)));
% --- Executes during object creation, after setting all properties. function wavname_CreateFcn(hObject, eventdata, handles) % hObject handle to wavname (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 liulan.
function liulan_Callback(hObject, eventdata, handles) % hObject handle to liulan (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 liulan [filename,filepath]=uigetfile('*.wav','wavfile'); set(handles.wavname,'string',filename); [handles.y,Fs,bit]=wavread(filename); handles.inputtype=2; guidata(hObject,handles);
plot(handles.fenxiduixiang,(1:length(handles.y)/10)/Fs,handles.y(1:length(handles.y)/10)); ysize=size(handles.y);
set(handles.caiyangdianshu,'String',num2str(ysize(1))); set(handles.caiyangpinlv,'string',Fs);
% --- Executes during object creation, after setting all properties. function listbox2_CreateFcn(hObject, eventdata, handles) % hObject handle to listbox2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called
% Hint: listbox 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 inwave_CreateFcn(hObject, eventdata, handles) % hObject handle to inwave (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu 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
9 / 21
% --- Executes during object creation, after setting all properties. function infudu_CreateFcn(hObject, eventdata, handles) % hObject handle to infudu (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 infre_CreateFcn(hObject, eventdata, handles) % hObject handle to infre (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 inphase_CreateFcn(hObject, eventdata, handles) % hObject handle to inphase (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 shengchengboxing.
function shengchengboxing_Callback(hObject, eventdata, handles) % hObject handle to shengchengboxing (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')); x=linspace(0,N/Fs,N);
soundtype=get(handles.inwave,'Value');
frequency=str2double(get(handles.infre,'String')); amp=str2double(get(handles.infudu,'String')); phase=str2double(get(handles.inphase,'String')); switch soundtype case 1
y=amp*sin(2*pi*x*frequency+phase); handles.inputtype=3; case 2
y=amp*sign(sin(2*pi*x*frequency+phase)); handles.inputtype=3; case 3
y=amp*sawtooth(2*pi*x*frequency+phase,0.5);
10 / 21
handles.inputtype=3; case 4
y=amp*sawtooth(2*pi*x*frequency+phase); handles.inputtype=3; case 5
y=amp*(2*rand(size(x))-1); handles.inputtype=4;
end
if get(handles.mix,'Value')==0.0 handles.y=y; else
handles.y=handles.y+y; end
guidata(hObject,handles);
plot(handles.fenxiduixiang,handles.y); title('WAVE');
axis([0 N -str2double(get(handles.infudu,'String')) str2double(get(handles.infudu,'String'))]);
% --- Executes during object creation, after setting all properties. function edit11_CreateFcn(hObject, eventdata, handles) % hObject handle to edit11 (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 edit12_CreateFcn(hObject, eventdata, handles) % hObject handle to edit12 (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 popupmenu3_CreateFcn(hObject, eventdata, handles) % hObject handle to popupmenu3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu 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.
11 / 21
function edit13_CreateFcn(hObject, eventdata, handles) % hObject handle to edit13 (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 edit14_CreateFcn(hObject, eventdata, handles) % hObject handle to edit14 (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 edit15_CreateFcn(hObject, eventdata, handles) % hObject handle to edit15 (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 edit9_CreateFcn(hObject, eventdata, handles) % hObject handle to edit9 (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 edit10_CreateFcn(hObject, eventdata, handles) % hObject handle to edit10 (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');
12 / 21
end
% --- Executes during object creation, after setting all properties. function circle_CreateFcn(hObject, eventdata, handles) % hObject handle to circle (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 outfreq_CreateFcn(hObject, eventdata, handles) % hObject handle to outfreq (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 outamp_CreateFcn(hObject, eventdata, handles) % hObject handle to outamp (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 outphase_CreateFcn(hObject, eventdata, handles) % hObject handle to outphase (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 outpeak_CreateFcn(hObject, eventdata, handles) % hObject handle to outpeak (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.
13 / 21
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end
% --- Executes during object creation, after setting all properties. function outmean_CreateFcn(hObject, eventdata, handles) % hObject handle to outmean (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 edit24_CreateFcn(hObject, eventdata, handles) % hObject handle to edit24 (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 outminus_CreateFcn(hObject, eventdata, handles) % hObject handle to outminus (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 foutt_CreateFcn(hObject, eventdata, handles) % hObject handle to foutt (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 foutfreq_CreateFcn(hObject, eventdata, handles) % hObject handle to foutfreq (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.
14 / 21
% 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 (3) 三角波 (4) 锯齿波 20 / 21 (5) 白噪声 白噪声是随机产生的,故时域和频域分析结果都是非周期的。 六、结果分析及体会 通过以上界面和程序,本设计基本实现了实验的要求。三种输入方式间可以方便的切换,并且一次只能选择一种输入方式(选择一种输入方式后,其他输入方式的功能键会变灰,将不能使用,除非再次选择该输入方式)。对于非周期的信号,会显示“非周期”。 同时,本作品还有待改进和完善,如可以对函数进行加窗分析,还可以把分析结果导出来称特定格式的文件,等等。由于本次试验学时有限,自身知识所限,没有来得及实现。在后面的学习中,有机会将进行研究。 21 / 21
正在阅读:
14秋电工基础试卷06-19
解放思想大讨论活动总结10-08
海产品深加工02-17
工作犯错检讨书范文02-13
上海市建平中学2018届高三10月月考英语试题(含详细答案)04-26
中南大学 人工智能考试试卷及答案07-04
最新部编版四年级语文上册23梅兰芳蓄须梅兰芳蓄须优质教案12-03
白云深处作文600字06-22
- 多层物业服务方案
- (审判实务)习惯法与少数民族地区民间纠纷解决问题(孙 潋)
- 人教版新课标六年级下册语文全册教案
- 词语打卡
- photoshop实习报告
- 钢结构设计原理综合测试2
- 2014年期末练习题
- 高中数学中的逆向思维解题方法探讨
- 名师原创 全国通用2014-2015学年高二寒假作业 政治(一)Word版
- 北航《建筑结构检测鉴定与加固》在线作业三
- XX县卫生监督所工程建设项目可行性研究报告
- 小学四年级观察作文经典评语
- 浅谈110KV变电站电气一次设计-程泉焱(1)
- 安全员考试题库
- 国家电网公司变电运维管理规定(试行)
- 义务教育课程标准稿征求意见提纲
- 教学秘书面试技巧
- 钢结构工程施工组织设计
- 水利工程概论论文
- 09届九年级数学第四次模拟试卷
- 频谱
- 信号处理
- 分析仪
- 音频
- 实验
- 实现
- 数字
- 设计
- 肉禽食品加工厂项目可行性研究报告
- 人教版小学数学三年级下册教案 表格式
- 施工项目风险控制“四步曲”落地指引
- 卫生事业管理复习重点
- 行政组织学教案2013年
- 房地产评估技术报告
- 风清气正活动实施方案
- 高三化学集体备课记录
- 中考政治热点专题
- 04741计算机网络原理李全龙计算机网络原理,课后习题第一章
- 作业公路运输费用计算操作实训计算题
- 数学 - 湖南省衡阳市八中2016-2017学年下学期高高二年期末试题(
- 石油华东石油华东《社会学》2016年秋学期在线作业(一)
- 民事诉讼法重点法条裁定适用范围
- 汽车发动机管理系统检修
- 泰安市政府采购管理办法
- 接龙铁矿地面建设工程钢结构制作安装细则
- 2016-2017学年最新人教版二年级数学下册全册教案(含教学计划与进
- 1-5 管路计算
- 一级建造师铁路工程管理与实务案例分析题