-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathnoncausalFiltering.m
42 lines (31 loc) · 1.08 KB
/
noncausalFiltering.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
41
42
function filteredData = noncausalFiltering(data,noncausalFilter,filteringMethod)
if nargin == 2
filteringMethod = 'filter';
% filteringMethod = 'conv';
end
if strcmp(filteringMethod ,'filter')
forwardOrder = numel(zero(noncausalFilter)) - numel(pole(noncausalFilter));
noncausalFilter.Variable = 'z^-1';
Ts = noncausalFilter.Ts;
z = tf('z',Ts);
causalFilter = noncausalFilter * z^(-1*forwardOrder);
casualFilter= minreal(causalFilter);
figure;impulse(causalFilter);
[b,a] = tfdata(causalFilter,'v');
filteredData = filter(b,a,data);
filteredData = circshift(filteredData,-1*forwardOrder);
elseif strcmp(filteringMethod,'conv')
forwardOrder = numel(zero(noncausalFilter)) - numel(pole(noncausalFilter));
noncausalFilter.Variable = 'z^-1';
Ts = noncausalFilter.Ts;
z = tf('z',Ts);
causalFilter = noncausalFilter * z^(-1*forwardOrder);
casualFilter= minreal(causalFilter);
num = numel(data);
[h,t] = impulse(causalFilter,(num -1) * Ts);
h = h * Ts;
filteredData = conv(h,data);
filteredData = filteredData(1:num);
filteredData = circshift(filteredData,-1*forwardOrder);
end
end