Merge remote-tracking branch 'origin/main'

This commit is contained in:
Silas Oettinghaus
2024-10-07 08:24:08 +02:00
23 changed files with 1550 additions and 97 deletions

View File

@@ -193,14 +193,14 @@ classdef Signal
end
%% Add signals from one signal to another, the first object will sustain
function Difference = minus(X,y)
function Diff = minus(X,y)
if isa(y,'Signal')
Difference = X;
Difference.signal = X.signal - y.signal;
Diff = X;
Diff.signal = X.signal - y.signal;
elseif isnumeric(y)
Difference = X;
Difference.signal = X.signal - y;
Diff = X;
Diff.signal = X.signal - y;
end
end
@@ -303,9 +303,11 @@ classdef Signal
xlim([-obj.fs/2 obj.fs/2].*1e-9)
edgetick = 2^(nextpow2(obj.fs*1e-9));
% xticks([-edgetick:16:edgetick]);
xlim([-244, 244])
ylim([-120,10]);
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]);
yticks([-200:10:10]);
grid on
grid minor
legend
end
@@ -423,8 +425,8 @@ classdef Signal
end
%% Synchronize with reference
function [obj,D,cuts] = tsynch(obj,options)
%%
function [obj,S] = tsynch(obj,options)
% time sync and cut
arguments
obj Signal
@@ -440,29 +442,36 @@ classdef Signal
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);
[co,lags] = xcorr(a,b);
[~,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!')
%estimate start pos of signal
maxpeaknum = floor(length(a)/length(b));
[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
S = {};
for c = shifts
sig = obj.delay(-c,'mode','samples');
sig.signal = sig.signal(1:length(b));
S{end+1,1} = sig;
end
% delay by lagging samples
obj = obj.delay(-D,'mode','samples');
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);
%plot all synced signals and the ref signal
debug = 0;
if debug
figure;hold on;
for i = 1:size(S,1)
plot(S{i}.normalize('mode','oneone').signal(1000:1100),'LineWidth',0.1,'Color',[0.2157 0.4941 0.7216]);
plot(b(1000:1100),'LineWidth',1);
end
end
%return the sinal with the highest correlation...
[~,idx]=max(pks);
obj.signal = S{idx}.signal;
end
@@ -623,7 +632,6 @@ classdef Signal
% beautify
colormap(cbrewer2("Blues",4096));
if isa(obj,'Opticalsignal')
title("Optical Eye")
ylabel("Power in mW");
@@ -673,41 +681,15 @@ classdef Signal
% Define properties
boxPosition = [0.15 0.86 0.2 0.05]; % Position for the first box [x y width height]
boxColor = [0.9 0.9 0.9]; % Light grey background color
boxEdgeColor = 'k'; % Black edge color
boxLineStyle = '--'; % Dashed line style
boxFontWeight = 'bold'; % Bold font
% Create first annotation box for Power
annotation('textbox', boxPosition, ...
'String', ['Power: ',num2str(pwr_dbm),' dBm'], ...
'BackgroundColor', boxColor, ...
'EdgeColor', boxEdgeColor, ...
'LineStyle', boxLineStyle, ...
'FontWeight', boxFontWeight, ...
'HorizontalAlignment', 'center');
% Adjust position for the second box (slightly to the right)
boxPosition = [0.37 0.86 0.2 0.05]; % Adjusted position
% Create second annotation box for PAPR
annotation('textbox', boxPosition, ...
'String', ['PAPR(lin):',num2str(papr_),''], ...
'BackgroundColor', boxColor, ...
'EdgeColor', boxEdgeColor, ...
'LineStyle', boxLineStyle, ...
'FontWeight', boxFontWeight, ...
'HorizontalAlignment', 'center');
try
hist_interest = plot_data(:,posxall);
hist_interest_smoth = smooth(hist_interest,20);
a = scatter(hist_interest_smoth+posxall,1:length(hist_interest_smoth),4,'.','MarkerEdgeColor','red');
[pk,loc] = findpeaks(hist_interest_smoth,"MinPeakDistance",40,"NPeaks",M,"MinPeakHeight",30);
[pk,loc] = findpeaks(hist_interest_smoth,"MinPeakDistance",10,"NPeaks",M,"MinPeakHeight",30,"MinPeakProminence",10);
scatter(posxall,loc,'red','Marker','x','LineWidth',2);
yline(loc,'Color','red','LineWidth',1,'LineStyle',':');
for i = 1:numel(loc)
@@ -738,6 +720,37 @@ classdef Signal
thirdboxstring = ['OMA outer:',num2str(er),' V'];
end
plot_infos = 0;
if plot_infos
% Define properties
boxPosition = [0.15 0.86 0.2 0.05]; % Position for the first box [x y width height]
boxColor = [0.9 0.9 0.9]; % Light grey background color
boxEdgeColor = 'k'; % Black edge color
boxLineStyle = '--'; % Dashed line style
boxFontWeight = 'bold'; % Bold font
% Create first annotation box for Power
annotation('textbox', boxPosition, ...
'String', ['Power: ',num2str(pwr_dbm),' dBm'], ...
'BackgroundColor', boxColor, ...
'EdgeColor', boxEdgeColor, ...
'LineStyle', boxLineStyle, ...
'FontWeight', boxFontWeight, ...
'HorizontalAlignment', 'center');
% Adjust position for the second box (slightly to the right)
boxPosition = [0.37 0.86 0.2 0.05]; % Adjusted position
% Create second annotation box for PAPR
annotation('textbox', boxPosition, ...
'String', ['PAPR(lin):',num2str(papr_),''], ...
'BackgroundColor', boxColor, ...
'EdgeColor', boxEdgeColor, ...
'LineStyle', boxLineStyle, ...
'FontWeight', boxFontWeight, ...
'HorizontalAlignment', 'center');
annotation('textbox', boxPosition, ...
@@ -749,6 +762,8 @@ classdef Signal
'HorizontalAlignment', 'center');
end
end
yticks(linspace(0,histpoints,16));
y_tickstring = sprintfc('%.2f', y_tickstring);
yticklabels(y_tickstring);