Skip to Main Content Skip to Search
Home |   Select Country  Choose Country  |  Contact Us  |  Cart Store 
Create Account | Log In
Products & Services Industries Academia Support User Community Company

 

Student Center

Solution: Investigate the behavior of sampling a signal and reconstructing it


figure 1
Figure 1: Sine Wave Signal.

figure 2
Figure 2: Sampled Sine Wave Signal.

% First Create the Signal to be sampled (Sine Wave)
t = 0:0.01:2;
A = 2;
fn = 1.0;
Sig = A * sin(2*pi*fn*t);
% Sampling Interval
% Signal Amplitude
% Signal Frequency
% Signal to be Sampled
figure;
plot(t,Sig);
xlabel('Time (sec)');
ylabel('Signal Amplitude')
title('Signal To Be Sampled: fn = 1.0 Hz, A = 2);

(Answer)
figure 3


% Now Sample the Signal at different frequencies
Fs = 8;
Count = 0;
while Count < 5
% Sampling Frequency (Hz)
% Loop Counter
% Show 5 Different Sampled Frequencies

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 for

Sampled_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

figure 4

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.

figure 5

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.

figure 6

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.

figure 7

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.

figure 8

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.

Contact sales
Software evaluation for instructors
Free technical kit
E-mail this page

MATLAB & Simulink Student Version

Includes full-featured versions of both MATLAB and Simulink

From School To Industry

"The only limit to MATLAB is your imagination."
Carl Klopstein
Radar Systems Engineer

Free Code for LEGO MINDSTORMS NXT

LEGO® MINDSTORMS® NXT robotics invention system lets you create and control robots using programmable motors and sensors