




已阅读5页,还剩28页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
数字信号处理实验报告(八)1、 实验名称:音频频谱分析仪设计与实现2、 实验原理: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的小数部分,同样,以的平均值作为相位的估计值。频率、幅值和相位估计的流程如图所示。其中tin表示第n个过零点,yi为第i个采样点的值,Fs为采样频率。2、数字信号统计量估计(1) 峰值P的估计在样本数据x中找出最大值与最小值,其差值为双峰值,双峰值的一半即为峰值。P=0.5max(yi)-min(yi)(2)均值估计式中,N为样本容量,下同。(3) 均方值估计(4) 方差估计2、 频谱分析原理时域分析只能反映信号的幅值随时间的变化情况,除单频率分量的简单波形外,很难明确提示信号的频率组成和各频率分量大小,而频谱分析能很好的解决此问题。(1)DFT与FFT对于给定的时域信号y,可以通过Fourier变换得到频域信息Y。Y可按下式计算式中,N为样本容量,t = 1/Fs为采样间隔。采样信号的频谱是一个连续的频谱,不可能计算出所有的点的值,故采用离散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/24、模块划分模块化就是把程序划分成独立命名且可独立访问的模块,每个模块完成一个子功能,把这些模块集成起来构成一个整体,可以完成指定的功能满足用户需求。根据人类解决一般问题的经验,如果一个问题由两个问题组合而成,那么它的复杂程度大于分别考虑每个问题时的复杂程度之和,也就是说把复杂的问题分解成许多容易解决的小问题,原来的问题也就容易解决了。这就是模块化的根据。在模块划分时应遵循如下规则:改进软件结构提高模块独立性;模块规模应该适中;深度、宽度、扇出和扇入都应适当;模块的作用域应该在控制域之内;力争降低模块接口的复杂程度;设计单入口单出口的模块;模块功能应该可以预测。3、 实验内容:参考以上原理,查阅相关资料,构建交互界面,设计一个音频频谱分析仪,实现一下功能:(1) 音频信号信号输入,从声卡输入、从WAV文件输入、从标准信号发生器输入;(2) 信号波形分析,包括幅值、频率、周期、相位的估计,以及统计量峰值、均值、均方值和方差的计算;(3) 信号频谱分析,频率、周期的估计,图形显示幅值谱、相位谱、实频谱、虚频谱和功率谱的曲线。4、 实验程序 正弦波 混叠正弦波 方波 三角波 锯齿波 白噪声function varargout = xty(varargin)% XTY M-file for xty.fig% XTY, by itself, creates a new XTY or raises the existing% singleton*.% H = XTY returns the handle to a new XTY or the handle to% the existing singleton*.% XTY(CALLBACK,hObject,eventData,handles,.) calls the local% function named CALLBACK in XTY.M with the given input arguments.% XTY(Property,Value,.) creates a new XTY or raises the% existing singleton*. Starting from the left, property value pairs are% applied to the GUI before guojing_OpeningFunction gets called. An% unrecognized property name or invalid value makes property application% stop. All inputs are passed to guojing_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 xty % Last Modified by GUIDE v2.5 02-Nov-2011 22:54:25 % Begin initialization code - DO NOT EDITgui_Singleton = 1;gui_State = struct(gui_Name, mfilename, . gui_Singleton, gui_Singleton, . gui_OpeningFcn, guojing_OpeningFcn, . gui_OutputFcn, guojing_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 xty is made visible.function guojing_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 guojing (see VARARGIN) % Choose default command line output for guojing handles.output = hObject; % Update handles structureguidata(hObject, handles); % UIWAIT makes xty wait for user response (see UIRESUME)% uiwait(handles.figure1); % - Outputs from this function are returned to the command line.function varargout = guojing_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 soundcard.function soundcard_Callback(hObject, eventdata, handles)% hObject handle to soundcard (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 soundcardset(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); % - Executes on button press in generator.function generator_Callback(hObject, eventdata, handles)% hObject handle to generator (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 generatorh=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 recordtime_Callback(hObject, eventdata, handles)% hObject handle to recordtime (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 recordtime as text% str2double(get(hObject,String) returns contents of recordtime as a double % - 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 function 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 selection change in popupmenu1.function popupmenu1_Callback(hObject, eventdata, handles)% hObject handle to popupmenu1 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA) % Hints: contents = get(hObject,String) returns popupmenu1 contents as cell array% contentsget(hObject,Value) returns selected item from popupmenu1 % - Executes during object creation, after setting all properties.function popupmenu1_CreateFcn(hObject, eventdata, handles)% hObject handle to popupmenu1 (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 function freq_Callback(hObject, eventdata, handles)% hObject handle to freq (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 freq as text% str2double(get(hObject,String) returns contents of freq as a double % - Executes during object creation, after setting all properties.function freq_CreateFcn(hObject, eventdata, handles)% hObject handle to freq (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 amp_Callback(hObject, eventdata, handles)% hObject handle to amp (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 amp as text% str2double(get(hObject,String) returns contents of amp as a double % - Executes during object creation, after setting all properties.function amp_CreateFcn(hObject, eventdata, handles)% hObject handle to amp (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 phase_Callback(hObject, eventdata, handles)% hObject handle to phase (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 phase as text% str2double(get(hObject,String) returns contents of phase as a double % - Executes during object creation, after setting all properties.function phase_CreateFcn(hObject, eventdata, handles)% hObject handle to phase (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 startrecord.function startrecord_Callback(hObject, eventdata, handles)% hObject handle to startrecord (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,samplerate),String);handles.y=wavrecord(str2double(get(findobj(Tag,recordtime),String)*Fs, Fs,double);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 channel_Callback(hObject, eventdata, handles)% hObject handle to channel (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 channel as text% str2double(get(hObject,String) returns contents of channel as a double % - Executes during object creation, after setting all properties.function channel_CreateFcn(hObject, eventdata, handles)% hObject handle to channel (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 fileopen.function fileopen_Callback(hObject, eventdata, handles)% hObject handle to fileopen (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.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); % - Executes on button press in add.function add_Callback(hObject, eventdata, handles)% hObject handle to add (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 add % - Executes on button press in gensig.function gensig_Callback(hObject, eventdata, handles)% hObject handle to gensig (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,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); % - 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 WAVfileh=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 samplerate_Callback(hObject, eventdata, handles)% hObject handle to samplerate (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 samplerate as text% str2double(get(hObject,String) returns contents of samplerate as a double % - Executes during object creation, after setting all properties.function samplerate_CreateFcn(hObject, eventdata, handles)% hObject handle to samplerate (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 fun
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025-2026学年统编版(2024)小学语文二年级上册第一单元核心知识点归纳
- 防汛抗灾应急知识培训课件
- 公司与客户合作协议合同
- Unit 4 Exploring Literature Reading The Old Man and the Sea 课件(内嵌音视频)
- 全球智能电网市场机会分析
- 生物多样性-生态系统服务关联-洞察及研究
- 智能交通系统铁路应用-洞察及研究
- 服务器租用合同样板5篇
- 天津市房产购买中介合同范文6篇
- 培训班合伙协议模板6篇
- 2025年江苏省农垦集团有限公司人员招聘笔试备考及参考答案详解
- 军用无人机讲解课件
- 2025年中国移动校园招聘笔试试题解析及答题技巧
- 长宏国际安全知识培训课件
- 2025年湖南郴州市北湖区引进高层次人才和招聘事业单位工作人员28人备考练习题库及答案解析
- 项目四旅游电子商务网络营销92课件
- 麻醉深度监测-洞察及研究
- 电缆桥架设备知识培训课件
- 快乐的牛仔课件
- 2025年口腔修复学笔试题及答案
- 2025年组织部招聘笔试冲刺
评论
0/150
提交评论