function aliasDemo(n, max_x = 1, freq=10) x = max_x*(0:n-1)/n; f_of_x = @(t, fr) cos(2*pi*fr*t); y = f_of_x(x, freq); xs = 0:max_x/1000:max_x; ys = f_of_x(xs, freq); figure(1) plot(x, y, 'b*', xs, ys, 'b-', 'markersize', 4, 'linewidth', 2) Y = fft(y); f = (0:n/2)/max_x; pow = abs(Y(1:n/2+1)); fndFreq = find(pow == max(pow)); figure(2) plot([f;f], [0*pow;pow], 'r-', f,pow,'b*', 'linewidth',2, 'markersize',4) axis([-1 max(f)+1 0 pow(fndFreq)+1]) pause figure(1) hold on plot(xs, cos(2*pi*f(fndFreq)*xs), 'r-', 'linewidth', 2) hold off end