clc; clear all; close all;
format short
N=356;                                   %HMERES ENOS ETOYS
DAYS=5;                                  %KA8E D HMERES GINONTAI METRHSEIS 8ERMOKRASIAS
t=1:DAYS:N+1;                            %PINAKAS ME HMERES POY GINONTAI METRHSEIS 8ERMOKRASIAS
noise=10;                                %EPI TOIS EKATO PROS8ETIKOS 8ORYBOS STO SHMA
SHMA=sin((2*pi*(t-1))/(2*N));            %DHMIOYRGIA SHMATOS
T=SHMA+(noise*randn(length(t),1)./100)'; %PROS8ESH 8ORYBOY STO SHMA

%O PINAKAS T EMPERIEXEI TIS METRHSEIS 8ERMOKRASIWN ME 8ORYBO APO TO PERIBALON
N=length(T);                             %MHKOS PINAKA T
m=[1,1,1];                               %FILTRO E3OMALYNSHS, MPOREI NA AY3H8EI, ALLA PANTA PERITTOS ARI8MOS ASSWN
if (sum(m)~=0)                           %KANONIKOPOIHSH TIMWN FILTROY
    m=m/sum(m);
end

L=length(m);                             %MHKOS FILTROY
s=0;                                     %ARXIKOPOIHSH A8ROISTH
T2=T;                                    %DHMIOYRGIA NEOY PINAKA OPOY 8A APO8HKEY8OYN OI E3OMALYMENES TIMES

%FILTRARISMA TIMWN 8ERMOKRASIWN
p1=round(L/2-1);
zz=[zeros(p1,1)', T, zeros(p1,1)'];      %EPIMHKYNSH PINAKA
n=0;                                     %METRHTHS
for i=1+p1:N+p1                          %GIA KA8E TIMH TOY PINAKA
    s=sum(zz((i-p1):i+p1).*m(1:L));      %FILTRARISMA TIMHS 8RMOKRASIAS
    n=n+1;                               %AY3HSH A8ROISTH
    T2(n)=s;                             %APO8HKEYSH FILTRARISMENWN TIMWN STON PINAKA T2
end

T2=conv(T,m,'same'); %                   %ENTOLH MATLAB POY EKTELEI IDIO FILTRARISMA

%SXEDIASH SHMATWN, ARXIKOY KAI FILTRARISMENOY
figure(1);
plot(t,T,'-b','linewidth',1); 
hold on;
plot(t,T2,'-K','linewidth',2);
grid on;
legend('аявийо сгла','жиктяаяислемо сгла');
xlabel('глеяес');
ylabel('хеялойяасиа (╟C)');
title('жиктяаяисла хеялойяасиым')

