Minor bug fixes and code formatting
[100GbE-PON.git] / phaseNoise.m
1 function [xPN, phasenoise] = phaseNoise(x, linewidthTx, linewidthLO, Tsamp)
2   %% Simulates laser phase noise.
3   %% Inputs:
4   %%  - x: input waveform
5   %%  - linewidthTx: Tx laser linewidth (Hz)
6   %%  - linewidthLO: Rx LO laser linewidth (Hz)
7   %%  - Tsamp: Sampling period (s)
8   %% Outputs:
9   %%  - xPN: output waveform
10   %%  - phasenoise: the actual phase noise added (rad)
11   dphiTx = sqrt(2 * pi * linewidthTx * Tsamp) * randn(length(x), 1);
12   dphiLO = sqrt(2 * pi * linewidthLO * Tsamp) * randn(length(x), 1);
13   phiTx = cumsum(dphiTx);
14   phiLO = cumsum(dphiLO);
15
16   phasenoise = phiTx - phiLO;
17   xPN = x .* exp(-1j * phasenoise);
18 end