-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathGNGD_subFilter.m
57 lines (51 loc) · 1.97 KB
/
GNGD_subFilter.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
function [y,e] = GNGD_subFilter(input)
%% Generalized normalized gradient descent subfilter for use with Hybrid_Filter.m
% Based on Mandic: A generalized normalized gradient descent algorithm
% Inputs: input - input signal (1xN)
%
% Output: y - 1 step ahead prediction of input (1xN)
% e - filter prediction error (1xN)
%
% This program is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program. If not, see <http://www.gnu.org/licenses/>.
% Set filter parameters
order = 100; % Number of filter coefficients
mu = 0.1; % Learning rate of filter
rho = 0.15; % Regularisation parameter
ep = 0.01; % Initial value of regularisation term
% Initialize filter variables
w = zeros(order,1);
x = zeros(order,1);
y = zeros(1,length(input));
e = zeros(1,length(input));
for k=1:length(input)
% Store current input vector & regularisation value
x1 = x;
ep1 = ep;
% Create an input vector for the filter according to the filter length
for i = 1:order
if (k-i)>0
x(i) = input(k-i);
else
x(i) = 0; % Zero pad at the start of the signal
end
end
% Update filter
y(k) = x'*w;
e(k) = input(k) - y(k);
w = w + (mu/(x'*x + ep))*e(k)*x;
% Update regularisation term
if k>1
ep = ep - rho*mu*(e(k)*e(k-1)*x'*x1)/(x1'*x1 + ep1)^2;
end
end