Created
July 26, 2017 03:09
-
-
Save stephenHartzell/06b94963ee8e8047e354d6b264ad2eb4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| % The convolution is calculated as shown in this figure | |
| f_pad = f; | |
| g_pad = [g, zeros(1,length(f)-length(g))]; | |
| g_pad = circshift(fliplr(g_pad)',1)'; | |
| MF = zeros(1,length(f_pad)); | |
| figure('Position',[100 100 850 600]) | |
| v = VideoWriter('test.avi','Uncompressed AVI'); | |
| v.FrameRate = 1; | |
| open(v) | |
| MF(1) = sum(f_pad.*g_pad); | |
| subplot(2,1,1), stem(f_pad,'r','filled') | |
| title('Flip and Shift') | |
| hold on | |
| stem(g_pad,'m','filled') | |
| legend('f','g flipped') | |
| xlim([-1,length(f_pad)+1]) | |
| ylim([-2,9]) | |
| hold off | |
| subplot(2,1,2), stem(MF,'b','filled') | |
| xlim([-1,length(f_pad)+1]) | |
| ylim([-10,50]) | |
| set(gca,'NextPlot','replacechildren'); | |
| F(1:length(f_pad)) = struct('cdata', [], 'colormap', []); | |
| for j = 1:length(f_pad) | |
| MF(j) = sum(f_pad.*g_pad); | |
| subplot(2,1,1), stem(f_pad,'r','filled') | |
| hold on | |
| stem(g_pad,'m','filled') | |
| title('Flip and Shift') | |
| legend('f','g fliped') | |
| xlim([-1,length(f_pad)+1]) | |
| ylim([-2,9]) | |
| hold off | |
| subplot(2,1,2), stem(MF,'b','filled') | |
| title('Circular Convolution of f and g') | |
| xlim([-1,length(f_pad)+1]) | |
| ylim([-10,50]) | |
| frame = getframe(gcf); | |
| writeVideo(v, frame.cdata); | |
| g_pad = circshift(g_pad',1)'; | |
| end | |
| close(v) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment