function [ freq_resp, f_center, f_start, f_end, Length_Trans_L, Length_Trans_R ] = FreqPartition(b, r, j, j0)

% Function to form the spectral responses of the CC-DST windows.

% b: paramater to control the frequency spacing between the subbands (b>1).
% r: paramater to set the roll-off factor of the CC-DST filters.
% j: identity of the voice being analyzed.
% j0: identity of the first voice.
% Freq_Resp: the formed spectral response.
% f_center: the voice center frequency.
% f_start: the voice lower edge frequency.
% f_end: the voice upper edge frequency.
% Length_Trans_L: number of frequency samples in the left-hand transition band.
% Length_Trans_R: number of frequency samples in the right-hand transition band.


fst = @(b,j)round(b^(j-1));           % start freq
fend = @(b,j)round((b^(j)));          % end freq
bw = @(b,j)(fend(b,j) - fst(b,j));    % bandwidth
 
f0 = fst(b, j0);
Bw = bw(b,j); 
Nw = Bw+1; 
 
f_start = fst(b, j) - f0;                          
f_end = fend(b, j) - f0;                        
 
[Freq_Trans_R, Length_Trans_R] = Transband(Bw, r);
Bw_L = bw(b,max(j0, j-1));
 
[Freq_Trans_L, Length_Trans_L] = Transband(Bw_L, r);
Freq_Trans_L = flip(Freq_Trans_L);
 
freq_resp = ones(1, Nw+floor(Length_Trans_L/2) + floor(Length_Trans_R/2));
freq_resp(1:Length_Trans_L) = Freq_Trans_L;
freq_resp(end-Length_Trans_R + 1:end) = Freq_Trans_R;

% the following two conditions are necessory to guarentee that the collective
% amplitude of the frequency windows are always unitary over the signal spectrum.

if ~Length_Trans_L
    freq_resp(1) = 0.5;
end
if ~Length_Trans_R
    freq_resp(end) = 0.5;
end
 
f_end = f_end + floor(Length_Trans_R/2);
f_start = f_start - floor(Length_Trans_L/2);
f_center = round((f_start + f_end)/2);
     
end
 
 
function [ Trans, Trans_Length ] = Transband(Bw, r)

% Function to create transition bands.

Nw = Bw+1;
Trans_Length = 2*round(r*(Nw-1)/2)+1;
if  Trans_Length>1
    tTrans = linspace(1-r, 1+r, Trans_Length);
    Trans = 0.5*(1 + cos(pi/(2*r)*(tTrans - (1 - r))));
else
    Trans = [];
    Trans_Length = 0;
end
end