% file:      	upsampling_2.m, (c) Matthew Roughan, Thu Aug  5 2004
%
N = 32;
x = (1:N)/N;
f1 = 3.4;
y1 = sin(2*pi*f1*x);
K = 3; % upsample by 3
upsample = zeros(1,length(y1)*K);
upsample(K*(1:length(y1))) = y1;
x_u = (1:K*N)/(K*N);

figure(2)
subplot(2,1,1);
hold off
plot([x_u; x_u], [zeros(size(upsample)); upsample],'b', 'linewidth', 3);
hold on
plot(x_u, upsample, 'bo', 'linewidth', 4);
set(gca, 'linewidth', 3, 'fontsize', 18);
ylabel('signal');
set(gca, 'ylim', [-1.2 1.2], 'xlim', [0 max(x)], 'xtick', [], 'ytick', []);

z2 = fftshift(abs(fft(upsample)).^2);
subplot(2,1,2);
hold off
plot([-K*N/2:K*N/2-1; -K*N/2:K*N/2-1], [zeros(1, K*N); z2], 'b', 'linewidth', 4);
hold on
plot(-K*N/2:K*N/2-1, z2, 'bo', 'linewidth', 3);
set(gca, 'linewidth', 3, 'fontsize', 18);
set(gca, 'xlim', [-K*N/2 K*N/2], 'ytick', []);
ylabel('power');
xlabel('frequency');

set(gcf, 'PaperUnits', 'centimeters', 'PaperPosition', [0 0 30 15])
print('-depsc', 'Plots/upsampling_1.eps');
