-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4c2f09b
commit 193b122
Showing
1 changed file
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
% Demo: learn a sinc. Run one algorithm using its default parameters. | ||
% | ||
% This file is part of the Kernel Adaptive Filtering Toolbox for Matlab. | ||
% http://sourceforge.net/projects/kafbox/ | ||
|
||
close all | ||
clear all | ||
rs = 1; randn('state',rs); rand('state',rs); %#ok<RAND> | ||
|
||
%% PARAMETERS | ||
|
||
N = 1000; % number of training data | ||
N_test = 500; % number of test data | ||
SNR = 20; % SNR in dB | ||
|
||
algorithm = 'aldkrls'; | ||
|
||
%% GENERATE DATA | ||
x = randn(N,1); | ||
x_test = linspace(min(x),max(x),N_test)'; | ||
y_ref = sinc([x;x_test]); | ||
y = y_ref + sqrt(10^(-SNR/10)*var(y_ref))*randn(N+N_test,1); | ||
y_test = y_ref(N+1:N+N_test); | ||
|
||
%% RUN ALGORITHM | ||
fprintf('%s: ',upper(algorithm)); | ||
Y_est = zeros(N_test,1); | ||
kaf = feval(algorithm); | ||
t1 = tic; | ||
for i=1:N, | ||
if ~mod(i,floor(N/10)), fprintf('.'); end | ||
kaf = kaf.train(x(i),y(i)); | ||
end | ||
y_est = kaf.evaluate(x_test); | ||
MSE = mean((y_test-y_est).^2); | ||
|
||
%% OUTPUT | ||
|
||
fprintf(' %.2fs. MSE=%3.2fdB\n',toc(t1),10*log10(MSE)) | ||
|
||
figure; hold all | ||
plot(x,y(1:N),'.') | ||
|
||
plot(x_test,y_est,'LineWidth',2) | ||
legend({'data',strrep(upper(algorithm),'_','-')}) | ||
axis([min(x)-0.5 max(x)+0.5 min(y)-0.5 max(y)+0.5]); |