function aliasing_demo
clf;
clear all;

Fsmin = 0.01;
Fsmax = 10;
F0min = 0;
F0max = 20;

Fs = 10;
F0 = 0.5;

show_alias(Fs,F0);

hui=uicontrol('style','slider','value',Fs,'min',Fsmin,'max',Fsmax, ...
              'SliderStep',[0.001,0.001], ...
              'position',[10 10 300 20],'callback',{@nestfunc});
set(hui)
%huj=uicontrol('style','slider','value',F0,'min',F0min,'max',F0max, ...
%              'position',[400 10 300 20],'callback',{@nestfunc});


function nestfunc(src,evd)
Fs = get(hui,'Value');
%F0 = get(huj,'Value');
show_alias(Fs,F0)
end

function show_alias(Fs,F0)
fa = F0/Fs;
fa = fa - floor(fa+0.5);
Fa = fa*Fs;
disp([F0 Fa Fs]);

Fs0 = 1000;
T = 10;
t = [0:1/Fs0:T];
n = [0:1/Fs:T];
x = cos(2*pi*F0*t);
y = cos(2*pi*F0*n);
z = cos(2*pi*Fa*t);

hx = plot(t,x,'b'); hold on;
hz = plot(t,z,'Color',[0 0.5 0]);
hy = stem(n,y,'r','filled'); hold off;
axis([0 T -1.2 1.2]);
title('Move the slider to change the sample rate');
end

end
