function out=chanvocoder(in, fil, rmsN);

% out=chanvocoder(fil, in, rmsN);
%
% create a new noise-sound, channel vocoder /f-domain/
% 
% in: input
% rmsN: size of rms window
% out: filtered noise ()

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

n=min([length(fil); length(in)]);
in=[zeros(ws,1); in(1:n); zeros(mod(n,hop),1)];
fil=[zeros(ws,1); fil(1:n); zeros(mod(n,hop),1)];
out=zeros(length(in),1);
win=hanning(ws);

ii=0;
iiend=length(in)-ws;

while ii<iiend    
    frame=fft(in(ii+1:ii+ws).*win);
    env=chanvocf(fil(ii+1:ii+ws),ws,rmsN);
    frame=real(ifft(env.*frame)).*win;
    out(ii+1:ii+ws)=out(ii+1:ii+ws)+frame;
    ii=ii+hop;
end
out=out(ws+1:ws+n)/max(abs(out(ws+1:ws+n)));

figure;
plot(in);
hold on;
plot(out,'r');  