clc; close all; clear; % Define parameters T = 1/500; % Signal period fm = 1/T; % Signal frequency % Define sampling frequencies fs1 = 500; % Fs < 2F (Aliasing case) fs2 = 1000; % Fs = 2F (Critical Sampling) fs3 = 10000; % Fs > 2F (Oversampling) % Time vector (continuous) t = 0:1e-6:10*T; % High resolution for visibility % Continuous-time signal x = cos(2*pi*fm*t); % Define pulse width (short duration to approximate impulse) pulse_width = 1e-5; % Very narrow pulse % Create sample instants t1 = 0:1/fs1:max(t); % Sample times for Fs < 2F t2 = 0:1/fs2:max(t); % Sample times for Fs = 2F t3 = 0:1/fs3:max(t); % Sample times for Fs > 2F % Generate pulse trains pulses1 = pulstran(t, t1, @rectpuls, pulse_width); % Sampling with Fs < 2F pulses2 = pulstran(t, t2, @rectpuls, pulse_width); % Sampling with Fs = 2F pulses3 = pulstran(t, t3, @rectpuls, pulse_width); % Sampling with Fs > 2F % Sampled signals (multiplying by pulses) sampled1 = x .* pulses1; sampled2 = x .* pulses2; sampled3 = x .* pulses3; % Plot results figure; % Aliased signal (Fs < 2F) subplot(3,1,1); plot(t, sampled1, 'r'); hold on; xlabel('Time (s)'); ylabel('Amplitude'); title('Sampling with Fs < 2F (Aliasing)'); grid on; % Nyquist rate sampling (Fs = 2F) subplot(3,1,2); plot(t, sampled2, 'g'); hold on; xlabel('Time (s)'); ylabel('Amplitude'); title('Sampling with Fs = 2F (Critical Sampling)'); grid on; % Oversampling case (Fs > 2F) subplot(3,1,3); plot(t, sampled3, 'b'); hold on; xlabel('Time (s)'); ylabel('Amplitude'); title('Sampling with Fs > 2F (Oversampling)'); grid on;