Skip to content

Commit

Permalink
individual sinc demo
Browse files Browse the repository at this point in the history
  • Loading branch information
steven2358 committed Oct 15, 2013
1 parent 4c2f09b commit 193b122
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions demo/demo_sinc.m
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]);

0 comments on commit 193b122

Please sign in to comment.