function [ xt, Xf ] = ICCDST2( S, Trans_Band, N_sig )

% Function to invert the CC-DST.

% This function is used with the application of time-scalling audio signal.
% S: cell array contains the CC-DST voices.
% Trans_Band: number of frequency samples in the left-hand transition bands of the CC-DST frequency windows.
% N_sig: number of samples of the synthesized signal.
% xt: reconstructed signal (in time domain).
% Xf: DFT of the reconstructed signal.

D = length(S) - length(Trans_Band);
if D>0 
    S = S(D/2+1:end-D/2);
else
    Trans_Band = Trans_Band(-D/2+1:end+D/2);
end
 
N = length(S);
Xf = (N_sig/length(S{1})).* fftshift(fft(S{1}));
Bw = length(Xf);
if mod(Bw, 2)==0
    Xf = circshift(Xf,[0, -1]);
end
 
for j=2:N
    Xf_part = (N_sig/length(S{j})).*fftshift(fft(S{j}));
    Bw = length(Xf_part);
    if j<N/2+1 && mod(Bw, 2)==0
        Xf_part = circshift(Xf_part, [0, -1]);
    end
    L = length(Xf);
    Xf = [Xf, zeros(1, Bw-Trans_Band(j)-(Trans_Band(j)==0))];
    Xf(L-Trans_Band(j) + (Trans_Band(j)~=0):end)= Xf(L-Trans_Band(j) + (Trans_Band(j)~=0):end) + Xf_part;
end

if length(Xf)>N_sig
    Xf = Xf(ceil((length(Xf) + 1)/2) - N_sig/2:ceil((length(Xf) + 1)/2) + N_sig/2-1); % size adjustment
end 
xt = ifft(fftshift(Xf)); 
if max(imag(xt)<1e-10)
    xt=real(xt);   % neglect small imaginary part
end
end