function [freq,xx,yy]=reconstruct(freq_in,xx_in,yy_in)
% It takes the avaible S11 response of the resonance (with the part of 
% higher frequency) and reconstruct the whole S11 response 
% It is useful when only part of the S11 is free from other close effects
% function [freq,xx,yy]=reconstruct(freq_in,xx_in,yy_in)

% It takes the upper half of the S11 resonance response from the avaible
% data
abs_in=sqrt(xx_in.^2+yy_in.^2);
phase_in=unwrap(atan2(yy_in,xx_in));

[value,index]=min(abs_in);
freq_min=freq_in(index);
phase_offset=phase_in(index);

step_freq=freq_in(2)-freq_in(1);

% Writing the upper half of the S11 resonance response
abs_half=abs_in(index:length(abs_in));
phase_half=phase_in(index:length(abs_in));
freq_half=freq_in(index:length(abs_in));

% The S11 absolute value is symetric with respect to the resonace
missing_abs=abs_half(length(abs_half)-2:-1:2);
whole_abs=[missing_abs; abs_half];

% The S11 phase is anti-simmetric with respect to the offset
traslated_phase=phase_half-phase_offset;
missing_phase=-traslated_phase(length(abs_half)-2:-1:2);
whole_phase=[missing_phase; traslated_phase]+phase_offset;

% The frequency ...
ii=2:length(freq_half)-2;
missing_freq=2*freq_half(1)-freq_half(length(freq_half))+(step_freq).*ii';
freq=[missing_freq; freq_half];

% The final result
xx=whole_abs.*cos(whole_phase);
yy=whole_abs.*sin(whole_phase);