📄 auto_meas.m
字号:
function varargout = Auto_Meas(varargin)
% AUTO_MEAS M-file for Auto_Meas.fig
% AUTO_MEAS, by itself, creates a new AUTO_MEAS or raises the existing
% singleton*.
%
% H = AUTO_MEAS returns the handle to a new AUTO_MEAS or the handle to
% the existing singleton*.
%
% AUTO_MEAS('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in AUTO_MEAS.M with the given input arguments.
%
% AUTO_MEAS('Property','Value',...) creates a new AUTO_MEAS or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before Auto_Meas_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to Auto_Meas_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 Auto_Meas
% Last Modified by GUIDE v2.5 20-Dec-2007 11:41:45
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @Auto_Meas_OpeningFcn, ...
'gui_OutputFcn', @Auto_Meas_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 Auto_Meas is made visible.
function Auto_Meas_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 Auto_Meas (see VARARGIN)
% Choose default command line output for Auto_Meas
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes Auto_Meas wait for user response (see UIRESUME)
% uiwait(handles.figure1);
%%%%%%%%%%%%%% Initializing the Environment %%%%%%%%%%%%%%%%%%%%%
set(handles.edit_center,'string','1');
set(handles.edit_span,'string','1');
set(handles.button_close,'enable','off');
set(handles.button_stop,'enable','off');
set(handles.button_param,'enable','off');
set(handles.button_ad8341,'enable','off');
set(handles.button_adl5390,'enable','off');
set(handles.button_sa90_0001,'enable','off');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% --- Outputs from this function are returned to the command line.
function varargout = Auto_Meas_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 button_initial.
function button_initial_Callback(hObject, eventdata, handles)
% hObject handle to button_initial (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
clc
global cc rtdx_chan ins num freq
try
cc=ccsdsp;
rtdx_chan = cc.rtdx;
rtdx_chan.enable;
% Open channel for reading
open(rtdx_chan, 'ochan', 'r');
open(rtdx_chan,'ichan','w');
set(hObject,'Enable','off');
ins=tcpip('10.105.5.100',5025);
set(ins, 'InputBufferSize', 30000);
fopen(ins);
if(~strcmp(ins.Status,'open'))
errordlg('Can''t open Instrument !');
return;
end
catch
errmsg = lasterr;
errordlg(errmsg,'Initialization Failure!','modal')
end
% fprintf(ins, ':SYST:PRES');
fprintf(ins,':CALC1:PAR1:SEL');
% fprintf(ins,':ABOR');
fprintf(ins,':SENS1:SWE:POIN 401');
fprintf(ins,':CALC1:FORM PLIN');
% fprintf(ins,':SENS1:FREQ:START 1.5E9');
% fprintf(ins,':SENS1:FREQ:STOP 2.4E9');
%%%%%%%%%%%%%%%%%%%%% span frequency %%%%%%%%%%%%%%%%%%%%%%%%%%%
center=get(handles.edit_center,'string');
value=str2num(center);
if(value<0.1 | value > 5)
errordlg('error in setting the Center Frequency!');
return;
end
str=sprintf(':SENS1:FREQ:CENT %g',value*10^9);
fprintf(ins,str);
%%%%%%%%%%%%%%%%%%%% center frequency %%%%%%%%%%%%%%%%%%%%%%%%%%
span=get(handles.edit_span,'string');
value=str2num(span);
if(value<0.001 | value > 5)
errordlg('error in setting the Span Frequency!');
return;
end
str=sprintf(':SENS1:FREQ:SPAN %g',value*10^9);
fprintf(ins,str);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
fprintf(ins,':INIT1:CONT ON');
fprintf(ins,':CALC1:PAR1:SEL');
fprintf(ins,':TRIG:SOUR BUS');
fprintf(ins,':FORM:DATA REAL32');
fprintf(ins,':SENS1:SWE:POIN?');
num=str2num(fscanf(ins));
fprintf(ins,':SENS1:FREQ:DATA?');
freq=fread(ins,num+2,'float32');
str=sprintf('%g',freq(fix(num/2+2+1))/(10^9));
set(handles.edit_center,'string',str); % display the frequency
freq=freq(3:end);
set(handles.edit_center,'enable','off');
set(handles.edit_span,'enable','off');
set(handles.button_close,'enable','on');
set(handles.button_param,'enable','on');
function edit_center_Callback(hObject, eventdata, handles)
% hObject handle to edit_center (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 edit_center as text
% str2double(get(hObject,'String')) returns contents of edit_center as a double
% --- Executes during object creation, after setting all properties.
function edit_center_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit_center (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 edit_span_Callback(hObject, eventdata, handles)
% hObject handle to edit_span (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 edit_span as text
% str2double(get(hObject,'String')) returns contents of edit_span as a double
% --- Executes during object creation, after setting all properties.
function edit_span_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit_span (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 button_close.
function button_close_Callback(hObject, eventdata, handles)
% hObject handle to button_close (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global cc rtdx_chan ins
close(rtdx_chan,'all');
fclose(ins);
set(handles.button_initial,'Enable','on');
set(handles.edit_center,'enable','on');
set(handles.edit_span,'enable','on');
set(handles.button_close,'enable','off');
set(handles.button_param,'enable','off');
% --- Executes on button press in button_param.
function button_param_Callback(hObject, eventdata, handles)
% hObject handle to button_param (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
clc;
scan_mode;
load param_scanning; % load the model_num, param_amp,param_pha
switch(model_num)
case 1
str=sprintf('The current Parameter Model is:\n "Point test"\n Amplitude attenuation is:\n"%4.1fdB" \nPhase delay is:\n"%4.1f deg"',param_amp,param_pha);
set(handles.text_param,'string',str);
case 2
var1=min(param_pha);
var2=max(param_pha);
var3=param_pha(2)-param_pha(1);
str=sprintf('The current Parameter Model is:\n "Phase Scanning"\n Amplitude attenuation is:\n"%4.1fdB" \nPhase delay is:\n"form %4.1f to %4.1f deg, step is %4.1f"',param_amp,var1,var2,var3);
set(handles.text_param,'string',str);
case 3
var1=min(param_amp);
var2=max(param_amp);
var3=param_amp(2)-param_amp(1);
str=sprintf('The current Parameter Model is:\n "Amplitude Scanning"\n Amplitude attenuation is:\n"form %4.1f to %4.1f deg, step is %4.1f"\nPhase delay is:\n"%4.1f deg"',var1,var2,var3,param_pha);
set(handles.text_param,'string',str);
case 4
var1=min(param_amp);
var2=max(param_amp);
var3=param_amp(2)-param_amp(1);
var4=min(param_pha);
var5=max(param_pha);
var6=param_pha(2)-param_pha(1);
str=sprintf('The current Parameter Model is:\n "Area Scanning"\n Amplitude attenuation is:\n"form %4.1f to %4.1f dB, step is %4.1f"\nPhase delay is:\n"form %4.1f to %4.1f deg, step is %4.1f"',var1,var2,var3,var4,var5,var6);
set(handles.text_param,'string',str);
otherwise
end
global param_amp param_pha
set(handles.button_ad8341,'enable','on');
set(handles.button_adl5390,'enable','on');
set(handles.button_sa90_0001,'enable','on');
% --- Executes on button press in button_adl5390.
function button_adl5390_Callback(hObject, eventdata, handles)
% hObject handle to button_adl5390 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global param_amp param_pha
global cc rtdx_chan ins num freq var_pause
set(handles.button_stop,'enable','on');
set(handles.button_ad8341,'enable','off');
set(handles.button_sa90_0001,'enable','off');
center=get(handles.edit_center,'string');
value1=str2num(center);
span=get(handles.edit_span,'string');
value2=str2num(span);
str1=sprintf('Start=%gGHz Center=%gGHz Stop=%gGHz',value1-value2/2,value1,value1+value2/2);
str2=sprintf('The measured Frequency is:%gGHz',value1);
[I,Q,mea_pha,gain]=adl5390(param_amp,param_pha); % get the control voltage of the 8341
total=length(I);
data=[];
h = waitbar(0,'Measure in Processing ...');
counter=0;
var_pause=0;
for i=1:total
counter=counter+1;
if counter==10
counter=0;
pause(0.001);
end
if var_pause==1
close(h);
return;
end
send(I(i)*4096,Q(i)*4096); % must convert the analog value to the Control value
str_mea=sprintf('IQ Control variable:\n Phase is: %d\n Gain is:%g',mea_pha(i),gain(i));
set(handles.text_disp,'string',str_mea);
fread(ins,ins.BytesAvailable,'uint8');
fprintf(ins,':TRIG:SING');
fprintf(ins,'*OPC?');
mea=fscanf(ins,'%c',3);
% if(mea(2)~='1')
% errordlg('Error in the measure return !','modal');
% fclose(ins);
% return;
% end
fprintf(ins,':CALC1:DATA:FDAT?');
var1=fread(ins,[2,num+1],'float32');
data=[data var1(:,fix((num/2+2)))];
waitbar(i/total);
figure(2);
subplot(211);plot(freq,var1(2,2:end));ylabel('PHASE');xlabel(str1);
subplot(212);plot(freq,20*log10(var1(1,2:end)));ylabel('GAIN');xlabel(str1);
axis([(value1-value2/2)*10^9 (value1+value2/2)*10^9 -60 10]);
set(gca,'YTick',[-60 -50 -40 -35 -30 -25 -20 -15 -10 -5 0 5 10]);grid on;
end
close(h);
for i=1:total
I_m(i)=data(1,i)*cos(data(2,i)*pi/180);
Q_m(i)=data(1,i)*sin(data(2,i)*pi/180);
end
figure(1);
plot((I-0.5)/0.285,(Q-0.5)/0.285,':');hold on;
plot(I_m,Q_m,'r-.');hold on;
plot([-1 1],[0 0]);hold on;
plot([0 0],[-1 1]);hold off;
legend('Control vector','Measure result');
title(str2);
save result I Q I_m Q_m;
set(handles.button_ad8341,'enable','on');
set(handles.button_sa90_0001,'enable','on');
set(handles.button_stop,'enable','off');
% --- Executes on button press in pushbutton7.
function pushbutton7_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton7 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in button_ad8341.
function button_ad8341_Callback(hObject, eventdata, handles)
% hObject handle to button_ad8341 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global param_amp param_pha
global cc rtdx_chan ins num freq var_pause
set(handles.button_stop,'enable','on');
set(handles.button_adl5390,'enable','off');
set(handles.button_sa90_0001,'enable','off');
center=get(handles.edit_center,'string');
value1=str2num(center);
span=get(handles.edit_span,'string');
value2=str2num(span);
str1=sprintf('Start=%gGHz Center=%gGHz Stop=%gGHz',value1-value2/2,value1,value1+value2/2);
str2=sprintf('The measured Frequency is:%gGHz',value1);
[I,Q,mea_pha,gain]=ad8341(param_amp,param_pha); % get the control voltage of the 8341
total=length(I);
data=[];
h = waitbar(0,'Measure in Processing ...');
counter=0;
var_pause=0;
for i=1:total
counter=counter+1;
if counter==10
counter=0;
pause(0.001);
end
if var_pause==1
close(h);
return;
end
send(I(i)*4096,Q(i)*4096); % must convert the analog value to the Control value
str_mea=sprintf('IQ Control variable:\n Phase is: %d\n Gain is:%g',mea_pha(i),gain(i));
set(handles.text_disp,'string',str_mea);
fread(ins,ins.BytesAvailable,'uint8');
fprintf(ins,':TRIG:SING');
fprintf(ins,'*OPC?');
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -