Lab changes
This commit is contained in:
@@ -6,6 +6,10 @@ classdef Signal
|
||||
signal
|
||||
logbook
|
||||
fs
|
||||
|
||||
gitSHA
|
||||
gitStatus
|
||||
gitPatch
|
||||
end
|
||||
|
||||
methods
|
||||
@@ -17,18 +21,26 @@ classdef Signal
|
||||
options.fs = [];
|
||||
end
|
||||
|
||||
obj.signal = signal;
|
||||
obj.signal = obj.signal;
|
||||
obj.fs = options.fs;
|
||||
|
||||
obj.signal = signal;
|
||||
obj.signal = obj.signal;
|
||||
obj.fs = options.fs;
|
||||
|
||||
[~,obj.gitSHA] = system('git rev-parse HEAD');
|
||||
[~,obj.gitStatus] = system('git status --porcelain');
|
||||
[~,obj.gitPatch] = system('git diff');
|
||||
|
||||
%%% Stuff for Logbook %%%
|
||||
SignalType = [];
|
||||
TimeStamp = [];
|
||||
Length = [];
|
||||
SignalPower = [];
|
||||
Nase = [];
|
||||
SignalCopy = [];
|
||||
ModifierName = [];
|
||||
ModifierCopy= {};
|
||||
Description = [];
|
||||
|
||||
obj.logbook = table(SignalType,TimeStamp,Length,SignalPower,Nase,Description);
|
||||
obj.logbook = table(SignalType,TimeStamp,Length,SignalPower,Nase,SignalCopy,ModifierName, ModifierCopy, Description);
|
||||
|
||||
|
||||
end
|
||||
@@ -131,9 +143,13 @@ classdef Signal
|
||||
options.fignum
|
||||
options.displayname = [];
|
||||
options.timeframe = 0;
|
||||
options.clear = 0;
|
||||
end
|
||||
|
||||
figure(options.fignum); % If figure does not exist, create new figure
|
||||
if options.clear
|
||||
clf
|
||||
end
|
||||
|
||||
% 2) Plot into the figure handle found or created in one
|
||||
t = (0:length(obj.signal)-1) / obj.fs; % time vector
|
||||
@@ -227,24 +243,58 @@ classdef Signal
|
||||
%% Write Logbook Entry
|
||||
function obj = logbookentry(obj,varargin)
|
||||
|
||||
if nargin > 1
|
||||
if nargin == 2
|
||||
Description = varargin{1};
|
||||
CallingModifier = evalin('caller','obj');
|
||||
elseif nargin == 3
|
||||
Description = varargin{1};
|
||||
CallingModifier = varargin{2};
|
||||
else
|
||||
Description = "";
|
||||
CallingModifier = evalin('caller','obj');
|
||||
end
|
||||
|
||||
CallingModifierStruct = obj.objToStructFilteredRecursive(CallingModifier);
|
||||
|
||||
SignalType = [string(class(obj))];
|
||||
TimeStamp = [(datetime('now','TimeZone','local','Format','HH:mm:ss'))];
|
||||
Length = num2str(obj.length, ['%' sprintf('.%df', 0)]);%[obj.length];
|
||||
SignalPower = [obj.power];
|
||||
Nase = [0];
|
||||
SignalCopy = obj.signal;
|
||||
ModifierName = class(CallingModifier);
|
||||
ModifierCopy = {CallingModifierStruct};
|
||||
|
||||
cell = {SignalType , TimeStamp , Length , SignalPower(1) , Nase, Description};
|
||||
cell = {SignalType , TimeStamp , Length , SignalPower(1) , Nase, SignalCopy, ModifierName, ModifierCopy, Description};
|
||||
|
||||
obj.logbook = [obj.logbook;cell];
|
||||
obj.logbook = [obj.logbook; cell];
|
||||
|
||||
end
|
||||
|
||||
function s = objToStructFilteredRecursive(~,obj)
|
||||
% Convert the object to a structure using 'struct' and catch warnings
|
||||
warnState = warning('off', 'MATLAB:structOnObject');
|
||||
s = struct(obj); % Convert to struct
|
||||
warning(warnState); % Restore previous warning state
|
||||
|
||||
% Get all field names of the struct
|
||||
fields = fieldnames(s);
|
||||
|
||||
% Loop over each field and handle filtering
|
||||
for i = 1:numel(fields)
|
||||
fieldData = s.(fields{i});
|
||||
|
||||
if isstruct(fieldData) % If the field is a struct, call recursively
|
||||
s.(fields{i}) = obj.objToStructFilteredRecursive(fieldData);
|
||||
elseif numel(fieldData) > 1000 % Remove field if it has more than 1000 elements
|
||||
%s = rmfield(s, fields{i});
|
||||
s.(fields{i}) = [];
|
||||
elseif isa(fieldData,'table')
|
||||
s = rmfield(s, fields{i});
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
%% Resample Signal
|
||||
function obj = resample(obj,options)
|
||||
|
||||
@@ -260,13 +310,23 @@ classdef Signal
|
||||
warning('The signals fs is different from the given fs_in while it should be the same.');
|
||||
end
|
||||
|
||||
obj.signal = resample(obj.signal,options.fs_out,options.fs_in,options.n,options.beta);
|
||||
if options.fs_in == options.fs_out
|
||||
|
||||
desc = ['resample signal from ', num2str(options.fs_in*1e-9), ' GHz to ', num2str(options.fs_out*1e-9), ' GHz' ];
|
||||
desc = ['No need to resample signal from ', num2str(options.fs_in*1e-9), ' GHz to ', num2str(options.fs_out*1e-9), ' GHz' ];
|
||||
|
||||
obj = obj.logbookentry(desc,obj);
|
||||
|
||||
obj = obj.logbookentry(desc);
|
||||
else
|
||||
|
||||
obj.fs = options.fs_out;
|
||||
obj.signal = resample(obj.signal,options.fs_out,options.fs_in,options.n,options.beta);
|
||||
|
||||
desc = ['resample signal from ', num2str(options.fs_in*1e-9), ' GHz to ', num2str(options.fs_out*1e-9), ' GHz' ];
|
||||
|
||||
obj = obj.logbookentry(desc,obj);
|
||||
|
||||
obj.fs = options.fs_out;
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -284,7 +344,7 @@ classdef Signal
|
||||
N = 2^(nextpow2(length(obj.signal))-8);
|
||||
|
||||
[p_lin,w] = pwelch(obj.signal,hanning(N),N/2,N,obj.fs,"centered","power","mean");
|
||||
normalize = 1;
|
||||
normalize = 0;
|
||||
if normalize
|
||||
p_lin = p_lin./ max(p_lin);
|
||||
p_dbm = 10*log10(p_lin); %dB to dBm in case of "power"
|
||||
@@ -295,6 +355,7 @@ classdef Signal
|
||||
end
|
||||
|
||||
figure(options.fignum); % If figure does not exist, create new figure
|
||||
ax = gca;
|
||||
hold on
|
||||
plot(w.*1e-9,p_dbm,'DisplayName',options.displayname,'LineWidth',1);
|
||||
xlabel("Frequency in GHz");
|
||||
@@ -304,11 +365,11 @@ classdef Signal
|
||||
edgetick = 2^(nextpow2(obj.fs*1e-9));
|
||||
% xticks([-edgetick:16:edgetick]);
|
||||
xlim([100*round( min(w.*1e-9)/100,1)-10,100*round( max(w.*1e-9)/100,1)+10])
|
||||
ylim([100*round( min(p_dbm)/100,1)-3,100*round( max(p_dbm)/100,1)+3]);
|
||||
ylim([min(floor( min(p_dbm))-3 , ax.YLim(1)), max(ceil( max(p_dbm) )+(3), ax.YLim(2))]);
|
||||
yticks([-200:10:10]);
|
||||
grid on
|
||||
grid minor
|
||||
legend
|
||||
legend('Interpreter','none');
|
||||
|
||||
end
|
||||
|
||||
@@ -451,13 +512,21 @@ classdef Signal
|
||||
[pks,pkpos] = findpeaks(co./max(co),'MinPeakDistance',length(b)/2,'MinPeakHeight',0.2,'NPeaks',maxpeaknum);
|
||||
shifts = lags(pkpos);
|
||||
|
||||
%Cut occurences of ref signal from signal
|
||||
%Cut occurences of ref signal from signal (only positive shifts)
|
||||
S = {};
|
||||
for c = shifts
|
||||
for c = shifts(shifts>0)
|
||||
sig = obj.delay(-c,'mode','samples');
|
||||
sig.signal = sig.signal(1:length(b));
|
||||
S{end+1,1} = sig;
|
||||
end
|
||||
|
||||
%return/keep the sinal with the highest correlation (only within positive shifts)
|
||||
[~,idx]=max(pks(shifts>0));
|
||||
obj.signal = S{idx}.signal;
|
||||
|
||||
for c = 1:numel(shifts(shifts>0))
|
||||
S{c}.logbook = [];
|
||||
end
|
||||
|
||||
%plot all synced signals and the ref signal
|
||||
debug = 0;
|
||||
@@ -469,14 +538,16 @@ classdef Signal
|
||||
end
|
||||
end
|
||||
|
||||
%return the sinal with the highest correlation...
|
||||
[~,idx]=max(pks);
|
||||
obj.signal = S{idx}.signal;
|
||||
|
||||
|
||||
|
||||
end
|
||||
|
||||
function obj = filter(obj,a,b)
|
||||
|
||||
lbdesc = ['Filtering signal with H = a: ',num2str(a),' / b: ',num2str(b)];
|
||||
obj = obj.logbookentry(lbdesc,obj);
|
||||
|
||||
obj.signal = filter(a,b,obj.signal);
|
||||
end
|
||||
|
||||
@@ -560,7 +631,15 @@ classdef Signal
|
||||
|
||||
end
|
||||
|
||||
function eye(obj,fsym,M)
|
||||
function eye(obj,fsym,M,options)
|
||||
|
||||
arguments
|
||||
obj
|
||||
fsym
|
||||
M
|
||||
options.fignum = 100;
|
||||
options.displayname = "";
|
||||
end
|
||||
|
||||
mode = 1;
|
||||
|
||||
@@ -587,7 +666,7 @@ classdef Signal
|
||||
|
||||
eye_mat = reshape(x(1:end-mod(length(x),histpoints_horizontal)),histpoints_horizontal,floor(length(x)/histpoints_horizontal)); %% reshape signal into 256 rows each row has the histogram(eye data of all symbols)
|
||||
|
||||
figure(922)
|
||||
figure(options.fignum)
|
||||
clf
|
||||
if mode == 2
|
||||
% generate "intuitive eye diagram" by drawing lines on top over
|
||||
@@ -633,19 +712,19 @@ classdef Signal
|
||||
colormap(cbrewer2("Blues",4096));
|
||||
|
||||
if isa(obj,'Opticalsignal')
|
||||
title("Optical Eye")
|
||||
title(['Optical Eye ',options.displayname])
|
||||
ylabel("Power in mW");
|
||||
y_tickstring = string(linspace(maxA.*1e3,minA.*1e3,16));
|
||||
min_ = min(abs(obj.signal(100:end-100)).^2);
|
||||
max_ = abs(max(obj.signal(100:end-100)).^2);
|
||||
elseif isa(obj,'Electricalsignal')
|
||||
title("Electrical Eye")
|
||||
title(['Electrical Eye ',options.displayname])
|
||||
ylabel("Voltage in V");
|
||||
y_tickstring = string(linspace(maxA,minA,16));
|
||||
min_ = min(obj.signal(100:end-100));
|
||||
max_ = abs(max(obj.signal(100:end-100)));
|
||||
else
|
||||
title("Digital Eye")
|
||||
title(['Digital Eye ',options.displayname])
|
||||
ylabel("Digital Signal Amplitude");
|
||||
y_tickstring = string(linspace(maxA,minA,16));
|
||||
min_ = min(obj.signal(100:end-100));
|
||||
|
||||
Reference in New Issue
Block a user