%Script
  x= wavread('Guitar.wav');

  fs= 44100; %Sets Sampeling frequency

% Filter Design %
   
 %LPF Design
    
  PASSHZ_LOW = 250; %sets the passband frequency for the LPF in Hz
  STOPHZ_LOW = 300; %sets the stopband frequency for the LPF in Hz
  RIP_LOW = .1;      %sets the passband ripple for the LPF
  STOPDB_LOW = 60;  %sets the stopband attenuation for the LPF in dB

  LPFdesign = fdesign.lowpass('Fp,Fst,Ap,Ast',PASSHZ_LOW, STOPHZ_LOW, RIP_LOW,...
      STOPDB_LOW,fs);
   %Creates lowpass filter using default lowpass string elements
  LPF = design(LPFdesign,'IIR');
   %Implements filter design to LPF 
    
  %HPF Design
    
  PASSHZ_HI = 4000; %sets the passband frequency for the HPF in HZ
  STOPHZ_HI = 3500; %sets the stopband frequency for the HPF in HZ
  RIP_HI = .1;       %sets the passband ripple for the HPF
  STOPDB_HI = 60;   %sets the stopband attenuation for the HPF in dB
  
  HIdesign = fdesign.highpass('Fst,Fp,Ast,Ap', STOPHZ_HI, PASSHZ_HI, STOPDB_HI,...
      RIP_HI, fs);
   %Creates highpass filter using default highpass string elements
  HPF = design(HIdesign,'IIR');
   %Implements filter design to HPF
    
  %For Bandpass Filter
  
    PASSHZ_1_BP = 275;   %sets the first passband frequency for the BPF in Hz
    STOPHZ_1_BP = 200;   %sets the first stopband frequency for the BPF in Hz
    PASSHZ_2_BP = 3500;  %sets the second passband frequency for the BPF in Hz
    STOPHZ_2_BP = 4000;  %sets the second stopband frequency for the BPF in Hz
    STOPDB_1_BP = 60;    %sets the first stopband attenuation for the BPF in dB
    STOPDB_2_BP = 60;    %sets the second stopband attenuation for the BPF in dB
    RIP_BP  = .1;         %sets the passband ripple for the BPF
    
    MIDdesign = fdesign.bandpass('Fst1,Fp1,Fp2,Fst2,Ast1,Ap,Ast2', STOPHZ_1_BP,...
    PASSHZ_1_BP, PASSHZ_2_BP, STOPHZ_2_BP, STOPDB_1_BP, RIP_BP, STOPDB_2_BP,fs);
     %Creates bandpass filter using default bandpass string elements
    BPF = design(MIDdesign,'IIR');
     %Implements filter design to BPF
 
% Splitting the Input into 3 frequency bands %

  LOWX= filter(LPF,x); %Apply lowpass filter to input
  MIDX= filter(BPF,x); %Apply bandpass filter to input
  HIX=  filter(HPF,x); %Apply highpass filter to input


% Flanger permeters:

  display= '\n Flange Delay time (ms) 0.1-10\n\n >'  ;
  delay= input(display);

%Low Band permeters
  display= '\n Low Band Flange Width (ms) 0.1-10\n\n >';
  lwidth= input(display);

  display= '\n Low Band Flange Rate (HZ) 0.05-5\n\n >';
  lrate= input(display);

  display= '\n Low Band Flange Mix 0-1\n\n >';
  lmix= input (display);

%Mid Band permeters

  display= '\n mid Band Flange Width (ms) 0.1-10\n\n >';
  mwidth= input(display);

  display= '\n mid Band Flange Rate (HZ) 0.05-5\n\n >';
  mrate= input(display);

  display= '\n mid Band Flange Mix 0-1\n\n >';
  mmix= input (display);

%High Band

  display= '\n High Band Flange Width (ms) 0.1-10\n\n >';
  hwidth= input(display);

  display= '\n High Band Flange Rate (HZ) 0.05-5\n\n >';
  hrate= input(display);

  display= '\n High Band Flange Mix 0-1\n\n >';
  hmix= input (display);

%Apply Flanger to each frequency band.

  LOWflange= flanger(LOWX,lmix,delay,lwidth,lrate,fs);
  MIDflange= flanger(MIDX,mmix,delay,mwidth,mrate,fs);
  HIflange= flanger(HIX,hmix,delay,hwidth,hrate,fs);   

%Frequency Band normalization and overall mix.

  display= '\n Low Band Mix level 0-1\n\n>';
  LOWmix= input (display);
   %User sets low band mix level 
  display= '\n Mid Band Mix Level 0-1\n\n>';
  MIDmix= input (display);
   %User sets mid band mix level
  display= '/High Band Mix Level 0-1\n\n>';
  HImix= input (display);
   %User set high band mix level
  LOWfinal= LOWmix.*LOWflange;
  MIDfinal= MIDmix.*MIDflange;
  HIfinal= HImix.* HIflange;
   %Add the user set mix levels to the individual bands
  LOWfinal= LOWfinal./max(abs((LOWfinal)));
  MIDfinal= MIDfinal./max(abs((MIDfinal)));
  HIfinal= HIfinal./max(abs((HIfinal)));
   %Normalize the outputs
  output= LOWfinal+MIDfinal+HIfinal;
   %recombine frequency bands to a single signal.
   output= output./max(abs((output)));
   
  sound(output,fs);   %play final signal
