<?xml version="1.0" encoding="utf-8" standalone="no"?>
<!DOCTYPE document PUBLIC "-//CNX//DTD CNXML 0.5 plus MathML//EN" "http://cnx.rice.edu/technology/cnxml/schema/dtd/0.5/cnxml_mathml.dtd">
<document xmlns="http://cnx.rice.edu/cnxml" xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" xmlns:m="http://www.w3.org/1998/Math/MathML" id="new">
  <name>Modeling flange in Matlab</name>
  <metadata>
  <md:version>1.2</md:version>
  <md:created>2006/12/19 17:27:25 US/Central</md:created>
  <md:revised>2006/12/23 13:55:49.128 US/Central</md:revised>
  <md:authorlist>
      <md:author id="brent">
      <md:firstname>Brent</md:firstname>
      <md:othername>E.</md:othername>
      <md:surname>Stephens</md:surname>
      <md:email>brents@rice.edu</md:email>
    </md:author>
      <md:author id="robsmith">
      <md:firstname>Rob</md:firstname>
      
      <md:surname>Smith</md:surname>
      <md:email>rob@rice.edu</md:email>
    </md:author>
      <md:author id="barron">
      <md:firstname>Barron</md:firstname>
      <md:othername>D.</md:othername>
      <md:surname>Stone</md:surname>
      <md:email>barron@rice.edu</md:email>
    </md:author>
      <md:author id="narayann">
      <md:firstname>Neil</md:firstname>
      <md:othername>K.</md:othername>
      <md:surname>Narayan</md:surname>
      <md:email>narayann@rice.edu</md:email>
    </md:author>
  </md:authorlist>

  <md:maintainerlist>
    <md:maintainer id="brent">
      <md:firstname>Brent</md:firstname>
      <md:othername>E.</md:othername>
      <md:surname>Stephens</md:surname>
      <md:email>brents@rice.edu</md:email>
    </md:maintainer>
    <md:maintainer id="robsmith">
      <md:firstname>Rob</md:firstname>
      
      <md:surname>Smith</md:surname>
      <md:email>rob@rice.edu</md:email>
    </md:maintainer>
    <md:maintainer id="barron">
      <md:firstname>Barron</md:firstname>
      <md:othername>D.</md:othername>
      <md:surname>Stone</md:surname>
      <md:email>barron@rice.edu</md:email>
    </md:maintainer>
    <md:maintainer id="narayann">
      <md:firstname>Neil</md:firstname>
      <md:othername>K.</md:othername>
      <md:surname>Narayan</md:surname>
      <md:email>narayann@rice.edu</md:email>
    </md:maintainer>
    <md:maintainer id="richb">
      <md:firstname>Richard</md:firstname>
      <md:othername>G.</md:othername>
      <md:surname>Baraniuk</md:surname>
      <md:email>richb@rice.edu</md:email>
    </md:maintainer>
    <md:maintainer id="Markpanzee">
      <md:firstname>Mark</md:firstname>
      <md:othername>A.</md:othername>
      <md:surname>Davenport</md:surname>
      <md:email>md@rice.edu</md:email>
    </md:maintainer>
  </md:maintainerlist>
  
  <md:keywordlist>
    <md:keyword>Effects</md:keyword>
    <md:keyword>Flange</md:keyword>
    <md:keyword>Matlab</md:keyword>
  </md:keywordlist>

  <md:abstract>An implementation of flange in Matlab as written by Stephen G. McGovern, date: 08.03.03</md:abstract>
</metadata>
  <content>
    <para id="element-6">Flanging is performed by taking the original copy of the signal and adding it to a time delayed version of itself.  However, this effect differs from reverb, which is just adding a signal to a time-delayed version of itself with a set delay, because the delay gradually changes and is usually determined with a low frequency oscillator. Flanging is a type of phasing, which is where a signal is filtered with an all-pass filter with a non-linear phase responce.  The phasing effect can be easily observed in the spectrogram of the signal.</para><figure id="element-94"><name>Spectrogram of a Guitar Chord</name>
  <media type="image/png" src="specgram.png"/>
  <caption>The spectrogram of a guitar chord being played</caption></figure><figure id="element-867"><name>Spectrogram of a Guitar Chord after Flanging</name>
  <media type="image/png" src="flangedspec.png"/>
  <caption>The spectrogram of a guitar chord after flanging</caption></figure><para id="element-586">As for the actual Matlab implementation of flanging, Stephen G. McGovern had already created an implementation, and because the main point of this project is not to create guitar effects, but to implement adaptive guitar effects.</para><para id="element-622">This is Stephen G. McGovern's (slightly modified) code:</para><code type="block">function [y]=flanger(fs, y, wet)
v = 0.002;
r = 0.5;
orig = y;

%[y] = flange(fs, v, x, r)
%
%   This is a basic flanging effect.
%
%      fs = Sample rate
%      v = Variation.
%      x = Input audio signal. This should be a column 
%          vector.
%      r = Rate.
%
%   Example:
%     
%      &gt;&gt;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(y)+md;
v=round(v*fs);
z=zeros(md,1);
m=max(abs(y));
y=[z;y;z];
rr=2*pi/round(fs*r);
b=round((v/2)*(1-cos(rr.*n)));
y=y(n+md)+y(n+md-b);
m=m/max(abs(y));
y=m*y;

y = y(1:length(orig));

y = wet * y + (1 - wet) * orig;
</code><para id="element-245">This is the only thing that cannot be immediately converted into real time.  In order to do that, another implementation using circular buffer would be needed.</para><para id="element-154"><link src="http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=6656">Link to Stephen G. McGovern's implementation of Flange</link></para>   
  </content>
  
</document>
