实验三抽样
3.1正弦信号混叠
A.
程序:
>>nn=0:79;
>>sinus=sin(2*pi*300/8000*nn);
>>stem(nn,sinus)
.b.
程序:
>>plot(nn,sinus)
.c.
>> nn=0:79;
sinus=sin(2*pi*100/8000*nn);
>> x1=sinus;
>> nn=0:79;
sinus=sin(2*pi*225/8000*nn);
>> x2=sinus;
>> nn=0:79;
sinus=sin(2*pi*350/8000*nn);
>> x3=sinus;
>> nn=0:79;
sinus=sin(2*pi*475/8000*nn);
>> x4=sinus;
>> subplot(411),stem(nn,x1);
>> subplot(412),stem(nn,x2);
>> subplot(413),stem(nn,x3);
>> subplot(414),stem(nn,x4);
3.3产生信号
a,
n=0:1000;
f0=1000;
fsim=80000;
t=n./fsim;
x=cos(2*pi*f0*n/fsim);
subplot(211),stem(n,x);
title('SAMPLES'),ylabel('x(t)'),xlabel('n');
subplot(212),plot(t,x);
title('CONTINIOUS'),ylabel('x(t)'),xlabel('t')
c.
fmagplot函数m文件:
function fmagplot(xa,dt)
L=length(xa);
Nfft=round(2.^round(log2(5*L)));
Xa=fft(xa,Nfft);
range=0:(Nfft/4);
ff=range/Nfft/dt;
plot(ff/1000,abs(Xa(1:length(range))))
title('CONT-TIME FOURIER TRANSFORM(MAG)')
xlabel('FREQUENCY(kHz)'),grid;
Pause
fmagplot(x,1/fsim)
a.
fsim=80000;
fs=8000;
k=fsim/fs;
n=0:1000;
l=length(n);
x=cos(2*pi*1000*n/fsim);
y=x(1:k:l);
L=length(y);
n1=0:L-1;
stem(n1,y)
title('AD'),ylabel('x[n]'),xlabel('n')
b.
[H,W]=dtft(y,1000);
plot(W,abs(H));
title('DTFT AD'),ylabel('X(jw)'),xlabel('w')
3.5设计一个重建滤波器
B.
fsim=80000;
f0=1000;
fs=8000;
y2=zeros(1,L);
for i=0:L1-1;
y2(i*delta+1)=y(i+1);
end
fcut=2*(fs/2)/fsim;
[b,a]=cheby2(9,60,fcut);
x1=delta*filter(b,a,y2);
[c,d]=freqz(b,a,1000,'whole');
d(501:1000)=d(501:1000)-2*pi;
d=fftshift(d);
d=d/2/pi/1000*fsim;
c=fftshift(c);
plot(d,abs(c));ylabel('|H(j\omega)|');xlabel('FREQUENCY(kHz)');
3.6 D/A转换:
a.
y2=zeros(1,L);
for i=0:100;
y2(i*10+1)=y(i+1);
end
yy=filter(b,a,y2);
t=[0:0.001:1];
plot(t,yy)
ylabel('xr(t)'),xlabel('t')
b.
fmagplot(yy,0.0000125)
3.7测试混叠
function [x,x1,y,y1,y2]=testall(f0,fs,fsim)
n=0:1000;
fsim=80000;
dt=1/fsim;
t=n./fsim;
x=cos(2*pi*f0*n/fsim);
delta=round(fsim/fs);
L=length(x);
y1=zeros(1,L);
y1(1:delta:L)=x(1:delta:L);
y=x(1:delta:L);
L1=length(y);
n1=0:L1-1;
Nfft=round(2.^round(log2(5*L)));
Xa=fft(x,Nfft);
range=0:(Nfft/4);
ff=range/Nfft/dt;
[H,W]=dtft(y,L);
w1=W/2/pi/1000*fs;
y2=zeros(1,L);
for i=0:L1-1;
y2(i*delta+1)=y(i+1);
end
fcut=2*(fs/2)/fsim;
[b,a]=cheby2(9,60,fcut);
x1=delta*filter(b,a,y2);
M=length(x1);
Nfft1=round(2.^round(log2(5*M)));
X=fft(x1,Nfft1);
range1=0:(Nfft1/4);
ff1=range1/Nfft1/dt;
subplot(223);plot(t,x1);grid;title('Xr(t)');xlabel('t');
subplot(224);plot(ff1/1000,abs(X(1:length(range1))));title('|Xr(j\omega)|');xlabel('kHz');
subplot(221);plot(t,x);grid;title('X(t)');xlabel('t');
subplot(222);plot(ff/1000,abs(Xa(1:length(range))));title('|X(j\omega)|');xlabel('kHz');
a,
b,
f0=6kHz
f0=7kHz
f0=9kHz
f0=10kHz
f0=15kHz
数字信号处理实验报告(八)
一、实验名称:音频频谱分析仪设计与实现
二、实验原理:
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.5[max(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(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、模块划分
模块化就是把程序划分成独立命名且可独立访问的模块,每个模块完成一个子功能,把这些模块集成起来构成一个整体,可以完成指定的功能满足用户需求。根据人类解决一般问题的经验,如果一个问题由两个问题组合而成,那么它的复杂程度大于分别考虑每个问题时的复杂程度之和,也就是说把复杂的问题分解成许多容易解决的小问题,原来的问题也就容易解决了。这就是模块化的根据。
在模块划分时应遵循如下规则:改进软件结构提高模块独立性;模块规模应该适中;深度、宽度、扇出和扇入都应适当;模块的作用域应该在控制域之内;力争降低模块接口的复杂程度;设计单入口单出口的模块;模块功能应该可以预测。
三、实验内容:参考以上原理,查阅相关资料,构建交互界面,设计一个音频频谱分析仪,实现一下功能:
(1) 音频信号信号输入,从声卡输入、从WAV文件输入、从标准信号发生器输入;
(2) 信号波形分析,包括幅值、频率、周期、相位的估计,以及统计量峰值、均值、均方值和方差的计算;
(3) 信号频谱分析,频率、周期的估计,图形显示幅值谱、相位谱、实频谱、虚频谱和功率谱的曲线。
四、实验程序
正弦波
混叠正弦波
方波
三角波
锯齿波
白噪声
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 GUIDE's 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 EDIT
gui_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(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 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 structure
guidata(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 structure
varargout{1} = 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 soundcard
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');
% --- 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 generator
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');
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
% contents{get(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');
end
if get(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([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 WAVfile
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');
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
function samplenum_Callback(hObject, eventdata, handles)
% hObject handle to samplenum (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 samplenum as text
% str2double(get(hObject,'String')) returns contents of samplenum as a double
% --- Executes during object creation, after setting all properties.
function samplenum_CreateFcn(hObject, eventdata, handles)
% hObject handle to samplenum (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 pointfrom_Callback(hObject, eventdata, handles)
% hObject handle to pointfrom (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 pointfrom as text
% str2double(get(hObject,'String')) returns contents of pointfrom as a double
% --- 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
function pointto_Callback(hObject, eventdata, handles)
% hObject handle to pointto (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 pointto as text
% str2double(get(hObject,'String')) returns contents of pointto as a double
% --- 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 analyseall.
function analyseall_Callback(hObject, eventdata, handles)
% hObject handle to analyseall (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
if get(hObject,'Value')==0.0
set(handles.pointfrom,'Enable','on');
set(handles.pointto,'Enable','on');
else
set(handles.pointfrom,'String','1','Enable','off');
set(handles.pointto,'String',get(handles.samplenum,'String'),'Enable','off');
end
% Hint: get(hObject,'Value') returns toggle state of analyseall
% --- 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','samplerate'),'String'));
N=str2double(get(findobj('Tag','samplenum'),'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;
% 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<handles.y(i)
ymax=handles.y(i);
end
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);
set(handles.outt,'String',1/freq);
set(handles.outfreq,'String',num2str(freq));
%amplitude
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.outs,'String',std(handles.y(from:to))^2);
% --- 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','samplerate'),'String'));
N=str2double(get(findobj('Tag','samplenum'),'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));
set(handles.foutt,'String',1/f(I));
set(handles.foutfreq,'String',f(I));
Y=Y(1:(to-from+1)/2);
plot(handles.plot1,f,2*sqrt(Y.*conj(Y)));
plot(handles.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(handles.plot1,'amplitude');
ylabel(handles.plot2,'phase(rad)');
ylabel(handles.plot3,'real');
ylabel(handles.plot4,'Imaginary');
ylabel(handles.plot5,'power');
function outt_Callback(hObject, eventdata, handles)
% hObject handle to outt (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 outt as text
% str2double(get(hObject,'String')) returns contents of outt as a double
% --- Executes during object creation, after setting all properties.
function outt_CreateFcn(hObject, eventdata, handles)
% hObject handle to outt (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 outfreq_Callback(hObject, eventdata, handles)
% hObject handle to outfreq (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 outfreq as text
% str2double(get(hObject,'String')) returns contents of outfreq as a double
% --- 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
function outamp_Callback(hObject, eventdata, handles)
% hObject handle to outamp (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 outamp as text
% str2double(get(hObject,'String')) returns contents of outamp as a double
% --- 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
function outphase_Callback(hObject, eventdata, handles)
% hObject handle to outphase (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 outphase as text
% str2double(get(hObject,'String')) returns contents of outphase as a double
% --- 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
function outpeak_Callback(hObject, eventdata, handles)
% hObject handle to outpeak (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 outpeak as text
% str2double(get(hObject,'String')) returns contents of outpeak as a double
% --- 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.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function outmean_Callback(hObject, eventdata, handles)
% hObject handle to outmean (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 outmean as text
% str2double(get(hObject,'String')) returns contents of outmean as a double
% --- 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
function outmeansquare_Callback(hObject, eventdata, handles)
% hObject handle to outmeansquare (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 outmeansquare as text
% str2double(get(hObject,'String')) returns contents of outmeansquare as a double
% --- Executes during object creation, after setting all properties.
function outmeansquare_CreateFcn(hObject, eventdata, handles)
% hObject handle to outmeansquare (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 outs_Callback(hObject, eventdata, handles)
% hObject handle to outs (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 outs as text
% str2double(get(hObject,'String')) returns contents of outs as a double
% --- Executes during object creation, after setting all properties.
function outs_CreateFcn(hObject, eventdata, handles)
% hObject handle to outs (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 foutt_Callback(hObject, eventdata, handles)
% hObject handle to foutt (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 foutt as text
% str2double(get(hObject,'String')) returns contents of foutt as a double
% --- 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
function foutfreq_Callback(hObject, eventdata, handles)
% hObject handle to foutfreq (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 foutfreq as text
% str2double(get(hObject,'String')) returns contents of foutfreq as a double
% --- 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.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in play.
function play_Callback(hObject, eventdata, handles)
% hObject handle to play (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'));
wavplay(handles.y,Fs);
% --- Executes on selection change in wavetype.
function wavetype_Callback(hObject, eventdata, handles)
% hObject handle to wavetype (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 wavetype contents as cell array
% contents{get(hObject,'Value')} returns selected item from wavetype
% --- Executes during object creation, after setting all properties.
function wavetype_CreateFcn(hObject, eventdata, handles)
% hObject handle to wavetype (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 deletion, before destroying properties.
function add_DeleteFcn(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)
% --- Executes during object creation, after setting all properties.
function time_CreateFcn(hObject, eventdata, handles)
% hObject handle to time (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: place code in OpeningFcn to populate time
% --- Executes on slider movement.
function scale_Callback(hObject, eventdata, handles)
% hObject handle to scale (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,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
val=get(hObject,'value');
val=10^(val*5+1);
x=get(handles.xmove,'Value')*str2double(get(handles.samplenum,'String'));
axis(handles.time,[x val+x min(handles.y) max(handles.y)]);
% --- Executes during object creation, after setting all properties.
function scale_CreateFcn(hObject, eventdata, handles)
% hObject handle to scale (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
% --- Executes on slider movement.
function xmove_Callback(hObject, eventdata, handles)
% hObject handle to xmove (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,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
val=get(handles.scale,'value');
val=10^(val*5+1);
x=get(hObject,'Value')*str2double(get(handles.samplenum,'String'));
axis(handles.time,[x val+x min(handles.y) max(handles.y)]);
% --- Executes during object creation, after setting all properties.
function xmove_CreateFcn(hObject, eventdata, handles)
% hObject handle to xmove (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
% --- Executes on slider movement.
function scale2_Callback(hObject, eventdata, handles)
% hObject handle to scale2 (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,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
val=get(hObject,'value');
val=10^(val*5+1);
xlim(handles.plot1,[0 val]);
xlim(handles.plot2,[0 val]);
xlim(handles.plot3,[0 val]);
xlim(handles.plot4,[0 val]);
% --- Executes during object creation, after setting all properties.
function scale2_CreateFcn(hObject, eventdata, handles)
% hObject handle to scale2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: slider controls usually have a light gray background.
If isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
结果分析:
通过本次实验了解了gui的设计,学习了图形制作和程序设计,设计过程中有很多的不完美的地方,也有很多东西不懂,但也收获了很多!
实验报告哈尔滨工程大学教务处制实验一软硬件实验环境配置实验一实验目的本次实验主要是要求信息安全专业学生熟悉常用的保密泄密分析软件及…
水平管空隙率的测量预习报告一实验目的1基本掌握用仪测量空隙率的方法2了解与间的关系二实验原理射线衰减法测量是目前应用最多的一种方法…
数字信号处理实验实验一基本信号班级姓名学号指导教师20xx年10月实验一基本信号一实验原理本节专注于用MATLAB产生一些基本离散…
实验一数字基带信号实验一实验目的1了解单极性码双极性码归零码不归零码等基带信号波形特点2掌握AMIHDB3码的编码规则3了解HDB…
南京信息工程大学数字信号处理实验报告学院:电子与信息工程学院班级:11通信1班学号:XXX姓名:XX指导教师:XX20XX/12/…
实验一信号系统及系统响应1实验目的熟悉连续信号经过理想抽样前后的频谱变化关系加深对时域抽样定理的理解熟悉时域离散系统的时域特性利用…
北京信息科技大学实验报告课程名称数字信号处理实验项目IIR数字滤波器设计实验仪器计算机MATLAB软件学院信息与通信工程学院班级姓…
实验一用FFT作谱分析实验目的1进一步加深DFT算法原理和基本性质的理解因为FFT只是DFT的一种快速算法所以FFT的运算结果必然…
数字信号处理实验实验八音频频谱分析仪设计与实现班级姓名学号指导老师年11月20xx二实验内容functionvarargoutun…
实习报告——电气专题摘要:进入21世纪我国的船舶工业电气在自动化系统和技术上有了飞跃,特别是在引进吸收国外技术后,能生产出符合国际…