function [flan]=flange(fs, v, flan, r)
%[y] = flange(fs, v, in, r)
%
%   This is a basic flanging effect.
%
%      fs = Sample rate
%      v = Variation.
%      in = Input audio signal. This should be a column 
%          vector.
%      r = Rate.
%
%   Example:
%     
%      >>y = flange(fs,0.002,x,0.5);
%
%
%   See also WAVREAD and SOUND
%
%Version 1.0
%Coded by: Stephen G. McGovern, date: 08.03.03

md= ceil(v*fs);
n=1:length(flan)+md;
v=round(v*fs);
z=zeros(md,1);
m=max(abs(flan));
flan=[z;flan;z];
rr=2*pi/round(fs*r);
b=round((v/2)*(1-cos(rr.*n)));
flan=flan(n+md)+flan(n+md-b);
m=m/max(abs(flan));
flan=m*flan;
