fs  = 1e6;
fx  = 50e3;
afs = 1;
N   = 100;

t = linspace(0, (N-1)/fs, N);
y = Afs * cos(2*pi*fx*t);
s = 20 * log10(abs(fft(y)/N/Afs*2));
s = s(1:N/2);
f = (0:length(s)-1) / N;

subplot(2, 1, 1);
plot(t, y);
xlabel('Time');
ylabel('Amplitude');
fixfig;
subplot(2, 1, 2);
plot(f, s, 'rx');
xlabel('Frequency  [ f / f_s ]');
ylabel('Magnitude  [ dBFS ]');
fixfig;
