This commit is contained in:
Silas
2025-02-20 05:45:23 +01:00
17 changed files with 319 additions and 161 deletions

View File

@@ -355,7 +355,7 @@ classdef Signal
end
if isempty(options.fft_length)
options.fft_length = 2^(nextpow2(length(obj.signal))-6);
options.fft_length = 2^(nextpow2(length(obj.signal))-9);
end
if options.normalizeToNyquist == 0
@@ -844,9 +844,9 @@ classdef Signal
mode = 1;
histpoints = 1024*2; %% verticale resolution
histpoints = 2048; %% verticale resolution
histpoints = floor(histpoints/2)*2+1; %% to have the eye digram centered around one point make the vertical resolution uneven
histpoints_horizontal = 512*2; %% horizontal resolution
histpoints_horizontal = 2048; %% horizontal resolution
hist_data=zeros(histpoints,histpoints_horizontal ); %% initilize eye diagram
if isa(obj,'Opticalsignal')
@@ -905,16 +905,22 @@ classdef Signal
hist_data(:,n)=flip(nn.'); %without flip, the eye is upside down :-(
end
ax = gca;
plot_data = 20*log10(hist_data);
plot_data(plot_data==-Inf) = 0;
imagesc(plot_data);
% beautify
colormap(cbrewer2("Blues",4096));
cm=flip(cbrewer2("RdYlBu",4096));
% cm=flip(cbrewer2("RdBu",4096));
cm(1,:) = [1,1,1];
cm(1,:) = [0,0,0];
colormap(cm);
% colormap('turbo');
ax.Colormap(1,:) = [1,1,1];
% ax.CLim = [0 50];
if isa(obj,'Opticalsignal')
title(['Optical Eye ',options.displayname])
ylabel("Power in mW");

View File

@@ -43,7 +43,7 @@ classdef PAMsource
options.mrds_blocklength = 512;
options.applypulseform = 1;
options.pulseformer Pulseformer;
options.pulseformer;
options.fs_out ;

View File

@@ -22,7 +22,7 @@ classdef AwgKeysight
% AWG.upload("Signal4",Signal);
properties(Access=protected)
properties(Access=public)
model awg_model
%fdac double
skews double
@@ -209,8 +209,7 @@ classdef AwgKeysight
% read/write lock file to our ntserver/scratch
try
obj.check_lock(char(obj.model),1);
obj.lock_device(char(obj.model));
obj.lock_device(char(obj.model));
catch
warning('Could not reach ntserver to write lock!')
end
@@ -221,9 +220,14 @@ classdef AwgKeysight
v = visadev('TCPIP0::zizou.tf.uni-kiel.de::hislip0::INSTR');
case awg_model.M8199B
v = visadev('TCPIP0::localhost::hislip0::INSTR');
case awg_model.M8199A_ILV
v = visadev('TCPIP0::Zizou::hislip0::INSTR');
case awg_model.M8199A_ILV
v = visadev('TCPIP0::Zizou::hislip0::INSTR');
end
debug = 0;
if debug
disp(['Connected to Instrument: ',char(v.Vendor),' ',char(v.Model),' SerNo:',char(v.SerialNumber)]);
end
@@ -233,16 +237,17 @@ classdef AwgKeysight
% aw=readline(v);
% assert(obj.numChannels==sscanf(aw, '%f'),['Wrong Channel config. AWG response: ',num2str(sscanf(aw, '%f')), ' Channels']);
switch obj.model
case awg_model.M8196A
obj.writeNcheck(v,':INST:DACM FOUR');
obj.writeNcheck(v,':ABORt');
obj.writeNcheck(v,sprintf(':FREQuency:RASTer %.15g;', obj.fdac));
if obj.model == awg_model.M8196A
case awg_model.M8199B
obj.writeNcheck(v,':ABORt ''M2''');
obj.writeNcheck(v,sprintf(':FREQ ''M1.ClkGen'', %.15g;', obj.fdac));
obj.writeNcheck(v,':INST:DACM FOUR');
obj.writeNcheck(v,':ABORt');
obj.writeNcheck(v,sprintf(':FREQuency:RASTer %.15g;', obj.fdac));
elseif obj.model == awg_model.M8199B || obj.model == awg_model.M8199A || obj.model == awg_model.M8199A_ILV
obj.writeNcheck(v,':ABORt ''M2''');
obj.writeNcheck(v,sprintf(':FREQ ''M1.ClkGen'', %.15g;', obj.fdac));
end
@@ -257,8 +262,7 @@ classdef AwgKeysight
if segm_len > 0
switch obj.model
case awg_model.M8196A
if obj.model == awg_model.M8196A
% 1) TRAC DEl - delete the previous waveform
obj.writeNcheck(v,sprintf(':TRACe%d:DELete %d', chan, segm_num));
@@ -278,7 +282,7 @@ classdef AwgKeysight
% 5) SET OUTPUTS ON/ OFF (generation not started at this point)
obj.writeNcheck(v, sprintf(':OUTPut%d ON', chan));
case awg_model.M8199B
elseif obj.model == awg_model.M8199B || obj.model == awg_model.M8199A || obj.model == awg_model.M8199A_ILV
% 1) TRAC DEl - delete the previous ch waveform
obj.writeNcheck(v,sprintf(':TRAC:DEL ''M2.DataOut%d'', %d', chan, segm_num));
@@ -308,8 +312,7 @@ classdef AwgKeysight
else
% If no signal defined, turn off channel
switch obj.model
case awg_model.M8199B
if obj.model == awg_model.M8199B || obj.model == awg_model.M8199A || obj.model == awg_model.M8199A_ILV
obj.writeNcheck(v, sprintf(':OUTP ''M2.DataOut%d'', OFF',chan));
end
@@ -318,12 +321,11 @@ classdef AwgKeysight
end
% Set global output on/ off to start generation
switch obj.model
case awg_model.M8196A
if obj.model==awg_model.M8196A
obj.writeNcheck(v,':INIT:IMMediate');
case awg_model.M8199B
elseif obj.model == awg_model.M8199B || obj.model == awg_model.M8199A || obj.model == awg_model.M8199A_ILV
% SET Ref clock out (which is conn. to scope) to 10 MHz
obj.writeNcheck(v, ':OUTPut:FREQuency ''M1.RefClkOut'',10000000');
@@ -331,7 +333,7 @@ classdef AwgKeysight
% :OUTP:GLOB 'M1.System', OFF
obj.writeNcheck(v, ':OUTP:GLOB ''M1.System'', ON');
obj.writeNcheck(v, ':OUTP:GLOB ''M2.System'', ON');
obj.writeNcheck(v,':INIT:IMMediate ''M2''');
%obj.writeNcheck(v,':INIT:IMMediate ''M2''');
end
% operation ceomplete (opc)

View File

@@ -8,7 +8,6 @@ classdef DC_supply < handle
properties(Access=public)
active
voltage
meas_voltage
meas_current
@@ -18,7 +17,6 @@ classdef DC_supply < handle
function obj = DC_supply(options)
arguments
options.active logical = true
options.voltage double = [0,0];
@@ -35,10 +33,14 @@ classdef DC_supply < handle
assert(size(obj.voltage,1)==1,'Set Voltage for CH1 and CH2 must be given as vector [V1, V2]');
assert(size(obj.voltage,2)==2,'Set Voltage for CH1 and CH2 must be given as vector [V1, V2]');
v = obj.connectDevice();
disp(['Connected to: ', char(v.Vendor),' ', char(v.Model),' :-)']);
end
function v = connectDevice(obj)
v = visadev("GPIB1::19::INSTR");
v = visadev("GPIB0::19::INSTR");
end
function success = set(obj,options)
@@ -51,15 +53,7 @@ classdef DC_supply < handle
success = [0,0];
% %connect to device
% if exist('v','var')
% %v = visadev("GPIB1::19::INSTR");
% v = obj.connectDevice();
% else
%
% end
v = visadev("GPIB1::19::INSTR");
v = obj.connectDevice();
debug = 0;
if debug
@@ -133,58 +127,55 @@ classdef DC_supply < handle
end
function [voltage,current] = readVals(obj)
try
%connect to device
v = visadev("GPIB1::19::INSTR");
debug = 0;
if debug
disp(['Connected to Instrument: ',char(v.Vendor),' ',char(v.Model),' SerNo:',char(v.SerialNumber)]);
end
%connect to device
v = obj.connectDevice;
cmd = 'INST:SEL?';
writeline(v, cmd);
prev_selected_channel = readline(v);
for ch = 1:2
% choose channel
cmd = ['INST:SEL OUT',num2str(ch)];
writeline(v, cmd);
% get current voltage level
cmd = 'VOLT?';
writeline(v, cmd);
voltage(ch) = str2num(readline(v));
% get current voltage level
cmd = 'MEAS:CURR?';
writeline(v, cmd);
current(ch) = str2num(readline(v));
end
% set channel back to prev. selected one
cmd = ['INST:SEL ',char(strtrim(prev_selected_channel))];
writeline(v, cmd);
obj.meas_voltage = voltage;
obj.meas_current = current;
%disconnect
delete(v);
catch
debug = 0;
if debug
disp(['Connected to Instrument: ',char(v.Vendor),' ',char(v.Model),' SerNo:',char(v.SerialNumber)]);
end
cmd = 'INST:SEL?';
writeline(v, cmd);
prev_selected_channel = readline(v);
for ch = 1:2
% choose channel
cmd = ['INST:SEL OUT',num2str(ch)];
writeline(v, cmd);
% get current voltage level
cmd = 'VOLT?';
writeline(v, cmd);
voltage(ch) = str2num(readline(v));
% get current voltage level
cmd = 'MEAS:CURR?';
writeline(v, cmd);
current(ch) = str2num(readline(v));
end
% set channel back to prev. selected one
cmd = ['INST:SEL ',char(strtrim(prev_selected_channel))];
writeline(v, cmd);
obj.meas_voltage = voltage;
obj.meas_current = current;
%disconnect
delete(v);
end
end
end

