a_inj = 2e-4;
t_stop = 10e-6;
f_inj = 622e6;
ts = 1e-10;
duty_cycle = 60;
sim('ring_osc_comp_diff_pulse_fft',t_stop)

fs = 1/ts;

N = 4*8192;
vout_len = length(vout_last);

psd_avg = 0;
clf

for i=1:10
    X = (i-1)*2048;
    fft_signal = vout_last(vout_len-N+1-X:vout_len-X);

    dft = fft(fft_signal.*hann(length(fft_signal)), N);
    dft = dft(1:N/2+1);
    psd = (1/(fs*N))*abs(dft).^2;
    psd(2:end-1) = 2*psd(2:end-1);
    
    psd_avg = psd_avg + (psd - psd_avg)/i;
    
    %semilogx(freq,10*log10(psd))
    %hold on
end

freq = 0:fs/N:fs/2;

psd_log = 10*log10(psd_avg);

semilogx(freq,psd_log)
grid on
hold on