%% This shell convert the waveform from time domain to depth domain
%% Written by Heyaoyao on 2025/7/4
function [H, amp] = time2depth(time, data, tshift, vp, k, rayp, minH, maxH)
vs = vp/k;
delta = time(2)-time(1);
time_cut = time(round(tshift/delta)+1:end);
data_cut = data(round(tshift/delta)+1:end);
nt = length(time_cut);
H_temp = zeros(1, nt);
amp_temp = zeros(1, nt);
for ii = 1:nt
    diff_t = time_cut(ii);
    H_temp(ii) = diff_t/(sqrt(vs^(-2)-rayp^2)-sqrt(vp^(-2)-rayp^2));
    amp_temp(ii) = data_cut(ii);
end
H = linspace(minH, maxH, 2501);
amp = interp1(H_temp, amp_temp, H, 'linear');


%  def time_to_depth_Ps(t0,time,data,rayp,arfa,beta,hmin=0,hmax=600):
%     dt = time[1] - time[0]
%     nt = len(time)
%     it0 = int((t0-time[0]) /dt + 1 )
%     index = np.arange(it0,nt)  
%     H = []
%     amp = []
%     for i,tnumber in enumerate(index):
%         thist = (tnumber - it0) *dt
%         H.append(thist/(np.sqrt(beta**-2 - rayp**2)-np.sqrt(arfa**-2 - rayp**2)))
%         amp.append(data[tnumber])
%     H,amp = np.array(H),np.array(amp)
%     newH = np.linspace(0,600,6000)
%     f = interp1d(H,amp,kind='linear',bounds_error=False,fill_value=0)
%     newamp = f(newH)
%     return newH,newamp

end