(最新整理)音频频谱分析仪设计与实现_第1页
(最新整理)音频频谱分析仪设计与实现_第2页
(最新整理)音频频谱分析仪设计与实现_第3页
(最新整理)音频频谱分析仪设计与实现_第4页
已阅读5页,还剩14页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、(完整)音频频谱分析仪设计与实现(完整)音频频谱分析仪设计与实现 编辑整理:尊敬的读者朋友们:这里是精品文档编辑中心,本文档内容是由我和我的同事精心编辑整理后发布的,发布之前我们对文中内容进行仔细校对,但是难免会有疏漏的地方,但是任然希望((完整)音频频谱分析仪设计与实现)的内容能够给您的工作和学习带来便利。同时也真诚的希望收到您的建议和反馈,这将是我们进步的源泉,前进的动力。本文可编辑可修改,如果觉得对您有帮助请收藏以便随时查阅,最后祝您生活愉快 业绩进步,以下为(完整)音频频谱分析仪设计与实现的全部内容。实验八 音频频谱分析仪设计与实现1、 实验原理matlab是一个数据分析和处理功能十分

2、强大的工程实用软件,其数据采集工具箱为实现数据的输入和输出提供了十分方便的函数和指令.本实验基于声卡与matlab实现音频信号频谱分析仪。 1、频率(周期)检测 对周期信号来说,可以用时域波形分析来确定信号的周期,也就是计算相邻两个信号波峰的时间差或过零点的时间差。采用过零点(ti)的时间差t(周期)。频率即为f=1/t,由于能够求得多个t值,故采用他们的平均值作为周期的估计值。 2、峰值检测 在一个周期内,求出信号最大值与最小值的差得一半记为a,同样得到多个a值,但第一个a值对应的和不是在一个周期内搜索得到的,故以除第一个以外的a值的平均作为幅值的估计值. 3、相位检测 采用过零法,即通过判

3、断与同频零相位信号过零点时刻,计算其时间差,然后换成相应的相位差。,同样以的平均值作为相位的估计值。 4、数字信号统计量估计 (1)峰值p的估计 在样本数据x中找出最大值与最小值,其差为双峰值,双峰值的一半即为峰值。 (2)均值估计 ,n为样本容量。 (3)均方值估计 (4)方差估计 5、频谱分析原理 时域分析只能反映信号的幅值随时间的变化情况,除但频率分量的简单波形外,很难明确提示信号的频率组成和各频率分量大小,而频谱分析能很好的解决此问题。(1)dft与fft对于给定的时域信号y,可以通过fourier变换得到频域信息y.y可按下式计算式中,n为样本容量,t = 1/fs为采样间隔。采样信

4、号的频谱是一个连续的频谱,不可能计算出所有的点的值,故采用离散fourier变换(dft),即式中,f = fs/n。但上式的计算效率很低,因为有大量的指数(等价于三角函数)运算,故实际中多采用快速fourier变换(fft)。其原理即是将重复的三角函数算计的中间结果保存起来,以减少重复三角函数计算带来的时间浪费。由于三角函数计算的重复量相当大,故fft能极大地提高运算效率。(2) 频率、周期的估计 对于y(kf),如果当kf = 时,y(kf)取最大值,则为频率的估计值,由于采样间隔的误差,也存在误差,其误差最大为f / 2。周期t=1/f。从原理上可以看出,如果在标准信号中混有噪声,用上述

5、方法仍能够精确地估计出原标准信号的频率和周期. (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、 模块划分 模块化就是把程序划分成独立命名

6、且可独立访问的模块,每个模块完成一个子功能,把这些模块集成起来构成一个整体,可以完成制定的功能,满足用户需求.2、 实验内容设计一个音频频谱分析仪,功能包括:(1) 音频信号输入,从声卡输入、从wav文件输入、从标准信号发生器输入;(2) 信号波形分析,包括幅值、频率、周期、相位的估计,以及统计量峰值、均值。均方值和方差的计算。(3) 信号频谱分析,频率、周期的估计,图形显示幅值谱、相位谱、时频谱、虚频谱和功率谱的曲线。3 实验结果1.声卡输入(1) 正弦波 (2)方波(3) 三角波(4) 锯齿波(5) 白噪声程序function varargout = fanwenhan(varargin)

7、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

8、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(hand

9、les。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, handle

10、s) 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 choos

11、e 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 | tofrom5; msgbox(error range!); return;endfor i=from+2:to1; if handles。y(i1)0 & handles.y(i2)=0 hand

12、les.y(i+1)0 if handles.y(i)=0 ti(n)=i; else ti(n)=i-handles。y(i)/(handles.y(i)handles.y(i1); end amp(n)=(ymaxymin)/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.outfre

13、q,string,num2str(freq));set(handles。outamp,string,num2str(mean(amp(2:n-1));phase=2pi*(1-(ti(1:n1)1)。/t+floor((ti(1:n1)-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:

14、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,ph

15、ase);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

16、, 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)

17、;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,enabl

18、e,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

19、 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,background

20、color,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,defaultuicontrolbackgroundc

21、olor));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)functio

22、n 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(hobj

23、ect,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,backgro

24、undcolor,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=

25、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=

26、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(t

27、ag,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=ampsin(2*pi*x*frequency+phase); case 2 y=ampsign(sin(2pi*xfrequ

28、ency+phase); case 3 y=ampsawtooth(2*pix*frequency+phase,0.5); case 4 y=amp*sawtooth(2*pixfrequency+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

29、,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(hobje

30、ct,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 o

31、utphase_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_createfc

32、n(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)

33、;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,defaultuicontrolback

34、groundcolor));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)funct

35、ion 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,

36、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,defaul

37、tuicontrolbackgroundcolor);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, eventdat

38、a, 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 s

39、et(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,d

40、efaultuicontrolbackgroundcolor));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(h

41、andles.pointfrom,string));to=str2double(get(handles。pointto,string));sample=handles。y(from:to);f=linspace(0,fs/2,(tofrom+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,2sqrt(y.*conj(y)));plot(ha

42、ndles。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(handle

43、s。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

44、 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));en

45、d 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(val5+1);x=get(handles.xmove,value)*str2double(get(handles.samplenum,string);axis(handles.ti

46、me,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

47、(hobject,value);val=10(val5+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,defau

48、ltuicontrolbackgroundcolor));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,background

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论