Home > reduc > LowPass_filter.m

LowPass_filter

PURPOSE ^

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

SYNOPSIS ^

function filter = LowPass_filter(f1,f2,Fs,NFFT,x)

DESCRIPTION ^

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 filter = LowPass-filter(f1,f2,Fs,n_points,x)

 Function to generate a low pass filter (with cosine edges)
 
  -----          
      |\     
      | \    
      |  ---- 
     f1  |   
        f2   
 Inputs: 
            f1,f2
 (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 14/9/2010
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function filter = LowPass_filter(f1,f2,Fs,NFFT,x)
0002 
0003 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0004 % filter = LowPass-filter(f1,f2,Fs,n_points,x)
0005 %
0006 % Function to generate a low pass filter (with cosine edges)
0007 %
0008 %  -----
0009 %      |\
0010 %      | \
0011 %      |  ----
0012 %     f1  |
0013 %        f2
0014 % Inputs:
0015 %            f1,f2
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 14/9/2010
0024 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0025 
0026 if(nargin<3)
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 
0039 %Calculate lower edge
0040 
0041 for i =  n1:n2
0042     range = n2-n1;
0043     j=i-n1;
0044     filter(i) = 0.5 * (1+cos((pi*j)/(range)));
0045     filter(NFFT-i+1) = 0.5 * (1+cos((pi*j)/(range)));
0046 end
0047 
0048 
0049 %Outer region of filter
0050 
0051 for i = n2+1 : n_points
0052     filter(i)=0;
0053     filter(NFFT-i+1)=0;
0054 end
0055 
0056 
0057 %figure
0058 %plot(filter)

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