function env=chanvoc (y,fftN, winN)

% env=chanvoc (y,fftN, winN)
% 
% channel vocoder: rms using circular convolution
%
% y: input
% fftN: fft-size
% winN: RMS-window size
% env: low passed envelope of input

y=fft(y,fftN);
y=y.*conj(y);   % energy

winN=floor(winN/2);
winN=2*winN+1;  % window size must be odd
w=hanning(winN);
w=w./sum(w);    % normalise window
win=zeros(length(y),1);
win=[zeros(ceil(length(y)/2)-floor(winN/2)-1,1); w; zeros(floor(length(y)/2)-floor(winN/2),1)];
winf=fft(fftshift(win));

env=real(ifft(fft(y).*winf));
env=sqrt(env);