N = 64;                       % length of signal
fs = 1;                       % sampling rate of 1
f1 = 0.25;                    % frequency on fft bin
f2 = 0.25 + 0.5/N;            % move frequency up 1/2 bin
x1 = cos(2*pi*f1*[0:N-1]/fs); % signal to analyze
x2 = cos(2*pi*f2*[0:N-1]/fs); % signal to analyze
X1 = abs(fft(x1));
X2 = abs(fft(x2));

subplot(411);
plot([x1 x1], 'linewidth', 2);                % waveform repeated once
title('Sinusoid at f=0.25 Hz, repeated once', 'fontsize', 14);
xlabel('Time (s)', 'fontsize', 14);
ylabel('Amplitude', 'fontsize', 14);
subplot(412);
plot([x2 x2], 'linewidth', 2);                % waveform repeated once
title('Sinusoid at f=0.25 + 0.5/N Hz, repeated once', 'fontsize', 14);
xlabel('Time (s)', 'fontsize', 14);
ylabel('Amplitude', 'fontsize', 14);
subplot(413);
stem([0:N-1]/N, X1, 'linewidth', 2);
title('Sinusoid at f=0.25 Hz', 'fontsize', 14);
ylabel('Magnitude (linear)', 'fontsize', 14);
subplot(414);
stem([0:N-1]/N, X2, 'linewidth', 2);
title('Sinusoid at f=0.25 + 0.5/N Hz', 'fontsize', 14);
ylabel('Magnitude (linear)', 'fontsize', 14);
xlabel('Frequency (normalized)', 'fontsize', 14);



%print(gcf, '-depsc', 'betweenBins.eps');