How to Sample Continuous Signals and Avoid Aliasing in MATLAB?

Illustration
support - 2026-07-24T11:29:40+05:30
Question: How to Sample Continuous Signals and Avoid Aliasing in MATLAB?

How to demonstrate Nyquist-Shannon sampling theorem (fs >= 2 f_max) and aliasing in MATLAB?

Expert Answer

Profile picture of John Williams John Williams answered . 2026-07-24

This MATLAB script demonstrates proper Nyquist sampling vs undersampling (aliasing):

f_signal = 10; % 10 Hz continuous signal
t_cont = 0:0.0001:0.5;
x_cont = sin(2*pi*f_signal*t_cont);

% 1. Proper Sampling (fs = 50 Hz > 2*10 Hz)
fs1 = 50;
t_sample1 = 0:1/fs1:0.5;
x_sample1 = sin(2*pi*f_signal*t_sample1);

% 2. Undersampling / Aliasing (fs = 12 Hz < 20 Hz)
fs2 = 12;
t_sample2 = 0:1/fs2:0.5;
x_sample2 = sin(2*pi*f_signal*t_sample2);

figure;
plot(t_cont, x_cont, 'k--'); hold on;
stem(t_sample1, x_sample1, 'g', 'filled');
stem(t_sample2, x_sample2, 'r', 'filled');
legend('Continuous (10Hz)', 'Proper Sampled (50Hz)', 'Aliased Sampled (12Hz)');


Not satisfied with the answer ?? ASK NOW

Get a Free Consultation or a Sample Assignment Review!