View File

@@ -1,7 +1,8 @@
classdef Exfo_laser < handle
properties(Access=private)
serialport_number
connection_id
lab_interface
mainframe_channel
end
properties(Access=public)
@@ -15,11 +16,11 @@ classdef Exfo_laser < handle
function obj = Exfo_laser(options)
arguments
options.safety_mode = 1;
options.serialport_number = 'COM8';
options.mainframe_channel = 1;
options.safety_mode = 1;
options.lab_interface lab_interface = lab_interface.gbib;
options.connection_id = '8';
options.mainframe_channel = 1;
end
%
@@ -30,29 +31,19 @@ classdef Exfo_laser < handle
end
end
v = obj.connectLaser_();
% Connect to the laser
o = serialport(obj.serialport_number, 9600);
configureTerminator(o, "CR", "CR"); % Set the terminator to carriage return (CR)
flush(o);
writeline(o, "*IDN?");
answ = readline(o);
if obj.safety_mode
disp(['Yay! We can talk to Instrument: ',char(answ)]);
end
% Read states the first time
obj.cur_state = obj.getLaserStatus_(o,obj.mainframe_channel);
obj.cur_wavelength = obj.getLaserWavelength_(o,obj.mainframe_channel);
obj.cur_power = obj.getLaserPower_(o,obj.mainframe_channel);
obj.cur_state = obj.getLaserStatus_(v,obj.mainframe_channel);
obj.cur_wavelength = obj.getLaserWavelength_(v,obj.mainframe_channel);
obj.cur_power = obj.getLaserPower_(v,obj.mainframe_channel);
clear o;
clear v;
if obj.safety_mode
warning("Safety_mode ON: Display all information. Ask when switching laser. Turn safety_mode off in class instance or during initialization Exfo_laser(...,'safety_mode',0)");
else
warning("safety_mode OFF: EVERYTHING IS EXECUTED WITHOUT ASKING :-) BE SURE WHAT YOU DO");
disp("safety_mode OFF: EVERYTHING IS EXECUTED WITHOUT ASKING :-) BE SURE WHAT YOU DO");
end
end
@@ -171,20 +162,34 @@ classdef Exfo_laser < handle
% Abort the operation
disp('Operation aborted. Laser remains at wavelength.');
end
end
end %public mehtods
methods (Access=private)
function serialobj = connectLaser_(obj)
function v = connectLaser_(obj)
% Connect to the laser
serialobj = serialport(obj.serialport_number, 9600);
configureTerminator(serialobj, "CR", "CR"); % Set the terminator to carriage return (CR)
flush(serialobj);
writeline(serialobj, "*IDN?");
answ = readline(serialobj);
if obj.lab_interface == lab_interface.serial
% Connect to the laser via SERIAL (USB)
v = serialport(obj.connection_id, 9600);
configureTerminator(v, "CR", "CR"); % Set the terminator to carriage return (CR)
elseif obj.lab_interface == lab_interface.gpib
% Connect via GPIB adress
visastring = ['GPIB0::',obj.connection_id,'::INSTR'];
v = visadev(visastring);
else
error('Interface not supported');
end
if obj.safety_mode
flush(v);
writeline(v, "*IDN?");
answ = readline(v);
disp(['Yay! We can talk to Instrument: ',char(answ)]);
end
end
@@ -192,12 +197,16 @@ classdef Exfo_laser < handle
% Function to GET the STATE of the laser
function isEnabled = getLaserStatus_(obj,serialObj, channel)
writeline(serialObj, ['CH', num2str(channel), ':ENABLE?']); % Query current wavelength
writeline(serialObj, ['CH', num2str(channel), ':ENABLE?']); % Query current wavelength
manual_flush = 1;
while manual_flush
if serialObj.Type == visalib.InterfaceType.serial
manual_flush = 1;
while manual_flush
response = readline(serialObj);
manual_flush = contains(response, {'OK'});
end
else
response = readline(serialObj);
manual_flush = contains(response, {'OK'});
end
isEnabled = 0;
@@ -211,14 +220,14 @@ classdef Exfo_laser < handle
elseif ~isEnabled && isDisabled
obj.cur_state = isEnabled;
else
error(['Unknown Laser State ->', char(response)]);
error(['Quantum Laser State; your laser is ON and OFF ->', char(response)]);
end
if obj.safety_mode
if isEnabled
disp(['Laser ', num2str(channel) ,' is currently ON -> ', char(response)]);
elseif isDisabled
disp(['Laser ', num2str(channel) ,' is currently OFF ->', char(response)]);
disp(['Laser ', num2str(channel) ,' is currently OFF -> ', char(response)]);
else
error(['Unknown Laser State ->', char(response)]);
end
@@ -269,8 +278,11 @@ classdef Exfo_laser < handle
isEnabled = obj.getLaserStatus_(serialObj,obj.mainframe_channel);
writeline(serialObj, ['CH',num2str(channel),':ENABLE']);
response = readline(serialObj);
isok = contains(response, {'OK'});
if serialObj.Type == visalib.InterfaceType.serial
response = readline(serialObj);
isok = contains(response, {'OK'});
end
cnt=0;
while ~isEnabled || cnt>10
@@ -292,25 +304,30 @@ classdef Exfo_laser < handle
isEnabled = obj.getLaserStatus_(serialObj,obj.mainframe_channel);
writeline(serialObj, ['CH',num2str(channel),':DISABLE']);
response = readline(serialObj);
isok = contains(response, {'OK'});
if serialObj.Type == visalib.InterfaceType.serial
response = readline(serialObj);
isok = contains(response, {'OK'});
end
cnt=0;
while isEnabled || cnt>10
isEnabled = obj.getLaserStatus_(serialObj,obj.mainframe_channel);
pause(0.2);
pause(0.5);
cnt = cnt+1;
end
if isEnabled
error('Laser not enabled but command was send')
else
success = 1;
if serialObj.Type == visalib.InterfaceType.serial
if isEnabled
error('Laser not enabled but command was send')
else
success = 1;
end
end
end
% Function to SET the wavelength of the laser
function success = setLaserWavelength_(~,serialObj, channel, desiredWavelength_nm)
function success = setLaserWavelength_(obj,serialObj, channel, desiredWavelength_nm)
success = 0;
writeline(serialObj, ['CH',num2str(channel),':NM?']);
@@ -325,15 +342,18 @@ classdef Exfo_laser < handle
command = ['CH', num2str(channel), ':L=', num2str(desiredWavelength_nm)];
writeline(serialObj, command);
pause(0.2);
response = readline(serialObj);
success = contains(response, 'OK');
if serialObj.Type == visalib.InterfaceType.serial
pause(0.2);
response = readline(serialObj);
success = contains(response, 'OK');
end
success = desiredWavelength_nm == obj.getLaserWavelength_(serialObj, channel);
end
% Function to SET the laser power
function success = setLaserPower_(~,serialObj, channel, desiredPower_dBm)
function success = setLaserPower_(obj,serialObj, channel, desiredPower_dBm)
success = 0;
writeline(serialObj, ['CH',num2str(channel),':MW?']);
@@ -348,11 +368,13 @@ classdef Exfo_laser < handle
command = ['CH', num2str(channel), ':P=', num2str(desiredPower_dBm)];
writeline(serialObj, command);
pause(0.2);
response = readline(serialObj);
success = contains(response, 'OK');
if serialObj.Type == visalib.InterfaceType.serial
pause(0.2);
response = readline(serialObj);
success = contains(response, 'OK');
end
success = desiredPower_dBm == obj.getLaserPower_(serialObj, channel);
end
end

