% script prediktor.m
%
% Undersöker prediktion av signalen bitcoin

load bitcoin
%load Ljud

signal = bitcoin;
%signal = ljud1{10};

figure(1);plot(signal);
title('Signaln som ska predikteras');

n = 1;

interval = (n+1):length(signal);
b = signal(interval)';
A = liu_NPrevSamples(signal,n)';
%A = [A;A.^2];
%A = [A;A.^2;tan(A);tan(A*2);tan(A*3)];

h = inv(A'*A)*A'*b
a_pred = A*h;

figure(2);plot(interval,b,'b',interval,a_pred,'r');
title('Signalen (blå), predikterad signal (röd)');

figure(3);plot(interval,b-a_pred);
title('Differens mellan signal och predikterad signal');

figure(4);plot(abs(h(1:end)),'-o');
title('Prediktionskoefficienter');

fprintf('Standardavvikelse för prediktionsfelet %f\n',std(b-a_pred));
