% alias.m - aliasing due to undersampling % HJSIII - 98.11.05 clear % actual sampling rate 200 Hz fs = 200; % sampling rate for display fsfast=2000; % sampling times dt = 1 / fs; dtfast = 1 / fsfast; % fill sample buffers tend = 0.1; ns = tend / dt; nsfast = tend / dtfast; ts = (0:ns) * dt; v30 = sin( 2 * pi * 30 * ts ); v60 = sin( 2 * pi * 60 * ts ); v90 = sin( 2 * pi * 90 * ts ); v120 = sin( 2 * pi * 120 * ts ); v150 = sin( 2 * pi * 150 * ts ); v180 = sin( 2 * pi * 180 * ts ); v210 = sin( 2 * pi * 210 * ts ); v240 = sin( 2 * pi * 240 * ts ); tsfast = (0:nsfast) * dtfast; v30fast = sin( 2 * pi * 30 * tsfast ); v60fast = sin( 2 * pi * 60 * tsfast ); v90fast = sin( 2 * pi * 90 * tsfast ); v120fast = sin( 2 * pi * 120 * tsfast ); v150fast = sin( 2 * pi * 150 * tsfast ); v180fast = sin( 2 * pi * 180 * tsfast ); v210fast = sin( 2 * pi * 210 * tsfast ); v240fast = sin( 2 * pi * 240 * tsfast ); % plot time domain figure( 1 ) subplot(4,2,1) plot( ts, v30, ts, v30, 'o', tsfast, v30fast, ':' ) title('30/60/90/120 Hz sampled at 200 Hz') % xlabel('Time (sec)') % ylabel('Amplitude') subplot(4,2,3) plot( ts, v60, ts, v60, 'o', tsfast, v60fast, ':' ) % title('60 HZ sine sampled at 200 Hz') % xlabel('Time (sec)') % ylabel('Amplitude') subplot(4,2,5) plot( ts, v90, ts, v90, 'o', tsfast, v90fast, ':' ) % title('90 HZ sine sampled at 200 Hz') % xlabel('Time (sec)') % ylabel('Amplitude') subplot(4,2,7) plot( ts, v120, ts, v120, 'o', tsfast, v120fast, ':' ) % title('120 HZ sine sampled at 200 Hz') xlabel('Time (sec)') % ylabel('Amplitude') subplot(4,2,2) plot( ts, v150, ts, v150, 'o', tsfast, v150fast, ':' ) title('150/180/210/240 Hz sampled at 200 Hz') % xlabel('Time (sec)') % ylabel('Amplitude') subplot(4,2,4) plot( ts, v180, ts, v180, 'o', tsfast, v180fast, ':' ) % title('180 HZ sine sampled at 200 Hz') % xlabel('Time (sec)') % ylabel('Amplitude') subplot(4,2,6) plot( ts, v210, ts, v210, 'o', tsfast, v210fast, ':' ) % title('210 HZ sine sampled at 200 Hz') % xlabel('Time (sec)') % ylabel('Amplitude') subplot(4,2,8) plot( ts, v240, ts, v240, 'o', tsfast, v240fast, ':' ) % title('240 HZ sine sampled at 200 Hz') xlabel('Time (sec)') % ylabel('Amplitude') % plot frequency domain figure( 2 ) f0 = fs / 2; f = 0 : 400; fsym = [ 30 60 90 120 150 180 210 240 270 300 330 360 390 ]; a = f0 - abs( mod(f,fs) - f0 ); asym = f0 - abs( mod(fsym,fs) - f0 ); plot( f, a, fsym, asym, 'o' ) title( 'Aliasing = fs/2 - abs( mod(f,fs) - fs/2 )' ) xlabel( 'Actual frequency [Hz]' ) ylabel( 'Apparent frequency [Hz] for fs=200 Hz' )