6.1
close all;
clear all;
%a)
y1=[zeros(1,10) ones(1,10) zeros(1,40)];
subplot(3,1,1);
stem(y1);
E1=sum(y1.^2)
subplot(3,1,2);
n2=1:1:10;
y2=[2*n2 zeros(1,50)];
stem(y2);
E2=sum(y2.^2)
subplot(3,1,3);
y3=[zeros(1,49) ones(1,1) zeros(1,10)];
stem(y3);
E3=sum(y3.^2)
%b)
figure;
subplot(3,1,1);
correl1=corr(y1,y1);
plot(correl1);
subplot(3,1,2);
correl2=corr(y2,y2);
plot(correl2);
subplot(3,1,3);
correl3=corr(y3,y3);
plot(correl3);
Maximum1=max(correl1)
Maximum2=max(correl2)
Maximum3=max(correl3)
%On remarque que la valeur de chaque énergie est égale à la valeur max de
%chaque autocorrélation
%c)
figure;
subplot(3,1,1);
intercor1=corr(y1,y2);
plot(intercor1);
subplot(3,1,2);
intercor2=corr(y1,y3);
plot(intercor2);
subplot(3,1,3);
intercor3=corr(y2,y3);
plot(intercor3);
6.2
close all;
clear all;
load correl_data.mat
%a)
subplot(3,1,1);
plot(dsss);
title('Signal dsss');
subplot(3,1,2);
plot(cs1, '-r');
title('Signal cs1');
subplot(3,1,3);
plot(cs2);
title('Signal cs2');
Ecs1=sum(cs1.^2)
Ecs2=sum(cs2.^2)
%b)
figure;
cor1=corr(dsss,cs1); %intercorrélation entre le signal mutltiplexé et le code le plus long cs1
plot(cor1);
function r=corr(x,y)
b=length(y); % longueur de y
x=[x zeros(1,b)]; % x = x suivit d'autant de zéros que b
a=length(x); % longueur de x
buff=zeros(1,b); % initialisation du buffer
z=[];
for k=1:a % k allant de 1 à longueur de x
buff=[buff(2:end) x(k)]; % buff = buff suivit de x
r(k)=sum(y.*buff); % corrélation de y avec buff
end