Aliased Sampling

			
				% aliased sampling
				clc; clear;

				fi = 900; % signal freq

				fx = 10000; % oversampling
				tx = 0 : 1/fx : 1; % time vector over-sampled
				x = sin(2*pi*fi*tx); % signal

				X = fft(x,fx); % FFT
				X = abs(X(1:fx/2)); % single-sided
				Xdb = mag2db(X); % convert to dB
				Xdb = Xdb - max(Xdb); % scale ot 0dB
				fxvec = fx/2*linspace(0,1,fx/2); % frequency vector


				fy = 1000; % aliased sampling < 2*fi
				ty = 0 : 1/fy : 1; % time vector sampled under nyquist
				y = sin(2*pi*fi*ty); % aliased signal

				Y = fft(y,fy);
				Y = abs(Y(1:fy/2));
				Ydb = mag2db(Y);
				Ydb = Ydb - max(Ydb);
				fyvec = fy/2*linspace(0,1,fy/2);

				% plot oversampling
				subplot(4,1,1);
				stem(tx, x);
				grid on;
				xlim([0 0.01]);
				xlabel('time');
				ylabel('amplitude');
				title('oversampled');

				subplot(4,1,2);
				plot(fxvec,Xdb);
				grid on;
				xlabel('freq');
				ylabel('magnitude');
				title('fundamental at 900Hz');

				% plot aliased sampling
				subplot(4,1,3);
				stem(ty, y); 
				grid on;
				xlim([0 0.01]);
				xlabel('time');
				ylabel('amplitude');
				title('alias');

				subplot(4,1,4);
				plot(fyvec,Ydb);
				grid on;
				xlabel('freq');
				ylabel('magnitude');
				title('fundamental alias at 100Hz');
			
		
© 2018 Copyright. For individual use only. No liability is accepted for any consequences of using information on Testips.com.