classdef Opticalsignal < Signal
    %OPTICALSIGNAL Summary of this class goes here
    %   Detailed explanation goes here

    properties
        nase
        lambda
        fs

    end

    methods
        function obj = Opticalsignal(signal, options)
            %OPTICALSIGNAL Construct an instance of this class
            %   Detailed explanation goes here
            arguments
                signal
                options.fs
                options.logbook
                options.lambda
                options.nase
            end

            obj = obj@Signal(signal);

            fn = fieldnames(options);

            for l = 1:numel(fn)
                obj.(fn{l}) = options.(fn{l});
            end


        end

        %%
        function [obj,delay_n] = delay(obj,options)

            arguments
                obj Opticalsignal
                options.delay_meter double = 0
                options.delay_samples = 0
            end
            
            if options.delay_meter ~= 0
                delay_t = options.delay_meter /(physconst("LightSpeed")/1.4677);
                delay_n = delay_t .* obj.fs;
            else
                delay_n = options.delay_samples; 
            end

            obj.signal=delayseq(obj.signal,delay_n);

        end


        function pow = power(obj)

            pow = mean( abs(obj.signal).^2 ) ;
            pow = pow2db(pow)+30; %dbm

        end

        function cspr = cspr(obj)

            carrier_power_dbm = pow2db( abs(mean(obj.signal)).^2 )+30; % dB -> +30 -> dBm 
            signal_power_dbm  = obj.power;

            carr_lin = abs(mean(obj.signal)).^2;
            sign_lin = mean(abs(obj.signal).^2);

            cspr_lin = pow2db(carr_lin/sign_lin);

            cspr =carrier_power_dbm-signal_power_dbm;

        end

        function papr = papr(obj)

            average_power = obj.power;
            peak_power = pow2db(max(abs(obj.signal.^2)))+30;
            papr = peak_power - average_power;

        end
    end
end

