KEMBAR78
DSP Lab Report 7 | PDF | Sampling (Signal Processing) | Signal Processing
0% found this document useful (0 votes)
12 views8 pages

DSP Lab Report 7

The document details Lab#7 of the EEE-324 Digital Signal Processing course, focusing on sampling and multi-rate signal processing. It covers tasks involving the generation and analysis of sinusoidal signals, demonstrating the effects of sampling rates on aliasing and signal fidelity using FFT plots. The lab emphasizes the importance of adhering to the Nyquist-Shannon sampling theorem to prevent irreversible distortion of frequency content in digital signals.

Uploaded by

Roman Roman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views8 pages

DSP Lab Report 7

The document details Lab#7 of the EEE-324 Digital Signal Processing course, focusing on sampling and multi-rate signal processing. It covers tasks involving the generation and analysis of sinusoidal signals, demonstrating the effects of sampling rates on aliasing and signal fidelity using FFT plots. The lab emphasizes the importance of adhering to the Nyquist-Shannon sampling theorem to prevent irreversible distortion of frequency content in digital signals.

Uploaded by

Roman Roman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

EEE-324 Digital Signal Processing

Lab#7: Sampling and Multi-rate Signal Processing

Name Roman Bin Ehsan


Reg no# FA22-BEE-258
Class BEE-6A
Instructor Dr. Bakhtiar Ali
Introduction:
• Sampling is the process of converting a continuous signal into a digital signal by taking

values at regular time intervals.

• The sampling rate determines how accurately the digital version represents the original

signal.

• In this lab, we explored multi-rate signal processing, which involves:

 Downsampling (decimation): Reducing the sampling rate.


 Upsampling (interpolation): Increasing the sampling rate.

• We used the Fourier Transform (FFT) to analyze how the signal’s frequency content

changes at each stage.

• A key focus was aliasing, which happens when the sampling rate is too low, causing

distortion in the signal.

• We also examined whether upsampling could restore the original signal after

downsampling.

• Understanding these concepts is essential in audio processing, speech recognition, and

data transmission.

In-Lab Tasks
Task#1: Use your ‗sin‘ or ‗cos‘ function to generate a sinusoid wave having two
components as f1 = 3kHz and f2 = 5kHz and then sample it with fs = 10kHz.
Calculate its fft with zero frequency component in the middle. Plot it on a properly
scaled w-axis. Specify if there is aliasing or not? If there is aliasing specify which
component is casing the aliasing.

Code:

n = -50:50; y = fft(x, NFFT);


f1 = 3000; f_ax1 = fs/2*linspace(0,1,NFFT/2+1);
f2 = 5000; f_ax2 = fs/2*linspace(-1,0,NFFT/2-1);
fs = 10000; f_ax = [f_ax1 f_ax2];
x = sin(2*pi*(f1/fs)*n) + sin(2*pi*(f2/fs)*n); stem(f_ax,2*abs(y))
L = length(x); xlabel('Hz');
NFFT = 2^nextpow2(L); ylabel('Amplitude');

Graph:
Discussion:

This task demonstrates the practical implications of the Nyquist-Shannon sampling


theorem. The sinusoid combines 3 kHz and 5 kHz components, sampled at 10 kHz.
While the 3 kHz component is correctly captured (since it is below the Nyquist
frequency, fs/2=5kHzfs/2=5kHz), the 5 kHz component violates the theorem, leading
to aliasing. The FFT plot confirms this by showing mirrored peaks at ±5 kHz, indicating
spectral folding. The zero-centered frequency axis correctly represents the symmetry
of the DFT, but the aliasing artifact undermines signal fidelity. A higher sampling rate
(e.g., fs>10kHzfs>10kHz) would be necessary to avoid distortion, emphasizing the
importance of proper sampling in signal processing applications.

Task#2: Use your ‗sin‘ or ‗cos‘ function to generate a sinusoid wave having two
components as f1 = 3kHz and f2 = 5kHz and then sample it with fs = 8kHz. Calculate
its fft with zero frequency component in the middle. Plot it on a properly scaled w-
axis. Specify if there is aliasing or not? If there is aliasing specify which component
is casing the aliasing.

Code:

n = -50:50; y = fft(x, NFFT);


f1 = 3000; f_ax1 = fs/2*linspace(0,1,NFFT/2+1);
f2 = 5000; f_ax2 = fs/2*linspace(-1,0,NFFT/2-1);
fs = 8000; f_ax = [f_ax1 f_ax2];
x = sin(2*pi*(f1/fs)*n) + sin(2*pi*(f2/fs)*n) stem(f_ax,2*abs(y))
L = length(x); xlabel('Hz');
NFFT = 2^nextpow2(L); ylabel('Amplitude');

Graph:
Discussion:

