function [out_spec, out_theta] = puzzle_from_one_cycle(Espec, cep_full, res_oneCycle, theta_oneCycle, idx)
% input: Result (spectra and phases) for birthtimes in one cycle
% output: Full spectra (for birthtimes in both cycles) and phases

out_spec = zeros(numel(Espec), numel(cep_full));

out_spec(:, 1:idx.ub) = res_oneCycle(:, idx.Zpi:idx.ub_1) + res_oneCycle(:, idx.Tpi:end);
out_spec(:, idx.ub+1:idx.lb-1) = res_oneCycle(:, idx.ub_1+1:idx.lb_1-1);
out_spec(:, idx.lb:end) = res_oneCycle(:, idx.lb_1:idx.Tpi) + res_oneCycle(:, 1:idx.Zpi);

% Phase combi via harmonic theorem 
theta_oneCycle(isnan(theta_oneCycle)) = 0;
out_theta = zeros(numel(Espec), numel(cep_full));

spec11 = res_oneCycle(:, idx.Zpi:idx.ub_1); phase11 = theta_oneCycle(:, idx.Zpi:idx.ub_1);
spec21 = res_oneCycle(:, idx.Tpi:end); phase21 = theta_oneCycle(:, idx.Tpi:end);
out_theta(:, 1:idx.ub) = unwrap(atan2((abs(spec11).*sin(phase11) + abs(spec21).*sin(phase21)), (abs(spec11).*cos(phase11) + abs(spec21).*cos(phase21))));

out_theta(:, idx.ub+1:idx.lb-1) = theta_oneCycle(:, idx.ub_1+1:idx.lb_1-1);

spec11 = res_oneCycle(:, idx.lb_1:idx.Tpi); phase11 = theta_oneCycle(:, idx.lb_1:idx.Tpi);
spec21 = res_oneCycle(:, 1:idx.Zpi); phase21 = theta_oneCycle(:, 1:idx.Zpi);
out_theta(:, idx.lb:end) = unwrap(atan2((abs(spec11).*sin(phase11) + abs(spec21).*sin(phase21)), (abs(spec11).*cos(phase11) + abs(spec21).*cos(phase21))));

end
