commit old stuff from lab
This commit is contained in:
@@ -172,9 +172,9 @@ classdef Signal
|
||||
|
||||
hold on;
|
||||
if isempty(options.color)
|
||||
plot(t, sig(1:length(t)), 'DisplayName', dn, 'LineWidth', 0.1, 'Marker', '.', 'LineStyle','none', 'MarkerSize', 0.1);
|
||||
plot(t* 1e6, sig(1:length(t)), 'DisplayName', dn, 'LineWidth', 0.1, 'Marker', '.', 'LineStyle','none', 'MarkerSize', 0.1);
|
||||
else
|
||||
plot(t, sig(1:length(t)), 'DisplayName', dn, 'LineWidth', 0.1, 'Marker', '.', 'LineStyle','none', 'MarkerSize', 0.1,'Color',options.color);
|
||||
plot(t* 1e6, sig(1:length(t)), 'DisplayName', dn, 'LineWidth', 0.1, 'Marker', '.', 'LineStyle','none', 'MarkerSize', 0.1,'Color',options.color);
|
||||
end
|
||||
% 2 c)
|
||||
% - xlabel if not already here: time in readable format (1 ms and not 1e-3 s)
|
||||
@@ -187,10 +187,7 @@ classdef Signal
|
||||
ylabel('Amplitude');
|
||||
end
|
||||
|
||||
% Convert time axis to milliseconds for readability
|
||||
xticks = get(gca, 'XTick');
|
||||
set(gca, 'XTick', xticks, 'XTickLabel', xticks * 1e6);
|
||||
|
||||
|
||||
% Add legend if not already present
|
||||
if isempty(get(gca, 'Legend'))
|
||||
legend;
|
||||
@@ -656,7 +653,7 @@ classdef Signal
|
||||
end
|
||||
|
||||
%%
|
||||
function [obj,S,isFlipped,sequenceFound] = tsynch(obj,options)
|
||||
function [obj,S,inverted,sequenceFound,sequenceStarts] = tsynch(obj,options)
|
||||
% time sync and cut
|
||||
arguments
|
||||
obj Signal
|
||||
@@ -668,9 +665,9 @@ classdef Signal
|
||||
|
||||
|
||||
S = {};
|
||||
isFlipped=0;
|
||||
inverted = -1;
|
||||
sequenceFound = 0;
|
||||
|
||||
sequenceStarts = [];
|
||||
|
||||
|
||||
%normalize the signal
|
||||
@@ -696,8 +693,10 @@ classdef Signal
|
||||
return
|
||||
end
|
||||
|
||||
if mean(w) > 10 || mean(p) > 10
|
||||
if mean(w) > 10
|
||||
warning('No sync possible, check code of findpeaks! Look at correlation')
|
||||
return
|
||||
|
||||
else
|
||||
sequenceFound = 1;
|
||||
end
|
||||
@@ -711,19 +710,19 @@ classdef Signal
|
||||
|
||||
|
||||
shifts = lags(pkpos);
|
||||
|
||||
sequenceStarts = shifts;
|
||||
% shifts = shifts(shifts>=0);
|
||||
|
||||
if numel(shifts) > 0
|
||||
|
||||
%Cut occurences of ref signal from signal (only positive shifts)
|
||||
if all(sign(co(pkpos)))
|
||||
isFlipped = 1;
|
||||
if all(sign(co(pkpos))==-1)
|
||||
inverted = 1;
|
||||
end
|
||||
|
||||
for c = shifts
|
||||
sig = obj.delay(-c,'mode','samples');
|
||||
sig.signal = sig.signal(1:length(b)).*-isFlipped;
|
||||
sig.signal = sig.signal(1:length(b)) .* -inverted;
|
||||
S{end+1,1} = sig;
|
||||
end
|
||||
|
||||
|
||||
146
Classes/05_Lab/OptLaserN7714A.m
Normal file
146
Classes/05_Lab/OptLaserN7714A.m
Normal file
@@ -0,0 +1,146 @@
|
||||
classdef OptLaserN7714A < handle
|
||||
% Minimal controller for Keysight N7714A tunable laser over VISA-LAN
|
||||
% Methods: getLaserInfo, setPower, setWavelength
|
||||
%
|
||||
% Examples:
|
||||
% L = OptLaserN7714A('TCPIP::192.168.0.50::INSTR');
|
||||
% L.setWavelength(1550); % nm
|
||||
% L.setPower(-3.0, true); % dBm, also turns output ON
|
||||
% info = L.getLaserInfo();
|
||||
|
||||
properties (Access=private)
|
||||
v % visadev handle
|
||||
resource char % VISA resource string, e.g. 'TCPIP::...::INSTR'
|
||||
end
|
||||
|
||||
methods
|
||||
function obj = OptLaserN7714A(resource)
|
||||
arguments
|
||||
resource (1,:) char
|
||||
end
|
||||
obj.resource = resource;
|
||||
|
||||
% Robust connect with small retry loop
|
||||
maxRetries = 3; pauseTime = 1.0; lastErr = [];
|
||||
for k = 1:maxRetries
|
||||
try
|
||||
obj.v = visadev(obj.resource);
|
||||
% Identify instrument (SCPI *IDN?)
|
||||
writeline(obj.v, '*IDN?'); % SCPI common, identification
|
||||
idn = strtrim(readline(obj.v)); %#ok<NASGU>
|
||||
break
|
||||
catch ME
|
||||
lastErr = ME;
|
||||
pause(pauseTime);
|
||||
end
|
||||
end
|
||||
if isempty(obj.v) || ~isvalid(obj.v)
|
||||
error('OptLaserN7714A:ConnectFailed', ...
|
||||
'Could not connect to %s. Last error: %s', obj.resource, lastErr.message);
|
||||
end
|
||||
|
||||
% Set power unit to dBm for SOURce tree to be explicit (optional)
|
||||
% [:SOUR]:POWer:UNIT dBm (laser power unit)
|
||||
% Ref: SOURce:POWer:UNIT. :contentReference[oaicite:0]{index=0}
|
||||
try
|
||||
writeline(obj.v, 'SOUR:POW:UNIT DBM');
|
||||
catch
|
||||
% non-fatal
|
||||
end
|
||||
end
|
||||
|
||||
function delete(obj)
|
||||
if ~isempty(obj.v) && isvalid(obj.v); delete(obj.v); end
|
||||
end
|
||||
|
||||
function setPower(obj, power_dBm, outputOn, channel)
|
||||
arguments
|
||||
obj
|
||||
power_dBm (1,1) double
|
||||
outputOn (1,1) logical = true
|
||||
channel (1,1) double {mustBeMember(channel,0:4)} = 1
|
||||
end
|
||||
|
||||
v = obj.v;
|
||||
cmd = sprintf('SOUR%d:POW:LEV:IMM:AMPL %g DBM', channel, power_dBm);
|
||||
writeline(v, cmd);
|
||||
|
||||
if outputOn
|
||||
writeline(v, sprintf('SOUR%d:POW:STAT 1', channel)); %SOUR1:POW:STAT 0
|
||||
else
|
||||
writeline(v, sprintf('SOUR%d:POW:STAT 0', channel));
|
||||
end
|
||||
|
||||
writeline(v, '*OPC?');
|
||||
a=readline(v);
|
||||
end
|
||||
|
||||
function setWavelength(obj, wavelength_nm, channel)
|
||||
arguments
|
||||
obj
|
||||
wavelength_nm (1,1) double {mustBePositive}
|
||||
channel (1,1) double {mustBeMember(channel,0:4)} = 1
|
||||
end
|
||||
v = obj.v;
|
||||
cmd = sprintf('SOUR%d:WAV %gNM', channel, wavelength_nm);
|
||||
writeline(v, cmd);
|
||||
writeline(v, '*OPC?'); readline(v);
|
||||
end
|
||||
|
||||
function setDither(obj, enable, port)
|
||||
% Enable or disable laser frequency dither (stabilization).
|
||||
% enable = false → no dither (FIX), true → stabilization (STAB).
|
||||
% port = 1..4 (default 1).
|
||||
if nargin < 3
|
||||
port = 1;
|
||||
end
|
||||
|
||||
v = obj.v;
|
||||
if enable
|
||||
writeline(v, sprintf('SOUR%d:CONTrol:FCDither ON', port)); %[:SOURce[n]][:CHANnel[m]]:CONTrol:FCDither
|
||||
else
|
||||
writeline(v, sprintf('SOUR%d:CONTrol:FCDither OFF', port));
|
||||
end
|
||||
|
||||
% optional confirmation
|
||||
writeline(v, sprintf('SOUR%d:CONTrol:FCDither?', port));
|
||||
modeStr = strtrim(readline(v));
|
||||
fprintf('Port %d dither mode set to %s\n', port, modeStr);
|
||||
end
|
||||
|
||||
|
||||
|
||||
function info = getLaserInfo(obj, port)
|
||||
% Returns struct with IDN, output state, wavelength (nm), power (dBm)
|
||||
% port = 1..4 (for N7714A with 4 outputs). Default = 1.
|
||||
if nargin < 2
|
||||
port = 1;
|
||||
end
|
||||
|
||||
v = obj.v;
|
||||
|
||||
% *IDN?
|
||||
writeline(v, '*IDN?');
|
||||
idn = strtrim(readline(v));
|
||||
|
||||
% Output state: :SOURn:POW:STAT?
|
||||
writeline(v, sprintf('SOUR%d:POW:STAT?', port));
|
||||
out_state = str2double(readline(v)) ~= 0;
|
||||
|
||||
% Wavelength query (returns meters → convert to nm)
|
||||
writeline(v, sprintf('SOUR%d:WAV?', port));
|
||||
wav_m = str2double(readline(v));
|
||||
wav_nm = wav_m * 1e9;
|
||||
|
||||
% Power (set level) query (dBm)
|
||||
writeline(v, sprintf('SOUR%d:POW:LEV:IMM:AMPL?', port));
|
||||
p_dBm = str2double(readline(v));
|
||||
|
||||
info = struct('idn', idn, ...
|
||||
'output_on', out_state, ...
|
||||
'wavelength_nm', wav_nm, ...
|
||||
'power_dBm', p_dBm);
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user