The given task involves generating a composite sinusoidal signal with frequency
components at 3 kHz and 5 kHz, sampled at 8 kHz. Since the Nyquist frequency (fs/2
= 4 kHz) is lower than both input frequencies, aliasing occurs for both components.
The 3 kHz signal aliases to 5 kHz (due to fs - f1 = 5 kHz), while the 5 kHz signal aliases
to 3 kHz (due to fs - f2 = 3 kHz), resulting in mirrored peaks in the FFT spectrum. The
zero-centered FFT plot clearly shows these aliased components at ±3 kHz and ±5
kHz, confirming spectral distortion. This demonstrates the importance of adhering to
the Nyquist criterion to prevent aliasing and ensure accurate signal representation.

Task#3: Use your ‗sin‘ or ‗cos‘ function to generate a sinusoid wave having two
components as f1 = 1.5kHz and f2 = 4kHz and f3 = 7kHz and then (a) sample it with
an fs such that there is no aliasing (b) sample it with an fs which produces aliasing.
Show the result in both cases by plotting fft of the discretized signal.

Code:

n=-50:50; xlabel('Hz')
f1=3000; ylabel('Amplitude')
f2=5000; title('Without Aliasing');
f3=7000; x2=cos(2*pi*(f1/fs2)*n) + cos(2*pi*(f2/fs2)*n) +
fs1=15000; cos(2*pi*(f3/fs2)*n);
fs2=8000; L=length(x2);
x1=cos(2*pi*(f1/fs1)*n) + cos(2*pi*(f2/fs1)*n) + NFFT=2^nextpow2(L);
cos(2*pi*(f3/fs1)*n); y=fft(x2,NFFT);
L=length(x1); f_ax1=fs2/2*linspace(0,1,NFFT/2+1);
NFFT=2^nextpow2(L); f_ax2=fs2/2*linspace(-1,0,NFFT/2-1);
y=fft(x1,NFFT); f_ax2=[f_ax1 f_ax2];
f_ax1=fs1/2*linspace(0,1,NFFT/2+1); subplot(2,1,2)
f_ax2=fs1/2*linspace(-1,0,NFFT/2-1); stem(f_ax2,2*abs(y),'fill','linewidth',2)
f_ax1=[f_ax1 f_ax2]; xlabel('Hz')
subplot(2,1,1) ylabel('Amplitude')
stem(f_ax1,2*abs(y),'fill','linewidth',2) title('With Aliasing');
Graph:

Discussion:

This task explores the effects of sampling rates on signal fidelity through two
scenarios: (a) proper sampling (fs1=15kHz) and (b) undersampling (fs2=8kHz). In the
first case, all frequency components (1.5kHz, 4kHz, 7kHz) are preserved without
aliasing since fs1 > 2×fmax (Nyquist criterion satisfied). The FFT plot shows clean
peaks at the correct frequencies. In the second case, severe aliasing occurs because
fs2 < 2×f3 (7kHz), causing the 4kHz and 7kHz components to alias to 4kHz and 1kHz
respectively, visible as mirrored peaks in the FFT. The 1.5kHz component remains
intact as it lies below the Nyquist frequency (4kHz). This contrast vividly illustrates
how undersampling distorts spectral information, with the 7kHz component causing
the most significant aliasing due to being furthest beyond the Nyquist limit. The zero-
centered FFT presentation effectively highlights the symmetry of aliased components.
For practical applications, this demonstrates the critical need to select sampling
rates that exceed twice the highest frequency component to maintain signal integrity.

Task#4: Take a speech signal

i. Plot fft of the signal


ii. Downsample (decimate) the signal in part-by 2 and plot its fft. Comment if
there is aliasing or not?
iii. Now upsample (interpolate) the signal in part-(ii) by 2 and plot its fft.
Comment on the outcome? iv. Compare the fft of in part-(i) and in part-(iii)
and comment on whether or not the interpolation operation recovers the
information lost during decimation operation?

Function code:

recObj = audiorecorder(44100, 16, 2); disp('End of Recording.');


get(recObj) myRecording = getaudiodata(recObj); % Get
recObj = audiorecorder; audio data out of the recording object
disp( 'Start speaking.') stem(myRecording);
recordblocking(recObj, 5); sound(myRecording) ;

Graph:

Script code:

x1=myRecording; f2ax1=fs/2*linspace(0,1,NFFT/2+1);
fs=44100; f2ax2=fs/2*linspace(-1,0,NFFT/2-1);
L=length(x1); f2ax1=[f2ax1 f2ax2];
NFFT=2^nextpow2(L); subplot(3,1,2)
y=fft(x1,NFFT); stem(f2ax1,2*abs(y),'fill','linewidth',2)
f1ax1=fs/2*linspace(0,1,NFFT/2+1); x3=interp(x1,2);
f1ax2=fs/2*linspace(-1,0,NFFT/2-1); L2=length(x3);
f1ax1=[f1ax1 f1ax2]; NFFT=2^nextpow2(L);
subplot(3,1,1) y=fft(x3,NFFT);
stem(f1ax1,2*abs(y),'fill','linewidth',2) f3ax1=fs/2*linspace(0,1,NFFT/2+1);
x2=decimate(x1,2); f3ax2=fs/2*linspace(-1,0,NFFT/2-1);
L1=length(x2); f3ax1=[f3ax1 f3ax2];
NFFT=2^nextpow2(L); subplot(3,1,3)
y=fft(x2,NFFT); stem(f3ax1,2*abs(y),'fill','linewidth',2)

