- 1

- 0

Have the code for output P which i think is correct but i now need to do analyse the P spectrum in the Fourier domain.

I know my base should be p = abs(fft(f)) but im struggling to code it right! any help appreciate guys!

% Define laser parameters

Em = 1; %

factor = 2*pi;

c = 3e8; % speed of light

lambda = 1.5500e-006;

L = 1.5;

modes = 80

FSR = c/(2*L); % free spectral range of the cavity

t = -27e-9:1e-12:27e-9; % go from -27 ns to +27 ns in steps of 1 ps.

total = 0;

Upper = (c/lambda)+(modes*FSR); % Upper frequency limit: c/lambda + (modes * FSR)

for f = (c/lambda):FSR:Upper % go from fundamental laser frequency to higher freqs by steps of 1 FSR

phase = randn*factor; % calculate the phase for the mth mode

E = Em*cos(2*pi*f*t+phase); % calculate electric field for mth mode

total = total+E;

end

Power = abs(total).^2;

time = t./(1e-9);

% Plot power spectrum in time domain

PowerPlot = figure;

plot(time,Power/max(Power))

xlabel('time (ns)')

ylabel('y(t)')

title('Power Spectrum in Time Domain')

grid

xlim([-27 27])