DSP Lab # 8 Sampling in Time Domain: Questions
DSP Lab # 8 Sampling in Time Domain: Questions
t = 0:0.0005:1;
f = 13;
xa = cos(2*pi*f*t);
subplot(2,1,1)
plot(t,xa);grid
xlabel('Time, msec');
ylabel('Amplitude');
title('Continuous-time signal x_{a}(t)');
axis([0 1 -1.2 1.2])
subplot(2,1,2);
T = 0.1;
n = 0:T:1;
xs = cos(2*pi*f*n);
k = 0:length(n)-1;
stem(k,xs); grid
xlabel('Time index n');
ylabel('Amplitude');
title('Discrete-time signal x[n]');
axis([0 (length(n)-1) -1.2 1.2])
Questions
Q1.1 What is the frequency in Hz of the sinusoidal signal? What is the sampling period in
seconds?
Q1.2 Repeat the program by changing the frequency of the sinusoidal signal to 3 Hz and
7 Hz, respectively. Is there any difference between the corresponding equivalent discrete-
time signals. If not, why not?
clear all;
N=5;
fo=3; % maximum frequency in the signal
fs=10; % Sampling frequency
% Analog signal
t=0:0.005:N;
1
Digital Signal Processing Lab Electrical Engineering Department
x_t=sin(2*pi*fo*t);
% Digital signal
n=0:1:N*fs;
x_n=sin(2*pi*fo*n/fs);
j=0;
%for k=0:1/fs:N
% code for sequence of delayed sinc pulses
for k=0:1:N*fs
j=j+1;
h(j,:)=sinc((t-k/fs)*fs); % Each column represents a delayed sinc
end
y=x_n*h;
plot(n/fs,x_n,'o',t,y);grid;
xlabel('Time, msec');ylabel('Amplitude');
title('Reconstructed continuous-time signal y_{a}(t)');
figure;
xlabel('Time, msec');ylabel('Amplitude');
title('continuous-time signal y_{a}(t) sampled');
plot(n/fs,x_n,'o',t,x_t)
Q1.3 Repeat above program by changing the frequency of the sinusoidal signal to 3 Hz
and 7 Hz, respectively. Is there any difference between the corresponding equivalent
discrete-time signals and the one generated in Question.
clf;
t = 0:0.005:10;
xa = 2*t.*exp(-t);
subplot(2,2,1)
plot(t,xa);grid
xlabel('Time, msec');ylabel('Amplitude');
title('Continuous-time signal x_{a}(t)');
subplot(2,2,2)
wa = 0:10/511:10;
ha = freqs(2,[1 2 1],wa);
plot(wa/(2*pi),abs(ha));grid;
xlabel('Frequency, kHz');ylabel('Amplitude');
title('|X_{a}(j\Omega)|');
axis([0 5/pi 0 2]);
subplot(2,2,3)
T = 1;
2
Digital Signal Processing Lab Electrical Engineering Department
n = 0:T:10;
xs = 2*n.*exp(-n);
k = 0:length(n)-1;
stem(k,xs);grid;
xlabel('Time index n');ylabel('Amplitude');
title('Discrete-time signal x[n]');
subplot(2,2,4)
wd = 0:pi/255:pi;
hd = freqz(xs,1,wd);
plot(wd/(T*pi), T*abs(hd));grid;
xlabel('Frequency, kHz');ylabel('Amplitude');
title('|X(e^{j\omega})|');
axis([0 1/T 0 2]);
Q1.4 Run Program above to generate and display both the discrete-time signal and its
continuous-time equivalent, and their respective Fourier transforms. Is there any visible
effect of aliasing?
Q1.5 Repeat above program by increasing the sampling period to 1.5. Is there any visible
effect of aliasing?
2
Q1.6 Modify Program above program for the case of x(t) = e−πt and repeat
Questions 1.4 and 1.5.