% Priklad na pouzivanie MA filtra:

SignalSinus=sin(linspace(1,6*pi,300))


% Najprv sa pozrime, ako poskodi MA filter povodny harmonicky
% signal pri roznych velkostiach okienka:

plot(SignalSinus);  hold on;
plot(movingaverage(SignalSinus,5));
plot(movingaverage(SignalSinus,25));
plot(movingaverage(SignalSinus,100));


% Teraz uz naozaj ideme filtrovat. Vidno, ze ak jed MA filter
% normalny cisty signal mierne tlmi, tuto sa to neprejavi, pretoze
% sum niektore hodnoty rozhodi aj smerom nahor, aj nadol. Takze
% vyfiltrovany sinus je niekedy aj vacsi ako povodny...

clg;

noise    = 0 + 0.1 * randn(size(SignalSinus)); % \mu = 0, \sigma = 0.1

plot(SignalSinus+noise); hold on;
plot(movingaverage(SignalSinus+noise,10),"r");
plot(SignalSinus,"g");



% Teraz ideme filtrovat realne data z teplomera:

clg;
data; % nacita vektor temperature s teplotami:


t1 = movingaverage(temperature(:,2)',10);  % skus rozlicne M = 10, 30, 100
plot(t1);
hold on;
plot(temperature(:,2),"g");
