?? singal_system_analysis.m
字號(hào):
function varargout = singal_system_analysis(varargin)
%===============================================================
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @singal_system_analysis_OpeningFcn, ...
'gui_OutputFcn', @singal_system_analysis_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin & isstr(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 singal_system_analysis is made visible.
function singal_system_analysis_OpeningFcn(hObject, eventdata, handles, varargin)
% Choose default command line output for singal_system_analysis
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
set(handles.insingal_listbox,'string','均勻分布白噪聲|正態(tài)分布白噪聲|鳥(niǎo)叫聲|火車?guó)Q笛聲|Chi 2分布隨機(jī)噪聲|窄帶正態(tài)過(guò)程');
set(handles.insingal_edit,'string','幅度服從均勻分布的白噪聲');
set(handles.outsingal_edit,'string','輸入信號(hào)經(jīng)過(guò)系統(tǒng)后的輸出信號(hào)');
set(handles.insignal_popupmenu,'string','時(shí)域波形|頻域波形|自相關(guān)估計(jì)|功率譜估計(jì)|概率分布圖');
set(handles.outsingal_popupmenu,'string','時(shí)域波形|頻域波形|自相關(guān)估計(jì)|功率譜估計(jì)|概率分布圖');
set(handles.system_listbox,'string','全通系統(tǒng)|低通系統(tǒng)|高通系統(tǒng)|帶通系統(tǒng)|平方律檢波|全波線性檢波|半波線性檢波');
set(handles.system_edit,'string','即輸出等于輸入');
% --- Outputs from this function are returned to the command line.
function varargout = singal_system_analysis_OutputFcn(hObject, eventdata, handles)
% Get default command line output from handles structure
varargout{1} = handles.output;
%=================================================================
%==input===========================================================
% --- Executes during object creation, after setting all properties.
function insingal_listbox_CreateFcn(hObject, eventdata, handles)
if ispc
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
% --- Executes on selection change in insingal_listbox.
function insingal_listbox_Callback(hObject, eventdata, handles)
inlistindex=get(handles.insingal_listbox,'Value');
inliststr={'幅度服從均勻分布的白噪聲','幅度服從正態(tài)(高斯)分布的白噪聲',...
'鳥(niǎo)叫聲,能量主要集中在2600~4700Hz,可看做寬帶隨機(jī)過(guò)程',...
'火車?guó)Q笛聲,可看做寬帶隨機(jī)過(guò)程',...
'Chi 2分布的寬帶隨機(jī)過(guò)程'...
'窄帶正態(tài)隨機(jī)過(guò)程'};
set(handles.insingal_edit,'string',inliststr(inlistindex));
% --- Executes during object creation, after setting all properties.
function insignal_popupmenu_CreateFcn(hObject, eventdata, handles)
if ispc
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
%=================================================================
%==system=========================================================
% --- Executes during object creation, after setting all properties.
function system_listbox_CreateFcn(hObject, eventdata, handles)
if ispc
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
% --- Executes on selection change in system_listbox.
function system_listbox_Callback(hObject, eventdata, handles)
systemlistindex=get(handles.system_listbox,'Value');
systemliststr={'即輸出等于輸入',...
'輸入信號(hào)通過(guò)具有低通特性的濾波器(低通截至頻率2000Hz)',...
'輸入信號(hào)通過(guò)具有高通特性的濾波器(高通截至頻率2000Hz)',...
'輸入信號(hào)通過(guò)具有帶通特性的濾波器(通帶3000~3300Hz)',...
'輸入信號(hào)通過(guò)平方律檢波器件',...
'輸入信號(hào)通過(guò)全波線性檢波器件',...
'輸入信號(hào)通過(guò)半波線性檢波器件'};
set(handles.system_edit,'string',systemliststr(systemlistindex));
Fs=10000;
%輸入信號(hào)經(jīng)過(guò)選擇的系統(tǒng)生成輸出信號(hào)
sysindex=get(handles.system_listbox,'Value');
if sysindex==1
M=[1 1];
f=[0 Fs/2]/(Fs/2);
[B,A]=yulewalk(11,f,M);
elseif sysindex==2
M=[1 1 0 0];
f=[0 2000 2100 Fs/2]/(Fs/2);
[B,A]=yulewalk(30,f,M);
elseif sysindex==3
M=[0 0 1 1];
f=[0 2000 2100 Fs/2]/(Fs/2);
[B,A]=yulewalk(25,f,M);
elseif sysindex==4
M=[0 0 1 1 0 0 ];
f=[0 3000 3050 3350 3400 Fs/2]/(Fs/2);
[B,A]=yulewalk(50,f,M);
end
%畫出系統(tǒng)的特性曲線
axes(handles.system_axes)
if sysindex==5 %y=x^2
x=-1:0.1:1;
y=x.^2;
plot(x,y);grid on;axis([-2 2 0 inf]);xlabel('X');ylabel('Y');title('\fontsize{9}平方律檢波');
elseif sysindex==6
x=-1:0.1:1;
y=abs(x);
plot(x,y);grid on;axis([-2 2 0 inf]);xlabel('X');ylabel('Y');title('\fontsize{9}全波線性檢波');
elseif sysindex==7
x=-1:0.1:1;
y=(x+abs(x))/2;
plot(x,y);grid on;axis([-2 2 0 inf]);xlabel('X');ylabel('Y');title('\fontsize{9}半波線性檢波');
else
[H,W]=freqz(B,A,128);
plot(f*Fs/2,M,':r',W*Fs/(2*pi),abs(H),'-');grid on;
legend('\fontsize{9}理想曲線','\fontsize{9}實(shí)際曲線');xlabel('f/Hz');ylabel('\fontsize{9}幅頻特性');
title('\fontsize{9}系統(tǒng)');
end
%================================================================
%==output=========================================================
% --- Executes during object creation, after setting all properties.
function outsingal_edit_CreateFcn(hObject, eventdata, handles)
if ispc
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
% --- Executes during object creation, after setting all properties.
function outsingal_listbox_CreateFcn(hObject, eventdata, handles)
if ispc
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
%===============================================================
% --- Executes during object creation, after setting all properties.
function outsingal_popupmenu_CreateFcn(hObject, eventdata, handles)
if ispc
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
% --- Executes on button press in outsingal_refreshbutton.
function outsingal_refreshbutton_Callback(hObject, eventdata, handles)
inlistindex=get(handles.insingal_listbox,'Value');
%產(chǎn)生適當(dāng)?shù)男盘?hào)向量
Fs=10000;Ts=1/Fs;N=8096;t=[0:N-1]*Ts;
%均值和方差
Mu=0;Sigma=1;
%改變種子,可以使結(jié)果更“精確”
rand('state',1)
Nwhite=rand(1,N);
Nwhite=Nwhite-0.5+Mu;
temp=sqrt(12*(Mu^2+Sigma));
Nwhite=temp*Nwhite;
%改變種子,可以使結(jié)果更“精確”
rand('state',2)
Ngauss=randn(1,N);
temp=sqrt(Mu^2+Sigma);
Ngauss=temp*Ngauss;
%===============================================================
%根據(jù)選擇產(chǎn)生輸入信號(hào)
if inlistindex==1
X=Nwhite;
elseif inlistindex==2
X=Ngauss;
elseif inlistindex==3
load('chirp','Fs','y')
X=y(1:N);Fs=10000;
elseif inlistindex==4
load('train','Fs','y')
X=y(1:N);Fs=10000;
elseif inlistindex==5
X=chi2rnd(4,1,N);
elseif inlistindex==6
M=[0 0 1 1 0 0 ];
f=[0 3000 3050 3350 3400 Fs/2]/(Fs/2);
[B,A]=yulewalk(40,f,M);
Nt=filter(B,A,Ngauss);
X=Nt;
end
%===============================================================
%畫出輸入信號(hào)的圖形
inpopindex=get(handles.insignal_popupmenu,'Value');
axes(handles.insingal_axes)
if inpopindex==1
plot(t,X);grid on;
axis([0 200*Ts min(X) max(X)]);
xlabel('t/s');title('\fontsize{9}時(shí)域波形');
elseif inpopindex==2
Xf=fft(X,512);
semilogy((0:511)*Fs/512,abs(Xf));grid on;
axis([0 Fs/2 log(min(Xf)) inf]);
xlabel('f/Hz');title('\fontsize{9}頻域波形');
elseif inpopindex==3
R=xcorr(X,'biased');
plot((-N:length(R)-N-1)*Ts,R);grid on;
axis([-N*Ts (length(R)-N-1)*Ts min(R) max(R)]);
xlabel('t/s');title('\fontsize{9}自相關(guān)函數(shù)');
elseif inpopindex==4
[Pxx,f] = pwelch(X,[],[],1024,Fs);
semilogy(f,Pxx);grid on;
axis([min(f) max(f) log(min(Pxx)) inf]);
xlabel('f/Hz');title('\fontsize{9}功率譜密度');
elseif inpopindex==5
histfit(X,50);
title('\fontsize{9}概率分布直方圖');grid on;
h = findobj(gca,'Type','line');
set(h,'Color','r');
end
%輸入信號(hào)經(jīng)過(guò)選擇的系統(tǒng)生成輸出信號(hào)
sysindex=get(handles.system_listbox,'Value');
if sysindex==1
M=[1 1];
f=[0 Fs/2]/(Fs/2);
[B,A]=yulewalk(11,f,M);
Y=filter(B,A,X);
elseif sysindex==2
M=[1 1 0 0];
f=[0 2000 2100 Fs/2]/(Fs/2);
[B,A]=yulewalk(30,f,M);
Y=filter(B,A,X);
elseif sysindex==3
M=[0 0 1 1];
f=[0 2000 2100 Fs/2]/(Fs/2);
[B,A]=yulewalk(25,f,M);
Y=filter(B,A,X);
elseif sysindex==4
M=[0 0 1 1 0 0 ];
f=[0 3000 3050 3350 3400 Fs/2]/(Fs/2);
[B,A]=yulewalk(50,f,M);
Y=filter(B,A,X);
elseif sysindex==5
Y=X.^2;
elseif sysindex==6
Y=abs(X);
elseif sysindex==7
Y=(X+abs(X))/2;
end
%畫出系統(tǒng)的特性曲線
axes(handles.system_axes)
if sysindex==5 %y=x^2
x=-1:0.1:1;
y=x.^2;
plot(x,y);grid on;axis([-2 2 0 inf]);xlabel('X');ylabel('Y');title('\fontsize{9}平方律檢波');
elseif sysindex==6
x=-1:0.1:1;
y=abs(x);
plot(x,y);grid on;axis([-2 2 0 inf]);xlabel('X');ylabel('Y');title('\fontsize{9}全波線性檢波');
elseif sysindex==7
x=-1:0.1:1;
y=(x+abs(x))/2;
plot(x,y);grid on;axis([-2 2 0 inf]);xlabel('X');ylabel('Y');title('\fontsize{9}半波線性檢波');
else
[H,W]=freqz(B,A,128);
plot(f*Fs/2,M,':r',W*Fs/(2*pi),abs(H),'-');grid on;
legend('\fontsize{9}理想曲線','\fontsize{9}實(shí)際曲線');xlabel('f/Hz');ylabel('\fontsize{9}幅頻特性');
title('\fontsize{9}系統(tǒng)');
end
%===============================================================
%畫出輸出信號(hào)圖形
outpopindex=get(handles.outsingal_popupmenu,'Value');
axes(handles.outsingal_axes)
if outpopindex==1
plot(t,Y);
axis([0 200*Ts min(Y) max(Y)]);
xlabel('t/s');title('\fontsize{9}時(shí)域波形');grid on;
elseif outpopindex==2
Yf=fft(Y,512);
semilogy((0:511)*Fs/512,abs(Yf));grid on;
axis([0 Fs/2 log(min(Yf)) inf]);
xlabel('f/Hz'); title('\fontsize{9}頻域波形');
elseif outpopindex==3
R=xcorr(Y,'biased');
plot((-N:length(R)-N-1)*Ts,R);
axis([-N*Ts (length(R)-N-1)*Ts min(R) max(R)]);
xlabel('t/s');title('\fontsize{9}自相關(guān)函數(shù)');grid on;
elseif outpopindex==4
[Pyy,f] = pwelch(Y,[],[],1024,Fs);
semilogy(f,Pyy);
axis([min(f) max(f) log(min(Pyy)) inf]);
xlabel('f/Hz');title('\fontsize{9}功率譜密度');grid on;
elseif outpopindex==5
histfit(Y,55);
title('\fontsize{9}概率分布直方圖');grid on;
h = findobj(gca,'Type','patch');
set(h,'FaceColor','r','EdgeColor','w');
h = findobj(gca,'Type','line');
set(h,'Color','b');
end
%=================================================================
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -