📄 beampatt.m
字号:
%BEAMPATT Interactive demo : array beampattern
% Author: K. Bell
% 9/3/98
% Last Updated 8/30/00
function beampatt(action,in1,in2);
% possible actions:
% 'start'
% 'redraw'
% 'setus' - in1=1 ==> from us, in1=2 ==> from theta
% 'setN'
% 'sets'
% 'setwts'
% 'info'
% 'done'
if nargin<1,
action='start';
end;
global BP_DAT
if strcmp(action,'start'),
%====================================
% Graphics initialization
oldFigNumber = watchon;
figNumber = figure;
%************************************************************************
% Figure Boundary
%************************************************************************
mm=1;
wp = 700*mm;
hp = 500*mm;
set(gcf, ...
'NumberTitle','off', ...
'Name','Beampattern', ...
'backingstore','off',...
'Position',[50 50 930 650],...
'PaperPosition',[0.25 1 8 8*hp/wp]); % prints in same proportion
axes('Position',[0.01 0.01 0.98 0.98])
set(gca,'Box','on')
set(gca,'XTick',[])
set(gca,'YTick',[])
%************************************************************************
% Beampattern plots
%************************************************************************
bp_x = 3/35; % LHS margin
bp_w = 17/35; % BP width
bp_y0 = 2/25; % lower margin
bp_yt = 1/25; % top margin
bp_h = 4.5/25; % BP height
bp_delta = (1-4*bp_h-bp_y0-bp_yt)/3;
bp_yd = bp_h+bp_delta; % y offset to next plot between plots
h1=axes('position',[bp_x bp_y0+3*bp_yd bp_w bp_h]);
h2=axes('position',[bp_x bp_y0+2*bp_yd bp_w bp_h]);
h3=axes('position',[bp_x bp_y0+1*bp_yd bp_w bp_h]);
h4=axes('position',[bp_x bp_y0+0*bp_yd bp_w bp_h]);
%************************************************************************
% Polar Beampattern plots
%************************************************************************
p_x = 20/35; % p x offset
p_w = 15/35; % p plot width
p_y0 = 10/25; % p y offset (bottom even with 4th bp up)
p_h = 15/25; % p plot height
h5=axes('position',[p_x p_y0 p_w p_h]);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% SET DEFAULT SIMULATION PARAMETERS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Array
N= 10; % number of sensors
d= 0.5; % spacing wrt design wavelength
f=1; % freq wrt design freq
us = 0; % actual DOA
wtype=1; % uniform
q=0; % weight parameter (none for uniform)
%************************************************************************
% Main Buttons
%************************************************************************
but_x = 22/35; % x offset
but_y0 = 1/25; % y off set
but_xd = 6/35; % x offset to next button
but_w = 5/35; % button width
but_h = 2/25; % button height
m_color =[0.701961 0.701961 0.701961];
it_color = [0.5 0.5 0.5];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Printing values
%m_color = 0.98*[1 1 1];
%it_color = 0.98*[1 1 1];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
b1 = uicontrol('Parent',gcf, ...
'Units','normalized', ...
'BackgroundColor',m_color, ...
'Callback','', ...
'Position',[but_x but_y0 but_w but_h], ...
'String','Info');
b2 = uicontrol('Parent',gcf, ...
'Units','normalized', ...
'BackgroundColor',m_color, ...
'Callback','beampatt(''done'')', ...
'Position',[but_x+but_xd but_y0 but_w but_h], ...
'String','Quit');
%************************************************************************
% Parameter Edit
%************************************************************************
f_x = 22/35; % frame x offset
f_y0 = 4/25; % frame
f_w = 11/35; % frame width
f_hi = 6/25; % frame unit height,
th = 0.7/25; % text height
ew = 1.5/35; % edit box width
%++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
% Array Parameters
%++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
p_color = [0.6 0.6 0.6];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Print Values
%p_color = 0.98*[1 1 1];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% frame
f1 = uicontrol('Parent',gcf, ...
'Units','normalized', ...
'Style','Frame', ...
'BackgroundColor',p_color, ...
'Position',[f_x f_y0 f_w f_hi]);
% sensor label
t1_2 = uicontrol( ...
'Units','normalized', ...
'Style','text', ...
'BackgroundColor',p_color, ...
'ForegroundColor','black', ...
'Position',[f_x+1/35 f_y0+5/25 5/35 th],...
'Horiz','left',...
'String','Number of Sensors (N)',...
'Interruptible','off');
% sensor edit box
e_N = uicontrol( ...
'Units','normalized', ...
'Style','edit', ...
'BackgroundColor','white', ...
'ForegroundColor','black', ...
'Position',[f_x+6/35 f_y0+5/25 ew th],...
'Horiz','right',...
'Userdata',N,...
'String',int2str(N),...
'Callback','beampatt(''setN'');beampatt(''redraw'')');
% spacing label
t1_3 = uicontrol( ...
'Units','normalized', ...
'Style','text', ...
'BackgroundColor',p_color, ...
'ForegroundColor','black', ...
'Position',[f_x+1/35 f_y0+4/25 5/35 th],...
'Horiz','left',...
'String','Spacing wrt lambda_o (d)',...
'Interruptible','off');
% spacing edit box
e_d = uicontrol( ...
'Units','normalized', ...
'Style','edit', ...
'BackgroundColor','white', ...
'ForegroundColor','black', ...
'Position',[f_x+6/35 f_y0+4/25 ew th],...
'Horiz','right',...
'Userdata',d,...
'String',num2str(d,'%2.2f'),...
'Callback','beampatt(''setd'');beampatt(''redraw'')');
% freq label
t1_3 = uicontrol( ...
'Units','normalized', ...
'Style','text', ...
'BackgroundColor',p_color, ...
'ForegroundColor','black', ...
'Position',[f_x+1/35 f_y0+3/25 5/35 th],...
'Horiz','left',...
'String','Freq wrt f_o (f)',...
'Interruptible','off');
% freq edit box
e_f = uicontrol( ...
'Units','normalized', ...
'Style','edit', ...
'BackgroundColor','white', ...
'ForegroundColor','black', ...
'Position',[f_x+6/35 f_y0+3/25 ew th],...
'Horiz','right',...
'Userdata',f,...
'String',num2str(f,'%2.2f'),...
'Callback','beampatt(''setf'');beampatt(''redraw'')');
% Pointing direction label
t1_4 = uicontrol( ...
'Units','normalized', ...
'Style','text', ...
'BackgroundColor',p_color, ...
'ForegroundColor','black', ...
'Position',[f_x+1/35 f_y0+2/25 5/35 th],...
'Horiz','left',...
'String','Pointing Direction: u_s',...
'Interruptible','off');
% Pointing direction (u) edit box
e_us = uicontrol( ...
'Units','normalized', ...
'Style','edit', ...
'BackgroundColor','white', ...
'ForegroundColor','black', ...
'Position',[f_x+6/35 f_y0+2/25 ew th],...
'Horiz','right',...
'Userdata',us,...
'String',num2str(us,'%1.2f'),...
'Callback','beampatt(''setus'',1);beampatt(''redraw'')');
% Pointing direction label
t1_5 = uicontrol( ...
'Units','normalized', ...
'Style','text', ...
'BackgroundColor',p_color, ...
'ForegroundColor','black', ...
'Position',[f_x+7.8/35 f_y0+2/25 1.5/35 th],...
'Horiz','left',...
'String','theta_s',...
'Interruptible','off');
% Pointing direction (theta) edit box
e_th = uicontrol( ...
'Units','normalized', ...
'Style','edit', ...
'BackgroundColor','white', ...
'ForegroundColor','black', ...
'Position',[f_x+9.3/35 f_y0+2/25 ew th],...
'Horiz','right',...
'Userdata',acos(us)*180/pi,...
'String',num2str(acos(us)*180/pi,'%3.1f'),...
'Callback','beampatt(''setus'',2);beampatt(''redraw'')');
%++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
% Weights
%++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
% title
t5_1 = uicontrol( ...
'Units','normalized', ...
'Style','text', ...
'BackgroundColor',p_color, ...
'ForegroundColor','black', ...
'Position',[f_x+1/35 f_y0+1/25 5/35 th],...
'Horiz','left',...
'String','Weights',...
'Interruptible','off');
%get(t5_1)
% weights BUTTON
b_w = uicontrol( ...
'Style','popupmenu', ...
'Units','normalized', ...
'Position',[f_x+6/35 f_y0+1/25 4.8/35 th], ...
'String','Uniform|Uniform Difference|Triangular 1|Triangular 2|Raised Cosine|Cosine^m|Raised Cosine^2|Hamming|Blackman-Harris|DPSS|Kaiser', ...
'Interruptible','on', ...
'Callback','beampatt(''setwts'');beampatt(''redraw'')');
% weight param label
t_w = uicontrol( ...
'Units','normalized', ...
'Style','text', ...
'BackgroundColor',p_color, ...
'ForegroundColor','black', ...
'Position',[f_x+1/35 f_y0 5/35 th],...
'Horiz','left',...
'String','Weight parameter []',...
'Interruptible','off');
% weight param edit box
e_w = uicontrol( ...
'Units','normalized', ...
'Style','edit', ...
'BackgroundColor','white', ...
'ForegroundColor','black', ...
'Position',[f_x+6/35 f_y0 ew th],...
'Horiz','right',...
'Userdata',q,...
'String',num2str(q,'%2.2f'),...
'Callback','beampatt(''setq'');beampatt(''redraw'')');
BP_DAT = [N; d; f;us; wtype;q;h1;h2;h3;h4;h5;e_N;e_d;e_f;e_us;e_th;b_w;e_w;t_w];
beampatt('redraw');
watchoff(oldFigNumber);
elseif strcmp(action,'setus')
e_us = BP_DAT(15);
e_th = BP_DAT(16);
if (in1==1), % set from us edit box
s=get(e_us,'string');
us=eval(s);
if us>1
us=1;
end
if us<-1
us=-1;
end
else % set from theta edit box
s=get(e_th,'string');
th=eval(s);
us=cos(eval(s)*pi/180);
end
set(e_us,'Userdata',us,...
'String',num2str(us,'%1.2f'));
set(e_th,'Userdata',acos(us)*180/pi,...
'String',num2str(acos(us)*180/pi,'%3.1f'));
BP_DAT(4)=us;
elseif strcmp(action,'setd')
e_d = BP_DAT(13);
s=get(e_d,'string');
d=eval(s);
if d<0.1
d=0.1;
end
set(e_d,'Userdata',d,'String',num2str(d,'%2.2f'));
BP_DAT(2)=d;
elseif strcmp(action,'setf')
e_f = BP_DAT(14);
s=get(e_f,'string');
f=eval(s);
if f<0.1
f=0.1;
end
set(e_f,'Userdata',f,'String',num2str(f,'%2.2f'));
BP_DAT(3)=f;
elseif strcmp(action,'setN')
e_N = BP_DAT(12);
s=get(e_N,'string');
N=eval(s);
N=round(N);
if N<=0
N=1;
end
set(e_N,'Userdata',N);
BP_DAT(1)=N;
elseif strcmp(action,'setwts')
b_w = BP_DAT(17);
e_w = BP_DAT(18);
t_w = BP_DAT(19);
wtype=get(b_w,'value');
set(b_w,'value',wtype);
BP_DAT(5)=wtype;
if wtype == 1 % uniform
q=0;
wlabel='Weight parameter []';
elseif wtype ==2 % uniform difference
q=0;
wlabel='Weight parameter []';
elseif wtype ==3 % triangular (sampling)
q=0;
wlabel='Weight parameter []';
elseif wtype ==4 % triangular (root matching)
q=0;
wlabel='Weight parameter []';
elseif wtype ==5 % raised cosine
wlabel='Rectangular height (p)';
q=0.17;
elseif wtype ==6 % cosine^n
wlabel='Cosine power (m)';
q=1;
elseif wtype ==7 % raised cosine^2
wlabel='Rectangular height (p)';
q=0.08;
elseif wtype ==8 % Hamming
wlabel='Weight parameter []';
q=0;
elseif wtype ==9 % Blackman-Harris
wlabel='Weight parameter []';
q=0;
elseif wtype ==10 % DPSS
wlabel='Region half-width (u_o)';
q=0.2;
elseif wtype ==11 % Kaiser
wlabel='Beta';
q=2;
end
set(e_w,'UserData',q,'String',num2str(q,'%2.2f'));
set(t_w,'String',wlabel);
BP_DAT(6)=q;
elseif strcmp(action,'setq')
e_w = BP_DAT(18);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -