音频频谱分析仪设计与实现.docx

上传人:b****1 文档编号:2331602 上传时间:2023-05-03 格式:DOCX 页数:23 大小:22.04KB
下载 相关 举报
音频频谱分析仪设计与实现.docx_第1页
第1页 / 共23页
音频频谱分析仪设计与实现.docx_第2页
第2页 / 共23页
音频频谱分析仪设计与实现.docx_第3页
第3页 / 共23页
音频频谱分析仪设计与实现.docx_第4页
第4页 / 共23页
音频频谱分析仪设计与实现.docx_第5页
第5页 / 共23页
音频频谱分析仪设计与实现.docx_第6页
第6页 / 共23页
音频频谱分析仪设计与实现.docx_第7页
第7页 / 共23页
音频频谱分析仪设计与实现.docx_第8页
第8页 / 共23页
音频频谱分析仪设计与实现.docx_第9页
第9页 / 共23页
音频频谱分析仪设计与实现.docx_第10页
第10页 / 共23页
音频频谱分析仪设计与实现.docx_第11页
第11页 / 共23页
音频频谱分析仪设计与实现.docx_第12页
第12页 / 共23页
音频频谱分析仪设计与实现.docx_第13页
第13页 / 共23页
音频频谱分析仪设计与实现.docx_第14页
第14页 / 共23页
音频频谱分析仪设计与实现.docx_第15页
第15页 / 共23页
音频频谱分析仪设计与实现.docx_第16页
第16页 / 共23页
音频频谱分析仪设计与实现.docx_第17页
第17页 / 共23页
音频频谱分析仪设计与实现.docx_第18页
第18页 / 共23页
音频频谱分析仪设计与实现.docx_第19页
第19页 / 共23页
音频频谱分析仪设计与实现.docx_第20页
第20页 / 共23页
亲,该文档总共23页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

音频频谱分析仪设计与实现.docx

《音频频谱分析仪设计与实现.docx》由会员分享,可在线阅读,更多相关《音频频谱分析仪设计与实现.docx(23页珍藏版)》请在冰点文库上搜索。

音频频谱分析仪设计与实现.docx

音频频谱分析仪设计与实现

实验八音频频谱分析仪设计与实现

一、实验原理

MATLAB是一个数据分析和处理功能十分强大的工程实用软件,其数据采集工具箱为实现数据的输入和输出提供了十分方便的函数和指令。

本实验基于声卡与MATLAB实现音频信号频谱分析仪。

1、频率(周期)检测

对周期信号来说,可以用时域波形分析来确定信号的周期,也就是计算相邻两个信号波峰的时间差或过零点的时间差。

采用过零点(ti)的时间差T(周期)。

频率即为f=1/T,由于能够求得多个T值,故采用他们的平均值作为周期的估计值。

2、峰值检测

在一个周期内,求出信号最大值与最小值的差得一半记为A,同样得到多个A值,但第一个A值对应的和不是在一个周期内搜索得到的,故以除第一个以外的A值的平均作为幅值的估计值.

3、相位检测

采用过零法,即通过判断与同频零相位信号过零点时刻,计算其时间差,然后换成相应的相位差。

,同样以的平均值作为相位的估计值。

4、数字信号统计量估计

(1)峰值P的估计

在样本数据x中找出最大值与最小值,其差为双峰值,双峰值的一半即为峰值。

(2)均值估计

N为样本容量。

(3)均方值估计

(4)方差估计

5、频谱分析原理

时域分析只能反映信号的幅值随时间的变化情况,除但频率分量的简单波形外,很难明确提示信号的频率组成和各频率分量大小,而频谱分析能很好的解决此问题.

(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为横坐标,argY(f)为纵坐标,可以得到相位谱;

以频率f为横坐标,ReY(f)为纵坐标,可以得到实频谱;

以频率f为横坐标,ImY(f)为纵坐标,可以得到虚频谱.

根据采样定理,只有频率不超过Fs/2的信号才能被正确采集,即Fourier变换的结果中频率大于Fs/2的部分是不正确的部分,故不在频谱图中显示.即横坐标f∈[0,Fs/2]

6、模块划分

模块化就是把程序划分成独立命名且可独立访问的模块,每个模块完成一个子功能,把这些模块集成起来构成一个整体,可以完成制定的功能,满足用户需求。

二、实验内容

设计一个音频频谱分析仪,功能包括:

(1)音频信号输入,从声卡输入、从WAV文件输入、从标准信号发生器输入;

(2)信号波形分析,包括幅值、频率、周期、相位的估计,以及统计量峰值、均值。

均方值和方差的计算。

(3)信号频谱分析,频率、周期的估计,图形显示幅值谱、相位谱、时频谱、虚频谱和功率谱的曲线。

三.实验结果

1。

声卡输入

(1)正弦波

(2)方波

(3)三角波

(4)锯齿波

(5)白噪声

程序

functionvarargout=fanwenhan(varargin)

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’,[]);

ifnargin&&ischar(varargin{1})

gui_State.gui_Callback=str2func(varargin{1});

end

ifnargout

[varargout{1:

nargout}]=gui_mainfcn(gui_State,varargin{:

});

else

gui_mainfcn(gui_State,varargin{:

});

end

functionfanwenhan_OpeningFcn(hObject,eventdata,handles,varargin)

handles。

inputtype=0;

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(handles.plot1,’amplitude’);

ylabel(handles。

plot2,'phase(rad)');

ylabel(handles.plot3,’real’);

ylabel(handles。

plot4,'Imaginary');

ylabel(handles.plot5,'power’);

handles。

output=hObject;

functionvarargout=fanwenhan_OutputFcn(hObject,eventdata,handles)

varargout{1}=handles.output;

functionfigure1_CreateFcn(hObject,eventdata,handles)

functiontimeanalyse_Callback(hObject,eventdata,handles)

Fs=str2double(get(findobj('Tag',’samplerate'),'String’));

N=str2double(get(findobj(’Tag’,’samplenum'),'String’));

ifhandles。

inputtype==0

msgbox(’Nowaveexist!

Pleasechooseainputtype!

');

return;

end

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’));

iffrom〈1|to—from〈5;

msgbox('Errorrange!

');

return;

end

fori=from+2:

to—1;

ifhandles。

y(i—1)<0&handles.y(i-2)<0&handles.y(i)〉=0&handles。

y(i+1)>0

ifhandles.y(i)==0

ti(n)=i;

else

ti(n)=i-handles.y(i)/(handles.y(i)-handles。

y(i-1));

end

amp(n)=(ymax-ymin)/2;

ymax=0;

ymin=0;

n=n+1;

else

ifymax

ymax=handles.y(i);

end

ifymin>handles。

y(i)

ymin=handles.y(i);

end

end

end

n=n-1;

fori=1:

n—1

T(i)=ti(i+1)-ti(i);

end

freq=Fs/mean(T);

set(handles。

outt,’String',1/freq);

set(handles。

outfreq,'String’,num2str(freq));

set(handles。

outamp,’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.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:

to)));

set(handles。

outmeansquare,’String’,mean(handles.y(from:

to)。

^2));

set(handles。

outs,'String’,std(handles.y(from:

to))^2);

functionWAVfile_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’,'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');

functionsoundcard_Callback(hObject,eventdata,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');

set(handles。

wavetype,'enable',’off');

set(handles.add,’enable’,’off’);

set(handles。

startrecord,’enable',’on');

functiongenerator_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,'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');

functionfilename_Callback(hObject,eventdata,handles)

functionfilename_CreateFcn(hObject,eventdata,handles)

ifispc

set(hObject,’BackgroundColor’,'white');

else

set(hObject,'BackgroundColor’,get(0,'defaultUicontrolBackgroundColor’));

end

functionfreq_Callback(hObject,eventdata,handles)

functionfreq_CreateFcn(hObject,eventdata,handles)

ifispc

set(hObject,'BackgroundColor’,'white’);

else

set(hObject,'BackgroundColor',get(0,’defaultUicontrolBackgroundColor'));

end

functionamp_Callback(hObject,eventdata,handles)

functionamp_CreateFcn(hObject,eventdata,handles)

ifispc

set(hObject,’BackgroundColor','white’);

else

set(hObject,’BackgroundColor',get(0,’defaultUicontrolBackgroundColor'));

end

functionphase_Callback(hObject,eventdata,handles)

functionphase_CreateFcn(hObject,eventdata,handles)

ifispc

set(hObject,’BackgroundColor',’white’);

else

set(hObject,'BackgroundColor’,get(0,'defaultUicontrolBackgroundColor’));

end

functionsamplerate_Callback(hObject,eventdata,handles)

functionsamplerate_CreateFcn(hObject,eventdata,handles)

ifispc

set(hObject,'BackgroundColor’,'white’);

else

set(hObject,'BackgroundColor’,get(0,'defaultUicontrolBackgroundColor'));

end

functionsamplenum_Callback(hObject,eventdata,handles)

functionsamplenum_CreateFcn(hObject,eventdata,handles)

ifispc

set(hObject,’BackgroundColor',’white’);

else

set(hObject,’BackgroundColor’,get(0,'defaultUicontrolBackgroundColor'));

end

functionampfreq_CreateFcn(hObject,eventdata,handles)

functionrecordtime_Callback(hObject,eventdata,handles)

functionrecordtime_CreateFcn(hObject,eventdata,handles)

ifispc

set(hObject,'BackgroundColor’,'white’);

else

set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor’));

end

functionstartrecord_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=1;

guidata(hObject,handles);

plot(handles。

time,handles.y);

title(’WAVE');

ysize=size(handles.y)

set(handles。

samplenum,’String',num2str(ysize

(1)));

functionfileopen_Callback(hObject,eventdata,handles)

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)));

functiongensig_Callback(hObject,eventdata,handles)

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’));

switchsoundtype

case1

y=amp*sin(2*pi*x*frequency+phase);

case2

y=amp*sign(sin(2*pi*x*frequency+phase));

case3

y=amp*sawtooth(2*pi*x*frequency+phase,0.5);

case4

y=amp*sawtooth(2*pi*x*frequency+phase);

case5

y=amp*(2*rand(size(x))—1);

otherwise

errordlg('Illegalwavetype','Chooseerrer');

end

ifget(handles。

add,’Value’)==0。

0

handles。

y=y;

else

handles。

y=handles.y+y;

end

handles。

inputtype=3;

guidata(hObject,handles);

plot(handles.time,handles。

y);

title('WAVE');

axis([0N—str2double(get(handles.amp,'String’))str2double(get(handles。

amp,’String'))]);

functionoutfreq_Callback(hObject,eventdata,handles)

functionoutfreq_CreateFcn(hObject,eventdata,handles)

ifispc

set(hObject,'BackgroundColor','white');

else

set(hObject,’BackgroundColor',get(0,'defaultUicontrolBackgroundColor’));

end

functionoutamp_Callback(hObject,eventdata,handles)

functionoutamp_CreateFcn(hObject,eventdata,handles)

ifispc

set(hObject,'BackgroundColor',’white');

else

set(hObject,'BackgroundColor’,get(0,'defaultUicontrolBackgroundColor'));

end

functionoutphase_Callback(hObject,eventdata,handles)

functionoutphase_CreateFcn(hObject,eventdata,handles)

ifispc

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 工程科技 > 能源化工

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2