A função de correlação entre dois sinais é uma medida da dependência temporal entre eles. Se
tais sinais forem independentes, a função de correlação cruzada (FCC) será pequena
(estatisticamente zero) para todos os valores e diz-se que esses sinais são não-correlacionados.
A função de autocorrelação (FAC) possui o mesmo período que a função original. A FAC de
qualquer sinal periódico é também periódica, com o mesmo período. A função de autocorrelação
de uma variável aleatória é igual a zero.
As FAC e FCC são robustas ao ruído. Elas podem revelar a correlação existente em sinais
imersos em ruído.
Exercícios
2) Crie um sinal u(k) = Acos(wk) + e1(k) e um sinal y(k) = Asen(wk) +e2(k), sendo e1(k) e e2(k)
variáveis aleatórias.
a) Plote, em um gráfico com duas janelas, o sinal u(k) e o sinal y(k). Visualmente, existe
correlação entre estes sinais?
b) Faça a FCC entre u(k) e y(k). Os dois sinais são correlacionados?
c) Comente sobre a robustez da FCC ao ruído.
No uso estatístico geral, correlação se refere à medida da relação entre duas variáveis, embora
correlação não implique causalidade.
Coeficiente de correlação
Se tivermos uma matriz em que cada coluna contém observações de uma variável, podemos
calcular os coefcientes de correlação entre as variáveis desta matriz usando o comando
>> R = corrcoef(X)
1) Deseja-se estudar as variáveis peso (y) e altura (x) em uma amostra de 12 homens
adultos. Os valores são apresentados na tabela 1
corrcoef(altura,peso)
2) Crie uma senóide, faça a FAC dela e calcule seu coeficiente de correlação.
3) Crie um sinal aleatório, faça a FAC dele e calcule seu coeficiente de correlação.
randn(n,m)
function [t,r,l,B]=myccf(c,lag,flag1,flag2,cor);
% [t,r,l]=myccf(c,lag,flag1,flag2,cor);
% c1=c(:,1); c2=c(:,2);
% the ccf are calculated from -lag/2 to lag/2 if flag1 = 1;
% the ccf are calculated from 0 to lag if flag1 = 0;
% plots the ccf between c1 and c2 if flag2 = 1;
% if flag2=0 the ccf is returned in r (with respective
% lags in t), but not plotted;
% l is a scalar, the 95% confidence interval is +-l;
% if cor='w', white lines are used. If cor='k', black.
% r*B is the unnormalized value of r.
%
% in case of intending the FI(eu) plot c MUST be =[e u]
if flag1==1,
lag=floor(lag/2);
end;
c1=c(:,1);
c1=c1-mean(c1);
c2=c(:,2);
c2=c2-mean(c2);
cc1=cov(c1);
cc2=cov(c2);
m=floor(0.1*length(c1));
r12=covf([c1 c2],lag+1);
t=0:1:lag-1;
l=ones(lag,1)*1.96/sqrt(length(c1));
% ccf
B=sqrt(cc1*cc2);
r=[raux(1:length(raux)-1) r12(2,:)]/B;
% if plot
if flag2 == 1,
% if -lag to lag
if flag1 == 1,
t=-(lag):1:lag;
l=ones(2*lag+1,1)*1.96/sqrt(length(c1));
if cor=='w'
plot(t,r,'w-',t,l,'w:',t,-l,'w:',0,1,'w.',0,-1,'w.');
else
plot(t,r,'k-',t,l,'k:',t,-l,'k:',0,1,'k.',0,-1,'k.');
end;
xlabel('lag');
else
t=0:lag;
l=ones(lag+1,1)*1.96/sqrt(length(c1));
if cor=='w'
plot(t,r12(2,1:lag+1)/B,'w-',t,l,'w:',t,-l,'w:',0,1,'w.',0,-1,'w.');
else
plot(t,r12(2,1:lag+1)/B,'k-',t,l,'k:',t,-l,'k:',0,1,'k.',0,-1,'k.');
end;
xlabel('lag');
end;
else
% if -lag to lag, but no plots
if flag1 == 1,
t=-(lag):1:lag;
else
t=0:lag;
r=r12(2,1:lag+1)/B;
end;
end;
l=l(1);
_
Exercício
t = [0:0.01:5];
a = sin(2*pi*t);
figure(1)
plot(t,a)
v = randn(length(t),1);
figure(2)
plot(t,v)
c = 3*t + 2;
figure(3)
plot(t,c)
d = a' + v + c';
figure(4)
plot(t,d)
ccf([a' a'],500,1,5);
title('Autocorrelaçao da funçao senoidal')
ccf([v v],500,1,6);
title('Autocorrelaçao do sinal aleatorio')
ccf([c' c'],500,1,7);
title('Autocorrelaçao da tendencia')
ccf([d d],500,1,8);
title('Autocorrelaçao da soma das funçoes (1 caso)')