function out=bsp_weisslich(in, cepN);

% out=weisslich(in, cepN);
%
% create a new noise-sound, which envelope will follow the cepstrum of in.
% 
% in: input
% cepN: size of cepstrum window
% out: filtered noise (envelope=windowed cepstrum of input)

ws=2048;    % window size
hop=512;    % hop size

n=length(in);
in=[zeros(ws,1); in; zeros(ws-mod(n,hop),1); zeros(ws,1)];
out=zeros(length(in)+ws,1);
win=hanning(ws)*2*hop/ws;

ii=0;
iiend=length(in)-ws;
while ii<iiend    
    frame=in(ii+1:ii+ws).*win;
    [nix,fil]=cepstrum(frame,2*ws,cepN);
    frame=real(ifft(fft(rand(2*ws,1)-0.5).*fil));
    out(ii+1:ii+2*ws)=out(ii+1:ii+2*ws)+frame;  % overlap and add
    ii=ii+hop;
end
in=[in; zeros(ws,1)];
out=out(ws+1:ws+n)/max(abs(out(ws+1:ws+n)));
figure;
plot(in);
hold on;
plot(out,'r');  