forked from torstenmolitor/fourier-piano
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake_gif.m
28 lines (24 loc) · 764 Bytes
/
make_gif.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
function [] = make_gif(F,allFFTWindows,maxFFT,c_low,c_high,A,filename)
[nWindows, ~] = size(allFFTWindows);
h = figure;
hold on
axis tight manual % this ensures that getframe() returns a consistent size
plot_piano(maxFFT,c_low,c_high,A); % plot piano backdrop
for i = 1:nWindows
X = allFFTWindows(i,:);
fft_win = plot(log(F),X,'color','r', 'Linewidth', 3);
drawnow
% Capture the plot as an image
frame = getframe(h);
im = frame2im(frame);
[imind,cm] = rgb2ind(im,256);
% Write to the GIF File
if i == 1
imwrite(imind,cm,filename,'gif', 'Loopcount',inf);
else
imwrite(imind,cm,filename,'gif','WriteMode','append');
end
delete(fft_win) % delete current fft from plot
end
hold off
end