ChannelFreqResp optimized and compared to move-it

minimal lab setup
This commit is contained in:
Silas Labor Zizou
2024-10-07 08:19:56 +02:00
parent 8577f5f6f4
commit 135d0e7cfc
16 changed files with 369 additions and 146 deletions

View File

@@ -203,6 +203,8 @@ classdef AwgKeysight
v = visadev('TCPIP0::localhost::hislip0::INSTR');
end
disp(['Connected to Instrument: ',char(v.Vendor),' ',char(v.Model),' SerNo:',char(v.SerialNumber)]);
%check if channel config matches
writeline(v,'*opt?');
aw=readline(v);

View File

@@ -47,8 +47,7 @@ classdef DC_supply
%connect to device
v = visadev("GPIB1::19::INSTR");
writeline(v, '*IDN?;');
disp(['DC Source: ' readline(v)]);
disp(['Connected to Instrument: ',char(v.Vendor),' ',char(v.Model),' SerNo:',char(v.SerialNumber)]);
cmd = 'INST:SEL?';
writeline(v, cmd);
@@ -109,13 +108,14 @@ classdef DC_supply
end
% choose channel
cmd = ['INST:SEL ',prev_selected_channel];
cmd = ['INST:SEL ',char(strtrim(prev_selected_channel))];
writeline(v, cmd);
%disconnect
delete(v);
catch
end
end
end

View File

