T=5; % fundamental period
Np = 512; % number of points for plotting
t=linspace(0,T,Np+1);t=t(1:Np); % fine resolution time, for plotting
N= 16; % number of sampling points
Ts = T/N; % sampling interval
fs = 1/Ts; % sampling frequency
ts = Ts*(0:(N-1)); % instants when sampling accours
Nf = 1/(2*Ts); % Nyquist frequency
f = k/T; % true frequency of the signal
x = sin(2*pi*f*t); % signal, high resolution
xs = sin(2*pi*f*ts); % signal, sampling resolution
% find fapp, such that f=n*fs+fapp
n = round(f/fs);
fapp = f-n*fs;
xa = sin(2*pi*fapp*t);
plot(t,[x;xa],ts,xs,'o');
str1 = ['fs=',num2str(fs),' Nf=',num2str(Nf)];
str2 = ['k=',num2str(k),' f=',num2str(f),' fapp=',num2str(fapp)];
str =[str1, ' ',str2];
title(str);