Graph:
Discussion:

In this task, a speech signal was processed using both downsampling and upsampling
techniques. The FFT of the original signal indicated a broad frequency spectrum,
which is characteristic of speech signals. When the signal was downsampled by a
factor of 2, the resulting FFT displayed aliasing effects—high-frequency components
were reflected into lower frequencies, indicating a breach of the Nyquist sampling
rate. After this, upsampling the previously downsampled signal by the same factor led
to a stretched spectrum in the FFT. However, the high-frequency content that was lost
initially did not reappear; the aliasing artifacts persisted. This outcome demonstrates
that interpolation through upsampling cannot recover the information lost due to
aliasing, confirming its irreversibility.

Task#5: Take a speech signal, plot its fft, now decimate by 2,3,4 … until the
spectrum goes outsidethe range {-fs/2, fs/2} (That‘s when aliasing appears). Now do
the reverse process i.e. interpolate by … 4,3,2 and see whether the original signal
has recovered or not listening the reconstructed signal. Note that you are required
to plot fft at all stages.

Code:

% Your recorded speech signal f_d = (fs/d) * (-0.5:1/NFFT_d:0.5 - 1/NFFT_d);


x = myRecording; % Already stored from your subplot(3, 3, i+1);
custom function plot(f_d, abs(y_d));
fs = 44100; title(['Decimated by ', num2str(d)]);
% Original signal FFT xlabel('Frequency (Hz)');
L = length(x); ylabel('Magnitude');
NFFT = 2^nextpow2(L); end
y = fftshift(fft(x, NFFT)); interp_factors = fliplr(decim_factors);
f = fs * (-0.5:1/NFFT:0.5 - 1/NFFT); x_reconstructed = x_decimated{end};
figure; for i = 1:length(interp_factors)
subplot(3, 3, 1); u = interp_factors(i);
plot(f, abs(y)); x_reconstructed = interp(x_reconstructed, u);
title('Original Signal FFT'); NFFT_r =
xlabel('Frequency (Hz)'); 2^nextpow2(length(x_reconstructed));
ylabel('Magnitude'); y_r = fftshift(fft(x_reconstructed, NFFT_r));
decim_factors = [2, 3, 4]; f_r = fs * (-0.5:1/NFFT_r:0.5 - 1/NFFT_r);
x_decimated = cell(1, length(decim_factors)); subplot(3, 3, i+4);
for i = 1:length(decim_factors) plot(f_r, abs(y_r));
d = decim_factors(i); title(['Interpolated by ', num2str(u)]);
x_d = decimate(x, d); xlabel('Frequency (Hz)');
x_decimated{i} = x_d; ylabel('Magnitude');
NFFT_d = 2^nextpow2(length(x_d)); end
y_d = fftshift(fft(x_d, NFFT_d));

Graph:
Discussion:

In this task, a speech signal was processed by first reducing its sample rate
(decimation) and then increasing it again (interpolation). When the sample rate was
reduced by factors of 2, 3, and 4, the FFT graphs showed that parts of the frequency
content started to mix and overlap. This happened because the signal was sampled
too slowly, breaking the Nyquist rule and causing aliasing. When we tried to fix the
signal by increasing the sample rate again using the same factors, the FFT showed
that some of the original signal returned. However, the parts lost due to aliasing did
not come back. This shows that once aliasing happens, the lost details cannot be fully
recovered.

Critical Analysis:
This lab effectively demonstrated the crucial role of the Nyquist-Shannon sampling
theorem in digital signal processing. Across all tasks, the experiments highlighted how
aliasing occurs when the sampling rate is insufficient, resulting in irreversible
distortion of the frequency content. Tasks 1 and 2 clearly showed how different
frequency components fold into incorrect positions when undersampled, leading to
mirrored spectral peaks in the FFT plots. Task 3 emphasized the contrast between
proper sampling and undersampling, illustrating how higher frequencies suffer more
from aliasing. Tasks 4 and 5, involving downsampling and upsampling, reinforced that
once aliasing occurs, lost information cannot be recovered through interpolation.
Overall, the lab provided hands-on insight into the dangers of violating the Nyquist
criterion and the importance of selecting appropriate sampling rates. It also
emphasized that while interpolation can modify signal resolution, it cannot restore
original content lost due to aliasing.

You might also like