@@ -1,4 +1,4 @@
classdef OptAtten
classdef OptAtten < handle
% control optical attenuator Keysight N7764a via LAN
% set parameters of optical attenuator, e.g. attenuation, wavelength, etc. and read out output power from attenuator
@@ -10,6 +10,14 @@ classdef OptAtten
avgTime %'Enter a desired averaging time [ms]. Higher averaging times will increase stability of the readings but will slow down measurement speed. Range: [2, 1000]';
dbOffset %'A non-zero attenuation offset shifts the logarithmic attenuation scale. Then, the set attenuation value differs from the internally calibrated attenuation. Range [-200, 200]';
psetOffset %'A non-zero power offset shifts the logarithnic power scale. Then, the power reading and the set power (Pset) values differ from the internal power calibration. Range [-60, 60]';
atten_state
value_state
power_state
speed_state
wavelength_state
end
methods (Access=public)
@@ -34,6 +42,7 @@ classdef OptAtten
end
function success = set(obj,options)
arguments
@@ -46,47 +55,47 @@ classdef OptAtten
%connect to device
v = visadev('TCPIP::134.245.243.248::INSTR');
writeline(v, '*IDN?;');
disp(['Active atten: ' readline(v)]); %Keysight Technologies, N7764A, MY49A00696, 1.13.1
disp(['Connected to Instrument: ',char(v.Vendor),' ',char(v.Model),' SerNo:',char(v.SerialNumber)]);
%Keysight Technologies, N7764A, MY49A00696, 1.13.1
slot = 0; %init slot number
%loop to set values for every attenuator slot
for i = 1:length(obj.active)
for i = 1:length(options.active)
%convert index number i into slot number
slot = 2*i - 1;
%check whether attenuator is used or unused
if ~obj.active(i) %atten slot unused
if ~options.active(i) %atten slot unused
writeline(v, [':OUTP' num2str(slot) ':STAT OFF']);
else %atten slot used (attenuation/const output power)
%set attenuation or output power
if obj.active(i) == 1 %attenuation
if obj.value(i) < 0
obj.value(i) = 0;
hMsgBox = msgbox(['Value for attenuation out of range. Please consider minimum value. Attenuation set to ' num2str(obj.value(i)) 'dB']);
if options.active(i) == 1 %attenuation
if options.value(i) < 0
options.value(i) = 0;
hMsgBox = msgbox(['Value for attenuation out of range. Please consider minimum value. Attenuation set to ' num2str(options.value(i)) 'dB']);
uiwait(hMsgBox);
elseif obj.value(i) > 45
obj.value(i) = 45;
hMsgBox = msgbox(['Value for attenuation out of range. Please consider maximum value. Attenuation set to ' num2str(obj.value(i)) 'dB']);
elseif options.value(i) > 45
options.value(i) = 45;
hMsgBox = msgbox(['Value for attenuation out of range. Please consider maximum value. Attenuation set to ' num2str(options.value(i)) 'dB']);
uiwait(hMsgBox);
end
writeline(v, [':OUTP' num2str(slot) ':POW:CONTR OFF']);
writeline(v, [':INP' num2str(slot) ':ATT ' num2str(obj.value(i)) 'dB']);
elseif obj.active(i) == 2 %constant output power
if obj.value(i) < -50
obj.value(i) = -50;
hMsgBox = msgbox(['Value for output power out of range. Please consider minimum value. Output power set to ' num2str(obj.value(i)) 'dBm']);
writeline(v, [':INP' num2str(slot) ':ATT ' num2str(options.value(i)) 'dB']);
elseif options.active(i) == 2 %constant output power
if options.value(i) < -50
options.value(i) = -50;
hMsgBox = msgbox(['Value for output power out of range. Please consider minimum value. Output power set to ' num2str(options.value(i)) 'dBm']);
uiwait(hMsgBox);
elseif obj.value(i) > 20
obj.value(i) = 20;
hMsgBox = msgbox(['Value for output power out of range. Please consider maximum value. Output set to ' num2str(obj.value(i)) 'dBm']);
elseif options.value(i) > 20
options.value(i) = 20;
hMsgBox = msgbox(['Value for output power out of range. Please consider maximum value. Output set to ' num2str(options.value(i)) 'dBm']);
uiwait(hMsgBox);
end
writeline(v, [':OUTP' num2str(slot) ':POW:CONTR ON']);
writeline(v, [':OUTP' num2str(slot) ':POW ' num2str(obj.value(i))]);
writeline(v, [':OUTP' num2str(slot) ':POW ' num2str(options.value(i))]);
end
%set value for speed
@@ -160,8 +169,8 @@ classdef OptAtten
pause(2);
%read output power from attenuator and save to state.ouputpower
for i = 1:length(obj.active)
if obj.active(i)
for i = 1:length(options.active)
if options.active(i)
%convert index number i into slot number
slot = 2*i - 1;
@@ -174,11 +183,11 @@ classdef OptAtten
%create warning message when measured output power differs from
%set output power by 2dB.
for i = 1:length(obj.active)
if obj.active(i) == 2
for i = 1:length(options.active)
if options.active(i) == 2
%determine absolute difference
differ = abs(state.outputpower(i)-obj.value(i));
differ = abs(state.outputpower(i)-options.value(i));
%create msgbox when necessary
if differ >= 2
hMsgBox = msgbox(['Output Power at attenuator slot ' num2str(2) ' differs by 2dB or more!']);
@@ -188,22 +197,27 @@ classdef OptAtten
end
%create output
for i = 1:length(obj.active)
if obj.active(i) == 2
% Output power mode:
%differ = abs(state.outputpower(i)-obj.value(i));
ch_info_txt = ['OptAtten: ',num2str(i),' -> Desired: ',num2str(obj.value(i)),' dBm; Cur Output: ',num2str(state.outputpower(i)),'dBm'];
disp(ch_info_txt);
else
ch_info_txt = ['OptAtten: ',num2str(i),' -> Attenuated by: ',num2str(obj.value(i)),' dB; Cur Output: ',num2str(state.outputpower(i)),'dBm'];
disp(ch_info_txt);
silent = 0;
if silent
for i = 1:length(options.active)
if options.active(i) == 2
% Output power mode:
%differ = abs(state.outputpower(i)-options.value(i));
ch_info_txt = ['OptAtten: ',num2str(i),' -> Desired: ',num2str(options.value(i)),' dBm; Cur Output: ',num2str(state.outputpower(i)),'dBm'];
disp(ch_info_txt);
else
ch_info_txt = ['OptAtten: ',num2str(i),' -> Attenuated by: ',num2str(options.value(i)),' dB; Cur Output: ',num2str(state.outputpower(i)),'dBm'];
disp(ch_info_txt);
end
end
end
%disconnect
delete(v);
obj.readvals();
catch error
%disconnect if error occurrs
@@ -216,57 +230,51 @@ classdef OptAtten
end
function readvals(obj)
function readvals(obj,options)
arguments
obj
options.print2console = 0;
end
try
%connect to device
v = visadev('TCPIP::134.245.243.248::INSTR');
writeline(v, '*IDN?;');
disp(['Active atten: ' readline(v)]); %Keysight Technologies, N7764A, MY49A00696, 1.13.1
power=[];
cnt = 1;
for s = 1:2:7
writeline(v, [':OUTP' num2str(s) ':STAT?']);
line = readline(v);
answer = sscanf(line,'%f');
disp(['Slot ' num2str(s) ' enabled state: ' num2str(answer)]);
writeline(v, [':OUTP' num2str(s) ':POW?']);
line = readline(v);
answer = sscanf(line,'%f');
disp(['P_set (output power) for Slot ' num2str(s) ': ' num2str(answer) ' dBm']);
obj.value_state(cnt) = answer;
writeline(v, [':OUTP' num2str(s) ':POW:CONTR?']);
writeline(v, [':READ' num2str(s) ':POW?']);
line = readline(v);
answer = sscanf(line,'%f');
disp(['Power control for Slot ' num2str(s) ': ' num2str(answer)]);
obj.power_state(cnt) = answer;
if answer == 1
writeline(v, [':READ' num2str(s) ':POW?']);
line = readline(v);
answer = sscanf(line,'%f');
disp([' -> Slot ' num2str(s) ' desired outut power: ' num2str(answer) ' dBm']);
else
writeline(v, [':INP' num2str(s) ':ATT?']);
line = readline(v);
answer = sscanf(line,'%f');
disp([' -> Alpha (fix attenuation) for slot ' num2str(s) ': ' num2str(answer) ' dB']);
end
writeline(v, [':READ' num2str(s) ':POW?']);
line = readline(v);
answer = sscanf(line,'%f');
obj.power_state(cnt) = answer;
writeline(v, [':INP' num2str(s) ':ATT?']);
line = readline(v);
answer = sscanf(line,'%f');
obj.atten_state(cnt) = answer;
writeline(v, [':INP' num2str(s) ':WAV?']);
line = readline(v);
answer = sscanf(line,'%f');
disp(['Wavelength for Slot ' num2str(s) ': ' num2str(answer) ' nm']);
obj.wavelength_state(cnt) = answer;
writeline(v, [':OUTP' num2str(s) ':ATIM?']);
writeline(v, [':INP' num2str(s) ':WAV?']);
line = readline(v);
answer = sscanf(line,'%f');
disp(['Averaging time for Slot ' num2str(s) ': ' num2str(answer) ' s']);
fprintf('\n')
obj.speed_state(cnt) = answer;
cnt = cnt+1;
end
delete(v);
@@ -281,7 +289,7 @@ classdef OptAtten
end
end
end
end

View File

@@ -8,6 +8,7 @@ classdef ScopeKeysight
channel
autoScale
extRef
removeDC
interpolate
recordLen
IPaddress
@@ -25,6 +26,7 @@ classdef ScopeKeysight
options.channel logical = [0,0,0,0];
options.autoScale logical = 0;
options.extRef logical = 1;
options.removeDC logical = 1;
options.interpolate logical = 0;
options.recordLen double = 1000000;
options.IPaddress
@@ -169,11 +171,21 @@ classdef ScopeKeysight
recordedSignals = cell(size(obj.channel));
for n = find(obj.channel == 1)
% record
recordedSignals{n} = obj.readChannel(v,n);
% cut "safety samples" that were added at the end
recordedSignals{n} = recordedSignals{n}(1:obj.recordLen);
if obj.removeDC
recordedSignals{n} = recordedSignals{n}-mean(recordedSignals{n});
end
obj.writeNcheck(v,sprintf(':CHANnel%u:DISPlay ON',n));
end
% fill all other channels with nothing
for n = find(obj.channel == 0)
recordedSignals{n} = [];
end
@@ -181,6 +193,16 @@ classdef ScopeKeysight
obj.writeNcheck(v,sprintf(':%s',scope_state));
obj.writeNcheck(v,'*OPC?');
opdone = 0;
acqdone = 0;
procdone = 0;
while ~opdone || ~acqdone || ~procdone
opdone = sscanf(obj.writeReceiveCheck(v,'*opc?'), '%f');
acqdone = sscanf(obj.writeReceiveCheck(v,'ader?'), '%f');
procdone = sscanf(obj.writeReceiveCheck(v,'pder?'), '%f');
pause(0.005);
end
end
end