% Convolution Comparison

a = [1 2 1 1];
b = [1 2 3 4 5];
N = 6;

regular = conv(a, b);

circular = cconv(a, b, N);

figure(1);
subplot(3,1,1);
stem(0:length(a)-1, a);
xlim([-10 15]);
title('Sequence A');

subplot(3,1,2);
stem(0:length(b)-1,b);
xlim([-10 15]);
title('Sequence B');

subplot(3,1,3);
stem(0:length(regular)-1, regular);
xlim([-10 15]);
title('A * B');

figure(2);
subplot(4,1,1);
stem(0:length(regular)-1, regular);
xlim([-10 15]);
title('A * B');

subplot(4,1,2);
stem(0+N:length(regular)-1+N, regular, 'g');
hold on;
stem(0-N:length(regular)-1-N, regular, 'r');
hold off;
xlim([-10 15]);
title('A * B shifted by + N and -N');


subplot(4, 1, 3);
stem(0:length(regular)-1, regular, 'b');
xlim([-10 15]);
hold on;
stem(0:length(circular)-1,circular, 'k', 'LineWidth', [2]);
stem(0+N:length(regular)-1+N, regular, 'g');
stem(0-N:length(regular)-1-N, regular, 'r');
hold off;
title('Showing Aliasing in time domain')

subplot(4,1,4);
stem(0:length(circular)-1,circular);
xlim([-10 15]);
title('A \circ B with modulo N');

