% alias.m % demonstrate alising effect % copyright (c) 1997 by Yu Hen Hu % % x(t) = cos(2*pi*F*t) is continuous time signal where F is the % continuous time frequence, t is the time variable % y(n) = x(nT) = cos(2*pi*F*n*T)= cos(2*pi*fd*n) is sampled signal. % where T = 1/fs is sampling period % fd = FT is discrete frequency % Plot range -rg ms to rg ms % created: 9/29/97 clear all F=60; fs = 100; toend=0; while toend==0, disp(['curret continuous freq. F = ' num2str(F) '; sampling freq fs = ' ... num2str(fs) '.']); change=input('If want to change, enter 1: '); if change == 1, tmp=input('enter [F fs]: '); F=tmp(1); fs=tmp(2); end T = 1000/fs; % T in ms is sampling period. fd = F*T*.001; % discrete time frequence rg=10*T; drg=rg/500; % rg in ms! plot 10 samples each side. trange=[-rg:drg:rg]; % plot range in continuous time in ms! % symmetric w.r.t. origin xrange=[-rg/T:rg/T]; % corresponding range in discrete time samples xt=cos(2*pi*F*0.001*trange); xn=cos(2*pi*fd*xrange); figure(1); hold off; clf; set(1,'Position',[26 304 710 248]); hold on; plot(trange,xt,'-'); stem(xrange*T,xn); plot(xrange*T,xn,':'); xlabel('t (ms)'); ylabel('x(t) and x(n)') title('Illustration of Aliasing Effect') toend=input('To plot for another set of frequencies, enter 0: '); end