C6: using the built-in convolution and cross-correlation functions
C6: using the built-in convolution and cross-correlation functions
One can compute the sum or difference of pairs of probability distributions using the built-in convolution and cross-correlation functions, respectively. Start with the distribution:
x=1:10; p=ones(1,10);
then compute the convolution of this with itself:
xS=2:20; pS=conv(p,p);
figure; subplot(2,1,1); hold on;
stem(xS,pS,'k.'); plot(xS,pS,'ko','MarkerFaceColor','k','MarkerSize',7)
And finally verify that the cross-correlation of this distribution with itself produces identical probabilities (but different x-coordinates):
subplot(2,1,2); hold on;
xD=-9:9; pD=xcorr(p,p);
stem(xD,pD,'k.'); plot(xD,pD,'ko','MarkerFaceColor','k','MarkerSize',7)
compute the difference
pS-pD