Student Center
Solution: Investigate the behavior of sampling a signal and reconstructing it
![]() |
| Figure 1: Sine Wave Signal. |
![]() |
| Figure 2: Sampled Sine Wave Signal. |
% First Create the Signal to be sampled (Sine Wave)
t = 0:0.01:2; |
% Sampling Interval |
figure;
plot(t,Sig);
xlabel('Time (sec)');
ylabel('Signal Amplitude')
title('Signal To Be Sampled: fn = 1.0 Hz, A = 2);(Answer)

% Now Sample the Signal at different frequencies
Fs = 8; |
% Sampling Frequency (Hz) |
Sampler = square(2*pi*Fs*t); % Generating Pulses
%// Shift the Sampling Signal to All Positive values
for i = 1:length(Sampler)
Sampler(Sampler == -1) = 0;
end; % end forSampled_Sig = Sampler.* Sig; % Sample the Sine Wave (Signal)
figure;
% Subplot the sampled signal
subplot(2,1,1)
plot(t,Sampler, 'g-')
xlabel('Time (sec)')
ylabel('Sampling Signal Magnitude');
grid;
% Title each of the figures with the appropriate sampling frequency
samfreq = num2str(8/(2^Count));
t1 = 'Sampling Frequency: ';
t2 = ' Hz';
titlecat = [t1, samfreq, t2];
title(titlecat);
% Subplot the reconstructed signal
subplot(2,1,2)
plot(t,Sampled_Sig,'m-')
xlabel('Time (sec)')
ylabel('Sampling Value');
grid;
% Title each figure with the appropriate sampling frequency: Aliased or
% Non-Aliased
title3 = ['Fs = ', samfreq];
switch Count
case (0)
title(strcat(title3, ' Signal Can Be Reproduced'));
case (1)
title(strcat(title3, ' Signal Can Be Reproduced'));
case (2)
title(strcat(title3, ' Signal Can Be Reproduced'));
% at the Nyquist Frequency
case (3)
title(strcat(title3, ' Aliasing Occurs'));
case (4)
title(strcat(title3, ' Very Severe Aliasing'));
otherwise
disp('Counter is Off')
end
Count = Count + 1; % Increment the Counter
Fs = Fs/2; % Decreasing Sampling Frequency by half
end; % end while

Comment: In this figure, we can see that the signal is sampled eight times the sampling frequency (fs = 8 Hz). At this sampling frequency we obtain a large number of samples and because of this, we can very accurately reproduce the original signal.

Comment: In this figure, we notice that the signal is sampled at a decent sampling frequency (fs) of 4 Hz. Therefore, we will be able to accurately reassemble this signal and recover all the information it contains.

Comment: In this figure, we can also determine that the signal is sampled at an adequate sampling frequency (fs) of 2 Hz which is at the Nyquist frequency. Therefore, we will be able to recover this signal completely and recover all the information it contains.

Comment: In this figure, we can deduce that the signal is sampled at a sampling frequency (fs=1 Hz) which is not good enough for complete recovery of the signal. The behavior we are seeing is a phenomenon called aliasing. Aliasing is when you under sample your signal and therefore do not get enough samples for an accurate reconstruction.

Comment: In this figure, we are seeing an even more extreme case of a signal that is not sampled at a sampling frequency (fs = 0.5 Hz) that is good enough for any recovery of the signal. What were are seeing here is an extreme case of aliasing.
Store

