Update April

This commit is contained in:
Silas Oettinghaus
2024-04-19 10:31:36 +02:00
parent 025498d120
commit ed17953407
30 changed files with 3261 additions and 1580 deletions

View File

@@ -12,6 +12,7 @@ classdef Signal
%SIGNAL Construct an instance of this class
% Detailed explanation goes here
obj.signal = signal;
obj.signal = obj.signal;
SignalType = [];
TimeStamp = [];
@@ -26,13 +27,18 @@ classdef Signal
end
%% CONVERT TO INFORMATIONSIGNAL
function [i_sig, varargout] = Informationsignal(obj)
function [i_sig, varargout] = Informationsignal(obj,options)
arguments
obj
options.fs
options.logbook
end
if isa(obj,'Electricalsignal')
%convert to optical
%convert to information
varargout{1} = obj.fs;
i_sig = Informationsignal(obj.signal);
i_sig = Informationsignal(obj.signal,"fs",options.fs,"logbook",options.logbook);
elseif isa(obj,'Opticalsignal')
@@ -109,12 +115,32 @@ classdef Signal
end
%% Add signals from one signal to another, the first object will sustain
function Sum = plus(X,Y)
Sum = X; %first input object will sustain
Sum.signal = X.signal + Y.signal;
end
function Sum = plus(X,y)
%% Display length
if isa(y,'Signal')
Sum = X;
Sum.signal = X.signal + y.signal;
elseif isnumeric(y)
Sum = X;
Sum.signal = X.signal + y;
end
end
function Product = times(X,y)
if isa(y,'Signal')
Product = X;
Product.signal = X.signal .* y.signal;
elseif isnumeric(y)
Product = X;
Product.signal = X.signal .* y;
end
end
%% Display length
function return_length = length(obj)
%METHOD1 Summary of this method goes here
% Detailed explanation goes here
@@ -142,7 +168,7 @@ classdef Signal
end
%% Resample Signal
%% Resample Signal
function obj = resample(obj,options)
arguments
@@ -157,6 +183,8 @@ classdef Signal
obj = obj.logbookentry(desc);
obj.fs = options.fs_out;
end
%%
@@ -262,6 +290,7 @@ classdef Signal
end
%%
function obj = normalize(obj,options)
@@ -270,7 +299,7 @@ classdef Signal
options.mode normalization_mode = normalization_mode.rms
end
switch options.mode
switch options.mode
case normalization_mode.rms
obj.signal = obj.signal/sqrt(mean(abs(obj.signal).^2,"all"));
case normalization_mode.oneone
@@ -283,20 +312,58 @@ classdef Signal
function [obj,delay_n] = delay(obj,options)
arguments
obj Opticalsignal
options.delay_meter double = 0
obj Signal
options.delay_samples = 0
end
delay_t = options.delay_meter /(physconst("LightSpeed")/1.4677);
delay_n = round(delay_t .* obj.fs);
% finally circshift the signal
% obj.signal=circshift(obj.signal,delay_n);
obj.signal=[zeros(delay_n,1); obj.signal(1:end-delay_n) ];
obj.signal=delayseq(obj.signal,options.delay_samples);
end
%%
function [obj,D,cuts] = tsynch(obj,options)
% time sync and cut
arguments
obj Signal
options.reference Signal
options.fs_ref = 0;
end
%normalize the signal
a = obj.normalize("mode","oneone").signal;
%resample the reference
q = obj.fs/options.fs_ref;
b = options.reference.resample("fs_in",options.fs_ref,"fs_out",obj.fs).normalize("mode","oneone").signal;
%estimate delay between signals
[co,lags] = xcorr(a,b,100);
[~,pos] = max(co);
D = lags(pos);
if D == 100
warning('Check Sync: Delay is found to be 100 which is the max. windowlength is xcorr function!')
end
% delay by lagging samples
obj = obj.delay("delay_samples",-D);
cuts = obj.length-(options.reference.length*q);
if cuts > 10
warning('Check Sync: Signal difference larger than 10.')
end
if cuts < 0
% warning('Check Sync: Reference Signal shorter than signal to sync.')
else
% then cut out the length of the reference
obj.signal = obj.signal(1:end-cuts);
end
end
end
end