Professional Documents
Culture Documents
Democorrelacion PDF
Democorrelacion PDF
m 1 of 3
clear all
F=10;
t=0:1/F:(1/1)*1
%t=0:1:11;
a=sin(2*pi*1*t)
b = lagmatrix(a,0);
b(isnan(b)) = 0
b=b';
len = length(a);
if(len ~= length(b))
error('vectors supplied must be the same length');
end
figure
set(gcf, 'position', [ 285 347 642 367]);
plot_h = 0.25;
text_h = 0.1;
ax1 = subplot(2,1,1);
pl1_line = plot(a);
labels1 = text([1:len], a , num2str(a'), 'VerticalAlignment','bottom', ...
'HorizontalAlignment','right','fontsize',8);
hold on; pl1_dot = plot(a,'r.');
xlim([1 len])
ylim([min_amp max_amp])
ax2 = subplot(2,1,2);
pl2_line = plot(b);
labels2 = text([1:len], b , num2str(b'), 'VerticalAlignment','bottom', ...
'HorizontalAlignment','right','fontsize',7);
hold on; pl2_dot = plot(b,'r.');
xlim([1 len])
ylim([min_amp max_amp])
set(ax2,'visible','off')
set(ax2,'position', [(1/3) 0.9-plot_h*2 (1/3) plot_h])
27/09/14 09:48 AM C:\Users\mjuarezh\Documents\M...\demo1.m 2 of 3
str = '';
for k = 1: len
str = [str '(' num2str(a(k)) ')(' num2str(b(k)) ') + '];
end
str(end-1) = '=';
str = [str num2str(sum(a.*b))];
r_ba = xcorr(a,b);
pause
x_inc= (1/3)/(len-1);
for k = 1:len-1
str = '';
for m = 1: len-k
str = [str '(' num2str(a(m+k)) ')(' num2str(b(m)) ') + '];
end
str(end-1) = '=';
str = [str num2str(r_ba(len+k))];
'linestyle','none','verticalalignment','middle','horizontalalignment','left' ,'string',
{'Correlation' 'Sequence:'} ,'color','red');
end
annotation('textbox', [0.5+x_inc*k 0.01 1 text_h],
'linestyle','none','horizontalalignment','left' ,'string', [' ' num2str(k)]
,'color','blue', 'fontsize', 8);
pause
end
for k = 1:len-1
str = '';
for m = 1: len-k
str = [str '(' num2str(a(m)) ')(' num2str(b(m+k)) ') + '];
end
str(end-1) = '=';
str = [str num2str(r_ba(len-k))];
pause
end
% Uncomment the next two lines if you would like to see a plot of the
% correlation sequence
%[corr_seq lags] = xcorr(a,b);
%plot(lags,corr_seq)
%xlabel('lags');ylabel('correlation measure');