close all
clear all

ampli=sqrt(2*sqrt(10));
f=100;
T=1/f;
fe=500;
Te=1/fe;
t=[0:Te:2];
s=ampli*sin((2*pi/T)*t);
bruit=randn(size(t));
bruit=(bruit-mean(bruit))/std(bruit);
Pb=1;
%RSBdb=10*log10(ampli^2/2);
superposition=[s+bruit];

%Graph
subplot(221)
plot(t,s);
title('Sinusoide');
xlabel('t')
ylabel('y')
subplot(222)
plot(t,bruit);
title('Bruit');
xlabel('t')
ylabel('y')
subplot(223)
plot(t,superposition);
title('Superposition');
xlabel('t')
ylabel('y')

%Signal
%Methode for
E1=0;
for i=1:length(t)
    E1=E1+s(i)^2;
end

%Methode sum
E2=sum(s.^2);

%Methode produit
E3=s*s';

%puissance théorique
Psin=ampli^2/2;
Ptheorique=Psin*length(t);

%Signal bruité
%Methode for
E1b=0;
for i=1:length(t)
    E1b=E1b+superposition(i);
end

MoyE1=E1b/length(t);

%Methode sum
E2b=sum(superposition);
MoyE2b=E2b/length(t);

MoyE3b=mean(superposition);

