%%% Matlab OSA code %%%
OutputPort1 = InputPort1;
%%% Defining the amplitude and frequency arrays %%%
amp = InputPort1.Sampled.Signal;
freq = InputPort1.Sampled.Frequency;

%%% Assign default polarization to 1 %%%
polar = 1;

%%% Check how many polarizations there are, and then apply the appropriate  %%%
%%% equations to convert to power.                                           %%%

if (length(amp) > length(freq))
    polar = 2;
end
if (polar == 2)
    power = amp(1,:).^2 + amp(2,:).^2;
else
    power = amp(1,:).^2;
end

%%% Convert power to dBm, and plot %%%
power_dBm = 10*log10(power*1000);
plot(freq, power_dBm);
pause(5);
