Home > reduc > Tukey_filter.m

Tukey_filter

PURPOSE ^

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

SYNOPSIS ^

function filter = Tukey_filter(f1,f2,f3,f4,Fs,NFFT,x)

DESCRIPTION ^

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 filter = tukey_bandstop(f1,f2,f3,f4,Fs,n_points,x)

 Function to generate a Tukey bandstop filter (cosine edged band stop)
 
  -----          ------
      |\        /|
      | \      / |
      |  ------  | 
     f1  |    |  |
        f2    f3 f4
 Inputs: 
            f1,f2,f3,f4
 (Optional) Fs, n_points, x 
  These are automatically picked up when using filter_data.m
  If not given then resorts to default of Fs = 100 ,
  n_points =1000 (was useful for independent checking).



 act 2/9/2010
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function filter = Tukey_filter(f1,f2,f3,f4,Fs,NFFT,x)
0002 
0003 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0004 % filter = tukey_bandstop(f1,f2,f3,f4,Fs,n_points,x)
0005 %
0006 % Function to generate a Tukey bandstop filter (cosine edged band stop)
0007 %
0008 %  -----          ------
0009 %      |\        /|
0010 %      | \      / |
0011 %      |  ------  |
0012 %     f1  |    |  |
0013 %        f2    f3 f4
0014 % Inputs:
0015 %            f1,f2,f3,f4
0016 % (Optional) Fs, n_points, x
0017 %  These are automatically picked up when using filter_data.m
0018 %  If not given then resorts to default of Fs = 100 ,
0019 %  n_points =1000 (was useful for independent checking).
0020 %
0021 %
0022 %
0023 % act 2/9/2010
0024 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0025 
0026 if(nargin<7)
0027     Fs = 100;
0028     NFFT = 1000;
0029     x = Fs/2 * linspace(0,1,NFFT);
0030 end
0031 
0032 
0033 filter = ones(1,NFFT);
0034 
0035 n_points = NFFT/2+1;
0036 n1 = floor(f1 * n_points / (Fs/2));
0037 n2 = floor(f2 * n_points / (Fs/2));
0038 n3 = floor(f3 * n_points / (Fs/2));
0039 n4 = floor(f4 * n_points / (Fs/2));
0040 
0041 
0042 %Calculate lower edge
0043 
0044 for i =  n1:n2
0045     range = n2-n1;
0046     j=i-n1;
0047     filter(i) = 0.5 * (1+cos((pi*j)/(range)));
0048     filter(NFFT-i+1) = 0.5 * (1+cos((pi*j)/(range)));
0049 end
0050 
0051 %Calculate upper edge
0052 
0053 for i =  n3:n4
0054     range = n4-n3;
0055     j=i-n3;
0056     filter(i) = 1-(0.5 * (1+cos((pi*j)/(range))));
0057     filter(NFFT-i+1) = 1-(0.5 * (1+cos((pi*j)/(range))));
0058 end
0059 
0060 %Centre region of filter
0061 
0062 for i = n2+1 : n3-1
0063     filter(i)=0;
0064     filter(NFFT-i+1)=0;
0065 end
0066 
0067 
0068 %figure
0069 %plot(filter)

Generated on Sun 14-Jun-2015 17:12:45 by m2html © 2005