-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfilt_hp.m
More file actions
28 lines (23 loc) · 813 Bytes
/
filt_hp.m
File metadata and controls
28 lines (23 loc) · 813 Bytes
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
function [ filtdata ] = filt_hp( data, n, wp )
%FILT_HP Filters data using a high-pass Butterworth filter
% Frequency wp is in Hz, n is poles.
% Data is passed with colums of [time, sig1, sig2, ...], and
% returns the same array but with the data filtered.
% extract si. easier than passing each time
si = data(2,1)-data(1,1);
% convert from absolute frequency to 'normalized frequency'
% which is 0 at 0 and 1 at Nyquist freq 1/(2*si)
wn = 2*wp*si;
if (wn > 1)
filtdata = data;
return
end
% create the filter coefficients
[b a] = butter(n, wn, 'high');
% copy
filtdata = data;
% and replace data portion for all dimensions
for i=2:size(filtdata,2)
filtdata(:,i) = filtfilt(b,a,data(:,i));
end
end