clear all
close all

% generate data example
dt = 0.01
f=1/dt
duration = 1.0
df=1/duration
n = duration / dt

dt_sample=0.05
f_sample=1/dt_sample;
df_sample=1/duration
step_sample = dt_sample / dt
n_sample=n / step_sample

f1 = 8.0
f2 = 15.0
t = linspace(0,duration-dt,n);
t_sample = linspace(0,duration-dt,n_sample);
x1 = sin(2*pi*f1*t+1.0);
x2 = sin(2*pi*f2*t);
x=x1+x2

x_sample = zeros(1,n_sample);
for j = 1:n_sample
   x_sample(1,j)=x((j-1)*step_sample+1) 
end

figure(1)
subplot(2,1,1)
plot(t,x,t_sample,x_sample,'r-*')
xlabel('time')
ylabel('x,x(sample)')

% subplot(3,1,2)
% % compute FT
% ft=fft(x);
% ft_sample=fft(x_sample);
% freq = linspace(0,f/2-df,n/2);
% freq_sample = linspace(0,f_sample/2-df_sample,n_sample/2);
% plot(freq_sample,abs(ft_sample(1:n_sample/2)),'-*')
% xlabel('frequency')
% ylabel('amplitude power')

subplot(2,1,2)
% compute FT
ft=fft(x);
ft_sample=fft(x_sample);
freq = linspace(0,f/2-df,n/2);
freq_sample = linspace(0,f_sample/2-df_sample,n_sample/2);
plot(freq(1:25),abs(ft(1:25)),freq_sample,abs(ft_sample(1:n_sample/2)),'r-*')
xlabel('frequency')
ylabel('amplitude power')

% figure(2)
% %x_sample_alias = zeros(1,n_sample);
% x_sample_alias=sin(2*pi*f2*t_sample); 
% plot(t_sample,x_sample,'r-*',t_sample,x_sample_alias,'g-*')
% xlabel('time')
% ylabel('x(sample),x(alias)')
