-
Notifications
You must be signed in to change notification settings - Fork 0
/
lpfilt.m
45 lines (38 loc) · 1.05 KB
/
lpfilt.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
function fdata = lpfilt(data,delta_t,cutoff_f)
% LPFILT Low-pass filter
%
% fdata = lpfilt(data,delta_t,cutoff_f)
%
% Peforms low-pass filter by multiplication in frequency domain.
% Uses three-point taper (in frequency space) between pass-band and
% stop band.
%
% Coefficients suggested by D. Coats, Battelle, Ventura.
% Even better coefficients for the taper can be found in:
% Rabiner, L.R., Gold,B., and McGonegal, C.A. (1980). An Approach to
% the approximation problem for nonrecursive digital filters. IEEE Tran.
% vol. AU-18(2):83-106.
% Chris Sherwood, USGS
% March 17, 1999
n = length(data);
%c = polyfit((1:n)',data,1);
%trend = polyval(c,1:n)';
%data = data-trend;
mn = mean(data);
data = data-mn;
P = fft(data);
N = length(P);
filt = ones(N,1);
k = floor(cutoff_f*N*delta_t);
filt(1:k) = filt(1:k)*1;
filt(k+1) = .715;
filt(k+2) = .24;
filt(k+3) = .024;
filt(k+4:N-(k+4)) = filt(k+4:N-(k+4))*0.;
filt(N-(k+3)) = .024;
filt(N-(k+2)) = .24;
filt(N-(k+1)) = .715;
P = P .* filt;
fdata = real(ifft(P));
fdata = fdata(1:n)+mn;
%fdata = fdata(1:n)+trend;