diff --git a/@MyRsa/MyRsa.m b/@MyRsa/MyRsa.m index 9d23a95..72a32e1 100644 --- a/@MyRsa/MyRsa.m +++ b/@MyRsa/MyRsa.m @@ -1,257 +1,306 @@ classdef MyRsa < MyInstrument properties (SetAccess=protected, GetAccess=public) rbw; start_freq; stop_freq; cent_freq; span; average_no; point_no; Trace; end properties (Dependent=true) freq_vec; end methods function this=MyRsa(name,interface, address) this@MyInstrument(name, interface, address,'GuiRsa'); initGui(this); createCommandList(this); createCommandParser(this); switch interface case 'TCPIP' createTCPIP(this); end %Opens communications openDevice(this); %Finds the current status of the device readStatus(this); %Initializes the device initDevice(this); closeDevice(this); end end methods function createTCPIP(this) buffer = 1000 * 1024; visa_brand = 'ni'; visa_address_rsa = sprintf('TCPIP0::%s::inst0::INSTR',... this.address); this.Device=visa(visa_brand, visa_address_rsa,... 'InputBufferSize', buffer,... 'OutputBufferSize', buffer); set(this.Device,'InputBufferSize',1e6); set(this.Device,'Timeout',10); end function readProperty(this, varargin) for i=1:length(varargin) if ~isprop(this, varargin{i}) error('%s is not a property of the class',varargin{i}) end %Finds the index of the % sign which indicates where the value %to be written is supplied ind=strfind(this.CommandList.(varargin{i}).command,'%'); %Creates the correct read command read_command=[this.CommandList.(varargin{i}).command(1:(ind-2)),'?']; %Reads the property from the device and stores it in the %correct place this.(varargin{i})=str2double(this.read(read_command)); end end function readStatus(this) readProperty(this,'rbw','cent_freq','span','start_freq',... 'stop_freq'); end function initGui(this) set(this.Gui.reinit, 'Callback',... @(hObject, eventdata) reinitCallback(this, hObject,... eventdata)); set(this.Gui.point_no, 'Callback',... @(hObject, eventdata) point_noCallback(this, hObject,... eventdata)); set(this.Gui.start_freq, 'Callback',... @(hObject, eventdata) start_freqCallback(this, hObject,... eventdata)); set(this.Gui.stop_freq, 'Callback',... @(hObject, eventdata) stop_freqCallback(this, hObject,... eventdata)); set(this.Gui.span, 'Callback',... @(hObject, eventdata) spanCallback(this, hObject,... eventdata)); set(this.Gui.rbw, 'Callback',... @(hObject, eventdata) rbwCallback(this, hObject,... eventdata)); set(this.Gui.fetch_single, 'Callback',... - @(hObject, eventdata) fetch_singleCallback(this, hObject,... + @(hObject, eventdata) fetchCallback(this, hObject,... + eventdata)); + set(this.Gui.average_no, 'Callback',... + @(hObject, eventdata) average_noCallback(this, hObject,... + eventdata)); + set(this.Gui.enable_avg, 'Callback',... + @(hObject, eventdata) enable_avgCallback(this, hObject,... eventdata)); end - function initDevice(this) - + function initDevice(this) for i=1:this.command_no write(this, sprintf(this.CommandList.(this.command_names{i}).command,... this.CommandList.(this.command_names{i}).default)); this.(this.command_names{i})=... this.CommandList.(this.command_names{i}).default; end end function reinitCallback(this, hObject, eventdata) openDevice(this); readStatus(this); initDevice(this); write(this,'INIT:CONT ON'); closeDevice(this); %Turns off indicator set(hObject,'Value',0); end function point_noCallback(this, hObject, eventdata) value_list=get(hObject,'String'); this.point_no=str2double(value_list{get(hObject,'Value')}); openDevice(this); writeProperty(this,'point_no',this.point_no); readStatus(this); closeDevice(this); end function start_freqCallback(this, hObject, eventdata) this.start_freq=str2double(get(hObject,'String'))*1e6; openDevice(this); writeProperty(this,'start_freq',this.start_freq); readStatus(this); closeDevice(this); end function stop_freqCallback(this, hObject, eventdata) this.stop_freq=str2double(get(hObject,'String'))*1e6; openDevice(this); writeProperty(this,'stop_freq',this.stop_freq); readStatus(this); closeDevice(this); end function spanCallback(this, hObject, eventdata) this.span=str2double(get(hObject,'String'))*1e6; openDevice(this); writeProperty(this,'span',this.span); readStatus(this) closeDevice(this); end function rbwCallback(this, hObject, eventdata) this.rbw=str2double(get(hObject,'String'))*1e3; openDevice(this); writeProperty(this,'rbw',this.rbw); closeDevice(this); end function average_noCallback(this, hObject, eventdata) this.average_no=str2double(get(hObject,'String')); - openDevice(this); - writeProperty(this,'average_no',this.average_no); - closeDevice(this); + %Writes the average_no to the device only if averaging is + %enabled + if get(this.Gui.enable_avg,'Value') + openDevice(this); + writeProperty(this,'average_no',this.average_no); + closeDevice(this); + end end function createCommandList(this) addCommand(this, 'average_no','TRAC3:DPSA:AVER:COUN %d',... 1, {'numeric'}); addCommand(this, 'rbw','DPSA:BAND:RES %d Hz',... 1e3, {'numeric'}); addCommand(this, 'span','DPSA:FREQ:SPAN %d Hz',... 1e6, {'numeric'}); addCommand(this, 'start_freq','DPSA:FREQ:STAR %d Hz',... 1e6, {'numeric'}); addCommand(this, 'stop_freq','DPSA:FREQ:STOP %d Hz',... 2e6, {'numeric'}); addCommand(this, 'cent_freq','DPSA:FREQ:CENT %d Hz',... 1.5e6, {'numeric'}); addCommand(this, 'point_no','DPSA:POIN:COUN P%d',... 10401, {'numeric'}); end - function fetch_singleCallback(this, hObject, eventdata) + function fetchCallback(this, hObject, eventdata) + %Fetches the data using the settings given. This function can + %in principle be used in the future to add further fetch + %functionality. openDevice(this); readStatus(this); - fwrite(this.Device, 'fetch:dpsa:res:trace3?'); + switch get(hObject,'Tag') + case 'fetch_single' + fwrite(this.Device, 'fetch:dpsa:res:trace3?'); + end data = binblockread(this.Device,'float'); + + switch get(hObject,'Tag') + case 'fetch_single' + x=this.freq_vec/1e6; + unit_x='MHz'; + name_x='Frequency'; + end closeDevice(this); - this.Trace=MyTrace('RsaData',this.freq_vec,data,'Color','r',... - 'Marker','x','LineStyle',':'); + %Calculates the power spectrum from the data, which is in dBm. + %Output is in V^2/Hz + power_spectrum = (10.^(data/10))/this.rbw*50*0.001; + + %Plotting for test purposes - to be removed in the future + this.Trace=MyTrace('RsaData',x,power_spectrum,... + 'Color','r','unit_y','$\mathrm{V}^2/\mathrm{Hz}$',... + 'name_y','Power','Marker','x','LineStyle',':',... + 'unit_x',unit_x,'name_x',name_x); figure this.Trace.plotTrace(gca); set(this.Gui.fetch_single,'Value',0); end + function enable_avgCallback(this, hObject, eventdata) + openDevice(this) + %If averaging is turned off, set the average number on the RSA + %to 1, otherwise set it to whatever it is currently displaying. + if ~get(hObject,'Value'); + this.average_no=1; + end + set(this.Gui.average_no,'String',num2str(this.average_no)); + writeProperty(this,'average_no',this.average_no); + closeDevice(this); + end + end methods %Set function for central frequency, changes gui to show central %frequency in MHz function set.cent_freq(this, cent_freq) this.cent_freq=cent_freq; set(this.Gui.cent_freq,'String',this.cent_freq/1e6); end %Set function for rbw, changes gui to show rbw in kHz function set.rbw(this, rbw) + assert(isnumeric(rbw) && rbw>0,'RBW must be a positive double'); this.rbw=rbw; set(this.Gui.rbw,'String',this.rbw/1e3); end %Set function for span, changes gui to show span in MHz function set.span(this, span) + assert(isnumeric(span) && span>0,... + 'Span must be a positive number'); this.span=span; set(this.Gui.span,'String',this.span/1e6); end %Set function for start frequency, changes gui to show start %frequency in MHz function set.start_freq(this, start_freq) + assert(isnumeric(start_freq),'Start frequency must be a number'); this.start_freq=start_freq; set(this.Gui.start_freq,'String',this.start_freq/1e6) end %Set function for stop frequency, changes gui to show stop %frequency in MHz function set.stop_freq(this, stop_freq) + assert(isnumeric(stop_freq),... + 'Stop frequency must be a number'); this.stop_freq=stop_freq; set(this.Gui.stop_freq,'String',this.stop_freq/1e6) end %Set function for average number, also changes GUI function set.average_no(this, average_no) + assert(mod(average_no,1)==0 && average_no>0,... + 'Number of averages must be a positive integer') this.average_no=average_no; set(this.Gui.average_no,'String',this.average_no); end %Set function for point number, checks it is valid and changes GUI function set.point_no(this, point_no) point_list=get(this.Gui.point_no,'String'); ind=ismember(point_list,num2str(point_no)); if sum(ind) this.point_no=point_no; set(this.Gui.point_no,'Value',find(ind)); else error('Invalid number of points chosen for RSA') end end end methods %Generates a vector of frequencies between the start and stop %frequency of length equal to the point number function freq_vec=get.freq_vec(this) freq_vec=linspace(this.start_freq,this.stop_freq,... this.point_no) ; end end end diff --git a/GUIs/GuiRsa.fig b/GUIs/GuiRsa.fig index a8e04e0..e37e13a 100644 Binary files a/GUIs/GuiRsa.fig and b/GUIs/GuiRsa.fig differ diff --git a/GUIs/GuiRsa.m b/GUIs/GuiRsa.m index 931cef0..88fc3c1 100644 --- a/GUIs/GuiRsa.m +++ b/GUIs/GuiRsa.m @@ -1,464 +1,440 @@ function varargout = GuiRsa(varargin) % GuiRsa MATLAB code for GuiRsa.fig % GuiRsa, by itself, creates a new GuiRsa or raises the existing % singleton*. % % H = GuiRsa returns the handle to a new GuiRsa or the handle to % the existing singleton*. % % GuiRsa('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in GuiRsa.M with the given input arguments. % % GuiRsa('Property','Value',...) creates a new GuiRsa or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before GuiRsa_OpeningFcn gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to GuiRsa_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 GuiRsa -% Last Modified by GUIDE v2.5 05-Oct-2017 19:02:20 +% Last Modified by GUIDE v2.5 09-Oct-2017 16:20:12 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @GuiRsa_OpeningFcn, ... 'gui_OutputFcn', @GuiRsa_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 GuiRsa is made visible. function GuiRsa_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 GuiRsa (see VARARGIN) % Choose default command line output for GuiRsa handles.output = hObject; %use TCP/IP in Matlab buffer = 1000 * 1024; visa_brand = 'ni'; visa_address_rsa = 'TCPIP0::192.168.1.3::inst0::INSTR'; vi = visa(visa_brand, visa_address_rsa, 'InputBufferSize', buffer, ... 'OutputBufferSize', buffer); handles.vi=vi; set(vi,'InputBufferSize',1e6); set(vi,'Timeout',10); fopen(vi); %Read out / set initial settings set(handles.cent_freq,'String',num2str(str2num(query(vi,['DPSA:FREQ:CENT?']))/1e6)); set(handles.span,'String',num2str(str2num(query(vi,['DPSA:FREQ:SPAN?']))/1e6)); set(handles.start_freq,'String',num2str(str2num(query(vi,['DPSA:FREQ:STAR?']))/1e6)); set(handles.stop_freq,'String',num2str(str2num(query(vi,['DPSA:FREQ:STOP?']))/1e6)); set(handles.rbw,'String',num2str(str2num(query(vi,['DPSA:band:act?']))/1e3)); set(handles.average_no,'String','1'); fprintf(handles.vi,'TRAC3:DPSA:AVER:COUN 1'); set(handles.point_no,'Value',4); fprintf(handles.vi,'DPSA:POIN:COUN P10401'); fclose(vi); % Update handles structure guidata(hObject, handles); % UIWAIT makes GuiRsa wait for user response (see UIRESUME) % uiwait(handles.figure1); % --- Outputs from this function are returned to the command line. function varargout = GuiRsa_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; function cent_freq_Callback(hObject, eventdata, handles) % hObject handle to cent_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 cent_freq as text % str2double(get(hObject,'String')) returns contents of cent_freq as a double fopen(handles.vi); value=get(hObject,'String'); fprintf(handles.vi,['DPSA:FREQ:CENT ' value 'MHz']); set(handles.start_freq,'String',num2str(str2num(query(handles.vi,['DPSA:FREQ:STAR?']))/1e6)); set(handles.stop_freq,'String',num2str(str2num(query(handles.vi,['DPSA:FREQ:STOP?']))/1e6)); fclose(handles.vi); % --- Executes during object creation, after setting all properties. function cent_freq_CreateFcn(hObject, eventdata, handles) % hObject handle to cent_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 span_Callback(hObject, eventdata, handles) % hObject handle to 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 span as text % str2double(get(hObject,'String')) returns contents of span as a double fopen(handles.vi); value=get(hObject,'String'); fprintf(handles.vi,['DPSA:FREQ:SPAN ' value 'MHz']); set(handles.start_freq,'String',num2str(str2num(query(handles.vi,['DPSA:FREQ:STAR?']))/1e6)); set(handles.stop_freq,'String',num2str(str2num(query(handles.vi,['DPSA:FREQ:STOP?']))/1e6)); %set(handles.rbw,'String',num2str(str2num(query(vi,['DPSA:band:act?']))/1e3)); fclose(handles.vi); % --- Executes during object creation, after setting all properties. function span_CreateFcn(hObject, eventdata, handles) % hObject handle to 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 function start_freq_Callback(hObject, eventdata, handles) % hObject handle to start_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 start_freq as text % str2double(get(hObject,'String')) returns contents of start_freq as a double fopen(handles.vi); value=get(hObject,'String'); fprintf(handles.vi,['DPSA:FREQ:STAR ' value 'MHz']); set(handles.span,'String',num2str(str2num(query(handles.vi,['DPSA:FREQ:SPAN?']))/1e6)); set(handles.stop_freq,'String',num2str(str2num(query(handles.vi,['DPSA:FREQ:STOP?']))/1e6)); set(handles.cent_freq,'String',num2str(str2num(query(handles.vi,['DPSA:FREQ:CENT?']))/1e6)); %set(handles.rbw,'String',num2str(str2num(query(vi,['DPSA:band:act?']))/1e3)); fclose(handles.vi); % --- Executes during object creation, after setting all properties. function start_freq_CreateFcn(hObject, eventdata, handles) % hObject handle to start_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 rbw_Callback(hObject, eventdata, handles) % hObject handle to rbw (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 rbw as text % str2double(get(hObject,'String')) returns contents of rbw as a double fopen(handles.vi); value=get(hObject,'String'); fprintf(handles.vi,['DPSA:BAND:RES ' value 'kHz']); pause(0.1); set(hObject,'String',num2str(str2num(query(handles.vi,['DPSA:band:act?']))/1e3)); fclose(handles.vi); % --- Executes during object creation, after setting all properties. function rbw_CreateFcn(hObject, eventdata, handles) % hObject handle to rbw (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 average_no_Callback(hObject, eventdata, handles) % hObject handle to average_no (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 average_no as text % str2double(get(hObject,'String')) returns contents of average_no as a double if get(handles.enable_avg,'Value')==1 fopen(handles.vi); number=get(hObject,'String'); fprintf(handles.vi,['TRAC3:DPSA:AVER:COUN ' number]); fclose(handles.vi); else set(hObject,'String','1'); end % --- Executes during object creation, after setting all properties. function average_no_CreateFcn(hObject, eventdata, handles) % hObject handle to average_no (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 stop_freq_Callback(hObject, eventdata, handles) % hObject handle to stop_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 stop_freq as text % str2double(get(hObject,'String')) returns contents of stop_freq as a double fopen(handles.vi); value=get(hObject,'String'); fprintf(handles.vi,['DPSA:FREQ:STOP ' value 'MHz']); set(handles.span,'String',num2str(str2num(query(handles.vi,['DPSA:FREQ:SPAN?']))/1e6)); set(handles.start_freq,'String',num2str(str2num(query(handles.vi,['DPSA:FREQ:STAR?']))/1e6)); set(handles.cent_freq,'String',num2str(str2num(query(handles.vi,['DPSA:FREQ:CENT?']))/1e6)); %set(handles.rbw,'String',num2str(str2num(query(vi,['DPSA:band:act?']))/1e3)); fclose(handles.vi); % --- Executes during object creation, after setting all properties. function stop_freq_CreateFcn(hObject, eventdata, handles) % hObject handle to stop_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 % --- Executes on selection change in point_no. function point_no_Callback(hObject, eventdata, handles) % hObject handle to point_no (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: contents = cellstr(get(hObject,'String')) returns point_no contents as cell array % contents{get(hObject,'Value')} returns selected item from point_no fopen(handles.vi); contents=get(hObject,'String'); selection=contents{get(hObject,'Value')}; fprintf(handles.vi,['DPSA:POIN:COUN P' selection]); fclose(handles.vi); % --- Executes during object creation, after setting all properties. function point_no_CreateFcn(hObject, eventdata, handles) % hObject handle to point_no (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 on button press in enable_avg. function enable_avg_Callback(hObject, eventdata, handles) % hObject handle to enable_avg (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 enable_avg status=get(hObject,'Value'); fopen(handles.vi); if status==1; set(handles.average_no,'String','100'); fprintf(handles.vi,'TRAC3:DPSA:AVER:COUN 100'); else set(handles.average_no,'String','1'); fprintf(handles.vi,'TRAC3:DPSA:AVER:COUN 1'); end fclose(handles.vi); % --- Executes on button press in fetch_single. function fetch_single_Callback(hObject, eventdata, handles) % hObject handle to fetch_single (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 fetch_single -% Execute device object function(s). -number_points=get(handles.point_no,'Value'); -address=get(handles.vi,'rsrcname'); -RSA_Data = ReadRSA(number_points,address); - -%capturing the y data -x_data=RSA_Data.x; -%capturing the x data -y_data=RSA_Data.y; - -% Calculating the power spectrum (P/Hz) -Power_Spectrum = (10.^(y_data/10))/RSA_Data.res*50*0.001; - -% updating global variables and updating the plot - h_main_plot=getappdata(0,'h_main_plot'); - setappdata(h_main_plot,'x_data',x_data); - setappdata(h_main_plot,'y_data',Power_Spectrum); - setappdata(h_main_plot,'x_label',RSA_Data.xunit); - setappdata(h_main_plot,'y_label','V^2/Hz'); - update_axes=getappdata(h_main_plot,'update_axes'); - -set(hObject,'Value',0); -feval(update_axes); - -% --- Executes on button press in fetch_AVT. -function fetch_AVT_Callback(hObject, eventdata, handles) -% hObject handle to fetch_AVT (see GCBO) +% --- Executes on button press in fetch_avt. +function fetch_avt_Callback(hObject, eventdata, handles) +% hObject handle to fetch_avt (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 fetch_AVT +% Hint: get(hObject,'Value') returns toggle state of fetch_avt number_points=get(handles.point_no,'Value'); address=get(handles.vi,'rsrcname'); RSA_Data = ReadRSA_AVT(number_points,address); %capturing the y data x_data=RSA_Data.x; %capturing the x data y_data=RSA_Data.y; % Calculating the power spectrum (P/Hz) Power_Spectrum = (10.^(y_data/10))/RSA_Data.res*50*0.001; % updating global variables and updating the plot h_main_plot=getappdata(0,'h_main_plot'); setappdata(h_main_plot,'x_data',x_data); setappdata(h_main_plot,'y_data',Power_Spectrum); setappdata(h_main_plot,'x_label',RSA_Data.xunit); setappdata(h_main_plot,'y_label','V^2/Hz'); update_axes=getappdata(h_main_plot,'update_axes'); set(hObject,'Value',0); feval(update_axes); % --- Executes when user attempts to close figure1. function figure1_CloseRequestFcn(hObject, eventdata, handles) % hObject handle to figure1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hint: delete(hObject) closes the figure delete(handles.vi); delete(hObject); % --- Executes on selection change in device. function device_Callback(hObject, eventdata, handles) % hObject handle to device (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: contents = cellstr(get(hObject,'String')) returns device contents as cell array % contents{get(hObject,'Value')} returns selected item from device %use TCP/IP in Matlab buffer = 1000 * 1024; visa_brand = 'ni'; delete(handles.vi); if get(hObject,'Value')==1 visa_address_rsa = 'TCPIP0::192.168.1.3::inst0::INSTR'; else visa_address_rsa = 'TCPIP0::192.168.1.5::inst0::INSTR'; end vi = visa(visa_brand, visa_address_rsa, 'InputBufferSize', buffer, ... 'OutputBufferSize', buffer); handles.vi=vi; set(vi,'InputBufferSize',1e6); set(vi,'Timeout',10); fopen(vi); %Read out / set initial settings set(handles.cent_freq,'String',num2str(str2num(query(handles.vi,['DPSA:FREQ:CENT?']))/1e6)); set(handles.span,'String',num2str(str2num(query(handles.vi,['DPSA:FREQ:SPAN?']))/1e6)); set(handles.start_freq,'String',num2str(str2num(query(handles.vi,['DPSA:FREQ:STAR?']))/1e6)); set(handles.stop_freq,'String',num2str(str2num(query(handles.vi,['DPSA:FREQ:STOP?']))/1e6)); set(handles.rbw,'String',num2str(str2num(query(handles.vi,['DPSA:band:act?']))/1e3)); set(handles.average_no,'String','1'); fprintf(handles.vi,'TRAC3:DPSA:AVER:COUN 1'); set(handles.point_no,'Value',4); fprintf(handles.vi,'DPSA:POIN:COUN P10401'); fclose(vi); % Update handles structure guidata(hObject, handles); % --- Executes during object creation, after setting all properties. function device_CreateFcn(hObject, eventdata, handles) % hObject handle to device (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 on button press in reinit. function reinit_Callback(hObject, eventdata, handles) % hObject handle to reinit (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 reinit %Placeholder, callback redefined in class.