View File

@@ -53,11 +53,8 @@ classdef OptAtten < handle
try
%connect to device
v = visadev('TCPIP::134.245.243.248::INSTR');
debug = 0;
if debug
disp(['Connected to Instrument: ',char(v.Vendor),' ',char(v.Model),' SerNo:',char(v.SerialNumber)]);
@@ -279,6 +276,10 @@ classdef OptAtten < handle
cnt = cnt+1;
end
fprintf("\n SET: CH1 %.2f dB | CH2: %.2f dB | CH3: %.2f dB | CH4: %.2f dB\n",obj.value_state(1), obj.value_state(2), obj.value_state(3), obj.value_state(4));
fprintf(" ATT: CH1 %.2f dB | CH2: %.2f dB | CH3: %.2f dB | CH4: %.2f dB\n",obj.atten_state(1), obj.atten_state(2), obj.atten_state(3), obj.atten_state(4));
fprintf(" POW: CH1 %.2f dBm | CH2: %.2f dBm | CH3: %.2f dBm | CH4: %.2f dBm \n \n",obj.power_state(1), obj.power_state(2), obj.power_state(3), obj.power_state(4));
delete(v);
catch error
@@ -292,7 +293,12 @@ classdef OptAtten < handle
end
end
function [p1,p2,p3,p4]=readPower(obj)
function [p1,p2,p3,p4]=readPower(obj, options)
arguments
obj
options.silent = 0
end
v = visadev('TCPIP::134.245.243.248::INSTR');
cnt = 1;
@@ -309,6 +315,9 @@ classdef OptAtten < handle
p3 = obj.power_state(3);
p4 = obj.power_state(4);
if options.silent == 0
fprintf("\n CH1: %.2f dB | CH2: %.2f dB | CH3: %.2f dB | CH4: %.2f dB\n \n",p1, p2, p3, p4);
end
end
end

View File

@@ -43,13 +43,6 @@ classdef ScopeKeysight
end
end
switch obj.model
case scope_model.DSAZ634A
case scope_model.UXR1102A
end
end
@@ -68,7 +61,7 @@ classdef ScopeKeysight
if isempty(obj.IPaddress)
switch obj.model
case scope_model.DSAZ634A
v=visadev('TCPIP0::keysight.tf.uni-kiel.de::inst0::INSTR');% TCPIP0::127.0.0.1::inst0::INSTR
v=visadev('TCPIP0::134.245.243.195::inst0::INSTR');% TCPIP0::127.0.0.1::inst0::INSTR
case scope_model.UXR1102A
v=visadev('TCPIP0::testscope.tf.uni-kiel.de::inst0::INSTR');% TCPIP0::127.0.0.1::inst0::INSTR
case scope_model.UXR1104B