WIP Büro

This commit is contained in:
Silas Oettinghaus
2023-05-25 16:29:27 +02:00
parent f3f52b1f7c
commit 8b2129ac03
9 changed files with 270 additions and 120 deletions

View File

@@ -24,6 +24,7 @@ classdef Signal
end
%% CONVERT TO INFORMATIONSIGNAL
function [i_sig, varargout] = Informationsignal(obj)
if isa(obj,'Electricalsignal')
@@ -40,6 +41,7 @@ classdef Signal
end
%% CONVERT TO Electricalsignal
function [e_sig, varargout] = Electricalsignal(obj,options)
arguments
@@ -70,6 +72,7 @@ classdef Signal
end
%% CONVERT TO Opticalsignal
function o_sig = Opticalsignal(obj, options)
arguments
@@ -91,9 +94,9 @@ classdef Signal
if isa(obj,'Electricalsignal')
%convert to optical
o_sig = Opticalsignal(obj.signal,"fs",obj.fs,"lambda",options.lambda,"logbook",obj.logbook,"nase",options.nase);
elseif isa(obj,'Informationsignal')
@@ -104,12 +107,14 @@ classdef Signal
end
%% Display length
function return_length = length(obj)
%METHOD1 Summary of this method goes here
% Detailed explanation goes here
return_length = length(obj.signal);
end
%% Write Logbook Entry
function obj = logbookentry(obj,varargin)
if nargin > 1
@@ -130,6 +135,7 @@ classdef Signal
end
%% Resample Signal
function obj = resample(obj,options)
arguments
@@ -146,6 +152,104 @@ classdef Signal
end
%%
function spectrum(obj,fsamp,options)
arguments
obj
fsamp
options.figurename = [];
options.displayname = [];
end
%Get figure if there is already a spectrum plot -> I want to add the new
%spectum "onto" the existing plot to have a better comparison
if isempty(options.figurename)
fig = findall(groot, 'Type', 'figure', 'Name', 'power density');
if isvalid(fig)
fig = get(fig);
hold on
else
figure('name','power density');
end
else
fig = findall(groot, 'Type', 'figure', 'Name', options.figurename);
if isvalid(fig)
fig = get(fig);
hold on
else
figure('name',options.figurename);
end
end
%compute FFT of input
Fsignal = fft(obj.signal);
%POWER spectral density (todo: toggle?)
psd = Fsignal.*conj(Fsignal);
%Use only magnitude of FFT (which was complex)
psd = abs(psd);
%Shift the spectrum to yield
psd = fftshift(psd);
%divide by N
psd = psd/length(Fsignal);
%smoothing
psd = smooth(psd,100);
psd_plot = 20*log10(psd);
testParseval = 1;
if testParseval == 1
E_FreqDomain = sum(psd);
%test parseval
E_TimeDomain = sum(abs(Fsignal.^2));
if isequal(round(E_FreqDomain,1),round(E_TimeDomain,1))
%disp('Parseval is right!');
else
disp('Parseval theorem is not right...');
end
end
if fsamp <= 1e+100
%Frequency Axis
freq_vec = linspace(-fsamp/2,fsamp/2,length(psd));
freq_vec = reshape(freq_vec,size(psd_plot));
if ~isempty(options.displayname)
plot(freq_vec*1e-9,psd_plot,'Linewidth',0.5,'DisplayName',options.displayname);
else
plot(freq_vec*1e-9,psd_plot,'Linewidth',0.5);
end
xlabel('Frequency [GHz]')
else
%Wavelength Axis
freq_vec = physconst('LightSpeed')*linspace(-fsamp/2,fsamp/2,length(psd))./((physconst('LightSpeed')/1550e-9)^2);
if ~isempty(options.displayname)
plot(freq_vec*1e9,psd_plot,'Linewidth',0.5,'DisplayName',options.displayname);
else
plot(freq_vec*1e9,psd_plot,'Linewidth',0.5);
end
xlabel('Wavelength [nm]')
end
ylabel('Magnitude [dB]')
legend
grid minor;
end
end
end