Experiment 1
Aim: To generate basic analog and discrete-time signals using MATLAB.
Requirements:
• MATLAB
• Python
• NumPy
• Matplotlib
Theory:
Signals are functions of one or more independent variables that convey information. In
signal processing, signals are broadly classified as analog (continuous-time) and discrete-time
signals. Analog signals exist for every instant of time, while discrete signals are defined only
at specific time instants.
Basic signals such as sine wave, cosine wave, exponential signal, unit step signal, and ramp
signal are fundamental in signal analysis. These signals are used to model real-life physical
phenomena such as sound waves, electrical voltages, vibrations, and communication signals.
Generating these signals using MATLAB helps in visualizing their characteristics and
understanding their behaviour in both continuous and discrete domains.
MATLAB Code:
1 clc;
2 clear;
3 close all;
4
5 % -------- Analog Signals -------
6 t = 0:0.001:1; % continuous time axis
7
8 analog_sine = sin(2*pi*5*t);
9 analog_cos = cos(2*pi*5*t);
10 analog_exp = exp(-2*t);
11
12 % -------- Discrete Signals --------
13 n = 0:1:20; % discrete index
14
15 disc_step = ones(size(n));
16 disc_ramp = n;
17 disc_exp = (0.8).^n;
18
19 % -------- Plotting
-------20 figure
21
22 % Analog Signals
23 subplot(2,2,1)
24 plot(t,analog_sine)
25 title('Analog Sine Signal')
26 xlabel('Time')
27 ylabel('Amplitude')
28 grid on
29
30 subplot(2,2,2)
31 plot(t,analog_exp)
32 title('Analog Exponential Signal')
33 xlabel('Time')
34 ylabel('Amplitude')
35 grid on
36
37 % Discrete Signals
38 subplot(2,2,3)
39 stem(n,disc_step,'filled')
40 title('Discrete Unit Step Signal')
41 xlabel('n')
42 ylabel('Amplitude')
43 grid on
44
45 subplot(2,2,4)
46 stem(n,disc_ramp,'filled')
47 title('Discrete Ramp Signal')
48 xlabel('n')
49 ylabel('Amplitude')
50 grid on
Output:
Python Code:
import numpy as np
import [Link] as plt
N0 = 16
# Analog Signal
t = [Link](0, 1, 1000) # Continuous time
xa = [Link](2 * [Link] * 5 * t) # Analog cosine
[Link](figsize=(8,6))
[Link](2,1,1)
[Link](t, xa)
[Link]('Analog Cosine Signal')
[Link]('t')
[Link]('x(t)')
[Link](True)
# Discrete Signal
n = [Link](0, 64)
xd = [Link](2 * [Link] * n / N0)
[Link](2,1,2)
[Link](n, xd)
[Link]('Discrete Cosine Signal (Period = 16)')
[Link]('n')
[Link]('x[n]')
[Link](True)
plt.tight_layout()
[Link]()
Expected Output:
• A stem plot
• Discrete cosine waveform
• Period = 16 samples
• Signal repeats after every 16 samples
• Amplitude varies between –1 and +1
The graphical outputs of MATLAB and Python are visually similar, since both implement the
same mathematical expression.
Result:
Basic analog and discrete-time signals were generated successfully using MATLAB and their
characteristics were observed through graphical plots.
Conclusion:
The experiment helped in understanding the difference between analog and discrete signals
and how fundamental signals can be generated using MATLAB. These signals form the
foundation for studying advanced DSP operations such as filtering, convolution, and spectral
analysis.
Experiment 2
Aim: To implement linear convolution, circular convolution, and linear convolution using
circular convolution of two discrete-time sequences using MATLAB.
Requirements:
• MATLAB
• Python
• NumPy
• Matplotlib
Theory:
Convolution is one of the most important mathematical operations in digital signal processing
and is used to determine the response of a linear time-invariant (LTI) system to a given input
signal. If 𝑥(𝑛)represents the input sequence and ℎ(𝑛)represents the impulse response of the
system, then the output sequence 𝑦(𝑛)is obtained by convolving the two sequences.
Convolution essentially represents the process of reversing one sequence, shifting it over the
other, multiplying corresponding samples, and summing the products.
In linear convolution, the sequences are assumed to be finite and non-periodic. The output
length of linear convolution is given by
𝐿 = 𝐿𝑥 + 𝐿ℎ − 1
where 𝐿𝑥 and 𝐿ℎ are the lengths of the input sequences. Linear convolution is widely used in
filtering, system analysis, and signal processing applications where signals do not repeat
periodically.
In circular convolution, the sequences are treated as periodic with a fixed length 𝑁. During
convolution, when the sequence shifts beyond its boundary, it wraps around and reappears
from the beginning. Due to this periodic extension, the output length of circular convolution
remains equal to 𝑁. Circular convolution plays a major role in digital signal processing,
particularly in the implementation of Discrete Fourier Transform (DFT), Fast Fourier
Transform (FFT), and digital filtering using frequency-domain methods.
Linear convolution can be computed using circular convolution by appropriately zero-
padding both sequences so that their lengths become
𝑁 = 𝐿𝑥 + 𝐿ℎ − 1
When zero padding is applied, the periodic overlap in circular convolution is avoided, and the
result becomes identical to linear convolution. This approach forms the basis of fast
convolution algorithms used in real-time DSP systems, communication receivers, and
audio/image processing applications.
Thus, the study of linear and circular convolution helps in understanding how signals interact
with systems and how efficient computational methods such as FFT can be used to perform
convolution in practical applications.
MATLAB Code:
1 clc;
2 clear;
3 close all;
4
5 % Input sequences
6 x = [1 2 3];
7 h = [1 1 1];
8
9 % -------- Linear Convolution --------
10 y_linear = conv(x,h);
11
12 % -------- Circular Convolution -------13 N = max(length(x),length(h)); % choose same length
14 x_c = [x zeros(1,N-length(x))];
15 h_c = [h zeros(1,N-length(h))];
16 y_circular = cconv(x_c,h_c,N);
17
18 % -------- Linear using Circular --------
19 N1 = length(x)+length(h)-1;
20 x_pad = [x zeros(1,N1-length(x))];
21 h_pad = [h zeros(1,N1-length(h))];
22 y_lin_circ = cconv(x_pad,h_pad,N1);
23
24 % -------- Display outputs --------
25 disp('Linear convolution:')
26 disp(y_linear)
27
28 disp('Circular convolution:')
29 disp(y_circular)
30
31 disp('Linear using circular:')
32 disp(y_lin_circ)
33
34 % -------- Plotting --------
35 n1 = 0:length(x)-1;
36 n2 = 0:length(h)-1;
37 n3 = 0:length(y_linear)-1;
38 n4 = 0:length(y_circular)-1;
39
40 figure
41
42 subplot(4,1,1)
43 stem(n1,x,'filled')
44 title('Input Sequence x(n)')
45 grid on
46
47 subplot(4,1,2)
48 stem(n2,h,'filled')
49 title('Impulse Response h(n)')
50 grid on
51
52 subplot(4,1,3)
53 stem(n3,y_linear,'filled')
54 title('Linear Convolution Output')
55 grid on
56
57 subplot(4,1,4)
58 stem(n4,y_circular,'filled')
59 title('Circular Convolution Output')
60 grid on
Output:
Python Code:
import numpy as np
x = [Link]([1, 2, 3, 4])
h = [Link]([1, 1, 1])
# Linear Convolution
y_linear = [Link](x, h)
# Circular Convolution
N = max(len(x), len(h))
x1 = [Link](x, (0, N - len(x)))
h1 = [Link](h, (0, N - len(h)))
y_circular = [Link]([Link](x1) * [Link](h1)).real
# Linear using Circular Convolution
L = len(x) + len(h) - 1
x2 = [Link](x, (0, L - len(x)))
h2 = [Link](h, (0, L - len(h)))
y_linear_circular = [Link]([Link](x2) * [Link](h2)).real
print("Linear Convolution:", y_linear)
print("Circular Convolution:", y_circular)
print("Linear using Circular:", y_linear_circular)
Expected Output:
For:
x[n] = [1 2 3 4]
h[n] = [1 1 1]
Linear Convolution:
[1 3 6 9 7 4]
Length = 6
Circular Convolution (Length = 4):
Aliasing occurs.
Linear using Circular:
Result matches linear convolution: [1 3 6 9 7 4]
Result:
The linear convolution, circular convolution, and linear convolution using circular
convolution of the given sequences were successfully implemented using MATLAB. The
result obtained from circular convolution with zero padding matched the linear convolution
output.
Conclusion:
The experiment verified that circular convolution produces results different from linear
convolution unless zero padding is applied. By extending the sequence length appropriately,
linear convolution can be computed using circular convolution. This concept forms the basis
of efficient FFT-based convolution methods used in practical DSP systems.
Experiment 3
Aim: To compute the Discrete Fourier Transform (DFT) of a given discrete-time signal using
MATLAB and observe its frequency spectrum.
Requirements:
• MATLAB
• Python
• NumPy
• Matplotlib
Theory:
The Discrete Fourier Transform (DFT) is used to convert a finite-length discrete-time signal
from the time domain into the frequency domain. It represents the signal as a weighted sum
of complex sinusoids of different frequencies. DFT is widely used in digital signal processing
for spectral analysis, filtering, communication systems, and image processing.
For a sequence 𝑥(𝑛)of length 𝑁, the DFT is defined as
𝑁−1
𝑋(𝑘) = ∑ 𝑥(𝑛) 𝑒 −𝑗2𝜋𝑘𝑛/𝑁 , 𝑘 = 0,1,2, … , 𝑁 − 1
𝑛=0
The result of DFT is a complex sequence that contains magnitude and phase information of
the frequency components present in the signal. MATLAB provides a built-in function fft()
which efficiently computes the DFT using the Fast Fourier Transform (FFT) algorithm.
Understanding DFT helps in analysing signal bandwidth, detecting dominant frequencies, and
designing digital filters.
MATLAB Code:
1 clc;
2 clear;
3 close all;
4
5 x = [1 2 3 4];
6 N = length(x);
7
8 X = fft(x,N);
9
10 mag = abs(X);
11 phase = angle(X);
12
13 k = 0:N-1;
14
15 figure
16
17 subplot(3,1,1)
18 stem(0:N-1,x,'filled')
19 title('Input Sequence')
20 xlabel('n')
21 ylabel('Amplitude')
22 grid on
23
24 subplot(3,1,2)
25 stem(k,mag,'filled')
26 title('Magnitude Spectrum')
27 xlabel('k')
28 ylabel('|X(k)|')
29 grid on
30
31 subplot(3,1,3)
32 stem(k,phase,'filled')
33 title('Phase Spectrum')
34 xlabel('k')
35 ylabel('Phase')
36 grid on
Output:
Python Code:
import numpy as np
import [Link] as plt
# Given Signal
x = [Link]([1, 2, 3, 4])
N = len(x)
# Compute DFT
X = [Link](x)
# Magnitude and Phase
mag = [Link](X)
phase = [Link](X)
# Plot
[Link](figsize=(8,8))
[Link](3,1,1)
[Link](range(N), x)
[Link]('Input Signal x[n]')
[Link]('n')
[Link]('x[n]')
[Link](True)
[Link](3,1,2)
[Link](range(N), mag)
[Link]('Magnitude Spectrum')
[Link]('k')
[Link]('|X[k]|')
[Link](True)
[Link](3,1,3)
[Link](range(N), phase)
[Link]('Phase Spectrum')
[Link]('k')
[Link]('∠X[k]')
[Link](True)
plt.tight_layout()
[Link]()
Expected Output:
For input signal: x[n] = [1,2,3,4]
DFT output:
X[k] = [10, −2+2j,−2, −2−2j ]
Magnitude Spectrum: [10, 2.828, 2, 2.828]
Phase Spectrum: [0,135°,180°,−135°]
Result:
The Discrete Fourier Transform of the given signal was successfully computed using
MATLAB. The magnitude and phase spectra were obtained, representing the frequency
components present in the signal.
Conclusion:
The experiment demonstrated how a discrete-time signal can be transformed from the time
domain to the frequency domain using DFT. This transformation is essential in analysing
signal frequency content and forms the basis for advanced DSP techniques such as FFT-based
filtering and spectral estimation.
Experiment 4
Aim: To compute and plot the Fourier Transform amplitude spectrum and phase spectrum of
a given signal using MATLAB and Python.
Requirements:
• MATLAB
• Python
• NumPy
• Matplotlib
Theory:
Fourier Transform
The Fourier Transform converts a signal from:
• Time Domain → Frequency Domain
For continuous-time signals:
Continuous-time Fourier Transform (CTFT):
∞
𝑋(𝑓) = ∫ 𝑥(𝑡) 𝑒 −𝑗2𝜋𝑓𝑡 𝑑𝑡
−∞
For discrete-time signals (using DFT):
𝑁−1
2𝜋
𝑋[𝑘] = ∑ 𝑥[𝑛] 𝑒 −𝑗 𝑁 𝑘𝑛
𝑛=0
Amplitude Spectrum:
Amplitude spectrum represents: ∣X(f)∣
It shows the strength of frequency components.
Phase Spectrum:
Phase spectrum represents: ∠X(f)
It shows the phase shift of frequency components.
Importance:
Fourier Transform helps in:
• Frequency analysis
• Signal filtering
• System response analysis
• Communication systems
MATLAB Code:
Example Signal: x[n] = cos(2π5n/N)
clc;
clear;
close all;
fs = 100; % Sampling frequency
t = 0:1/fs:1-1/fs; % Time vector
x = cos(2*pi*5*t); % Given function
N = length(x);
X = fft(x); % Fourier Transform
f = (0:N-1)*(fs/N); % Frequency axis
mag = abs(X);
phase = angle(X);
subplot(3,1,1);
plot(t, x);
title('Input Signal');
xlabel('Time');
ylabel('Amplitude');
grid on;
subplot(3,1,2);
plot(f, mag);
title('Amplitude Spectrum');
xlabel('Frequency');
ylabel('|X(f)|');
grid on;
subplot(3,1,3);
plot(f, phase);
title('Phase Spectrum');
xlabel('Frequency');
ylabel('Phase (radians)');
grid on;
Output:
Python Code:
import numpy as np
import [Link] as plt
fs = 100 # Sampling frequency
t = [Link](0, 1, 1/fs) # Time vector
x = [Link](2 * [Link] * 5 * t) # Given function
N = len(x)
X = [Link](x) # Fourier Transform
f = [Link](N) * (fs/N) # Frequency axis
mag = [Link](X)
phase = [Link](X)
[Link](figsize=(8,8))
[Link](3,1,1)
[Link](t, x)
[Link]('Input Signal')
[Link]('Time')
[Link]('Amplitude')
[Link](True)
[Link](3,1,2)
[Link](f, mag)
[Link]('Amplitude Spectrum')
[Link]('Frequency')
[Link]('|X(f)|')
[Link](True)
[Link](3,1,3)
[Link](f, phase)
[Link]('Phase Spectrum')
[Link]('Frequency')
[Link]('Phase (radians)')
[Link](True)
plt.tight_layout()
[Link]()
Expected Output:
For a cosine signal of 5 Hz:
• Amplitude spectrum shows two peaks at ±5 Hz
• Phase spectrum shows phase corresponding to cosine signal
• Input signal is periodic
Result:
The Fourier Transform of the given function was computed successfully. The amplitude and
phase spectra were plotted and verified using MATLAB and Python.
Conclusion:
• Fourier Transform converts time-domain signals to frequency-domain.
• Amplitude spectrum shows magnitude of frequency components.
• Phase spectrum shows phase information.
• MATLAB and Python produce identical spectral outputs.
• FFT algorithm efficiently computes Fourier Transform.
Experiment 5
Aim: To plot the frequency response of a given system in the Z-domain using MATLAB.
Requirements:
• MATLAB
• Python
• NumPy
• Matplotlib
Theory:
In digital signal processing, systems are represented in the Z-domain using a transfer
function. The transfer function is defined as the ratio of the Z-transform of the output to the
Z-transform of the input under zero initial conditions. It is expressed as
H(z) = (b₀ + b₁z⁻¹ + … + bMz⁻M) / (1 + a₁z⁻¹ + … + aNz⁻N)
The frequency response of the system is obtained by evaluating the transfer function on the
unit circle by substituting z = e^(jω). This gives H(e^(jω)), which represents how the system
responds to different frequency components of the input signal.
The frequency response consists of magnitude response and phase response. The magnitude
response shows how the amplitude of each frequency component is affected, while the phase
response indicates the phase shift introduced by the system.
MATLAB provides the function freqz() to compute and plot the frequency response
efficiently. This is widely used in analyzing digital filters such as low-pass, high-pass, and
band-pass filters.
MATLAB Code:
clc;
clear;
close all;
b = [1 0.5];
a = [1 -0.8];
[H,w] = freqz(b,a);
mag = abs(H);
phase = angle(H);
figure
subplot(2,1,1)
plot(w/pi,mag)
title('Magnitude Response')
xlabel('Normalized Frequency (×π rad/sample)')
ylabel('|H(e^{jω})|')
grid on
subplot(2,1,2)
plot(w/pi,phase)
title('Phase Response')
xlabel('Normalized Frequency (×π rad/sample)')
ylabel('Phase (radians)')
grid on
MATLAB Output:
MATLAB Output:
Python Code:
import numpy as np import
[Link] as plt
from scipy import signal
# Transfer function
coefficients b = [1, 0.5]
# numerator a = [1, -0.8]
# denominator
# Compute frequency
response w, H =
[Link](b, a)
# Magnitude and Phase
magnitude = [Link](H)
phase = [Link](H)
# Plotting
[Link]()
[Link](2, 1, 1) [Link](w/[Link],
magnitude) [Link]('Magnitude Response')
[Link]('Normalized Frequency (×π
rad/sample)') [Link]('|H(e^jω)|')
[Link]()
[Link](2, 1, 2) [Link](w/[Link], phase)
[Link]('Phase Response')
[Link]('Normalized Frequency (×π
rad/sample)') [Link]('Phase (radians)')
[Link]()
plt.tight_layout() [Link]()
Python Expected Output:
For the given transfer function:
• Magnitude response is maximum at low frequencies and decreases as frequency increases.
• System exhibits low-pass filter behaviour.
• Phase response shows a smooth negative variation with increasing frequency.
• Output consists of magnitude and phase spectra plotted against normalized frequency.
Result:
The frequency response of the given transfer function was successfully obtained using
Python. The magnitude and phase spectra were plotted with respect to normalized frequency.
The magnitude response indicates higher gain at low frequencies and attenuation at higher
frequencies, confirming the system’s behavior.
Conclusion:
The experiment demonstrated how to analyse a digital system in the frequency domain using
its transfer function. From the obtained plots, it was observed that the system behaves like a
low-pass filter, allowing low-frequency components to pass while attenuating high-frequency
components. This experiment helps in understanding the frequency characteristics of digital
filters and the use of computational tools for DSP analysis.
Experiment 6
Aim: To plot the frequency response of a continuous-time system in the S-domain using
MATLAB and Python
Requirements:
• MATLAB
• Python
• NumPy
• Matplotlib
Theory:
In continuous-time systems, the transfer function is represented in the S-domain using the
Laplace transform. The transfer function is defined as
H(s) = Y(s) / X(s) = (b₀ + b₁s + … + bMs^M) / (a₀ + a₁s + … + aNs^N)
The frequency response of the system is obtained by substituting
s = jω
which gives
H(jω)
This represents how the system responds to different frequencies. The frequency response
consists of magnitude and phase components. The magnitude response indicates how the
amplitude of input signals is modified, while the phase response indicates the phase shift
introduced by the system.
In practical analysis, the frequency response is represented using Bode plots, which show
magnitude (in dB) and phase versus logarithmic frequency.
MATLAB Code:
clc;
clear;
close all;
% Transfer function H(s) = 1 / (s +
1) num = [1];
den = [1 1];
% Frequency range
w = logspace(-1, 2, 500); % 0.1 to 100 rad/sec
% Compute frequency response
H = freqs(num, den, w);
% Magnitude (dB) and Phase
(degrees) mag = 20*log10(abs(H));
phase = angle(H) * (180/pi);
% Plotting
figure
subplot(2,1,1) semilogx(w,
mag) title('Magnitude
Response') xlabel('Frequency
(rad/sec)')
ylabel('Magnitude (dB)')
grid on
subplot(2,1,2)
semilogx(w, phase)
title('Phase Response')
xlabel('Frequency (rad/sec)')
ylabel('Phase (degrees)')
grid on
MATLAB Output:
Python Code:
import numpy as np
import
[Link] as
plt from scipy import
signal
# Transfer function H(s) =
1 / (s + 1) num = [1] den =
[1, 1]
# Create system
system = [Link](num, den)
# Frequency range
(rad/sec) w =
[Link](-1, 2,
500)
# Frequency response
w, H = [Link](system, w)
# Magnitude (dB) and Phase
(degrees) mag = 20 *
np.log10(abs(H)) phase =
[Link](H, deg=True)
# Plotting
[Link]()
[Link](2,1,1)
[Link](w, mag)
[Link]('Magnitude
Response')
[Link]('Frequency
(rad/sec)')
[Link]('Magnitude
(dB)') [Link]()
[Link](2,1,2)
[Link](w, phase)
[Link]('Phase
Response')
[Link]('Frequency
(rad/sec)')
[Link]('Phase
(degrees)') [Link]()
plt.tight_layout() [Link]()
Expected Output:
• Magnitude decreases with increasing frequency
• System behaves like a low-pass filter
• Phase shifts from 0° to −90°
• Output is shown as Bode magnitude and phase plots
Result:
The frequency response of the given S-domain transfer function was successfully plotted
using Python.
Conclusion:
The experiment verified that the system behaves as a low-pass filter and demonstrated
frequency-domain analysis using Python.
Experiment 7
Aim: To compute and plot the Fast Fourier Transform (FFT) of a given signal and observe its
amplitude and phase spectrum.
Requirements:
• MATLAB
• Python
• NumPy
• Matplotlib
Theory: The Fast Fourier Transform (FFT) is an efficient algorithm used to compute the
Discrete Fourier Transform (DFT) of a signal. It converts a time-domain signal into its
frequency-domain representation, making it easier to analyze the frequency components
present in the signal.
For a discrete-time signal 𝑥(𝑛), the DFT is defined as
𝑁−1
𝑋(𝑘) = ∑ 𝑥(𝑛) 𝑒 −𝑗2𝜋𝑘𝑛/𝑁
𝑛=0
The FFT reduces the computational complexity of DFT from 𝑂(𝑁 2 )to 𝑂(𝑁log 𝑁), making it
suitable for real-time signal processing applications.
The output of FFT is a complex sequence that contains both magnitude and phase
information. The magnitude spectrum shows the strength of different frequency components,
while the phase spectrum shows the phase shift associated with each frequency component.
MATLAB Code:
clc;
clear;
close all;
fs = 100;
t = 0:1/fs:1-1/fs;
x = cos(2*pi*5*t);
N = length(x); X =
fft(x);
f = (0:N-1)*(fs/N);
mag = abs(X);
phase = angle(X);
figure
subplot(3,1,1)
plot(t,x)
title('Input
Signal')
xlabel('Time')
ylabel('Amplitude')
grid on
subplot(3,1,2) plot(f,mag)
title('Amplitude
Spectrum')
xlabel('Frequency (Hz)')
ylabel('|X(f)|') grid on
subplot(3,1,3) plot(f,phase) title('Phase Spectrum') xlabel('Frequency (Hz)')
ylabel('Phase (radians)') grid on
MATLAB Output:
Python Code:
import numpy as np
import [Link] as plt
fs = 100
t = [Link](0, 1,
1/fs)
x =
[Link](2*[Link]*5*t)
N = len(x)
X = [Link](x) f
=
[Link](N)*(fs/N)
mag = [Link](X)
phase =
[Link](X)
[Link]()
[Link](3,1,1)
[Link](t,x)
[Link]('Input
Signal')
[Link]('Time')
[Link]('Amplitude')
[Link]()
[Link](3,1,2)
[Link](f,mag)
[Link]('Amplitude
Spectrum')
[Link]('Frequency
(Hz)')
[Link]('|X(f)|')
[Link]()
[Link](3,1,3)
[Link](f,phase)
[Link]('Phase Spectrum')
[Link]('Frequency (Hz)')
[Link]('Phase
(radians)') [Link]()
plt.tight_layout()
[Link]()
Expected Output:
• Time-domain signal is a cosine wave of 5 Hz
• Amplitude spectrum shows peaks at ±5 Hz (or at 5 Hz in FFT plot)
• Phase spectrum shows nearly constant phase
• Signal is periodic
Result:
The Fast Fourier Transform of the given signal was successfully computed and its amplitude
and phase spectra were plotted.
Conclusion:
The experiment demonstrated how a time-domain signal can be transformed into the
frequency domain using FFT and helped in understanding the frequency and phase
characteristics of the signal.
Experiment 8
Aim: To study the effect of sampling a sinusoidal signal at Nyquist rate, above Nyquist rate,
and below Nyquist rate using MATLAB and Python.
Requirements:
• MATLAB
• Python
• NumPy
• Matplotlib
Theory: Sampling is the process of converting a continuous-time signal into a discrete-time
signal by taking samples at regular intervals. The sampling theorem states that a signal can be
perfectly reconstructed from its samples if it is sampled at a frequency greater than or equal
to twice its highest frequency component. This minimum sampling rate is called the Nyquist
rate.
If the sampling frequency 𝑓𝑠 is equal to 2𝑓𝑚 , where 𝑓𝑚 is the maximum frequency of the
signal, it is called Nyquist sampling. If 𝑓𝑠 > 2𝑓𝑚 , it is called oversampling, and the signal is
accurately represented. If 𝑓𝑠 < 2𝑓𝑚 , it results in aliasing, where different frequency
components overlap and the original signal cannot be reconstructed correctly.
This experiment demonstrates the effects of different sampling rates on a sinusoidal signal
and helps in understanding aliasing and proper sampling conditions.
MATLAB Code:
clc;
clear;
close all;
fm = 5; % Signal
frequency
t = 0:0.001:1; % Continuous
time
x = sin(2*pi*fm*t);
% Sampling rates
fs1 = 2*fm; % Nyquist rate
fs2 = 5*fm; % Above Nyquist
fs3 = fm; % Below Nyquist
% Sampled signals
t1 = 0:1/fs1:1;
t2 = 0:1/fs2:1;
t3 = 0:1/fs3:1;
x1 = sin(2*pi*fm*t1);
x2 = sin(2*pi*fm*t2);
x3 = sin(2*pi*fm*t3);
figure
subplot(3,1,1)
stem(t1,x1,'filled')
title('Sampling at Nyquist
Rate') grid on
subplot(3,1,2)
stem(t2,x2,'filled')
title('Sampling Above Nyquist
Rate') grid on
subplot(3,1,3)
stem(t3,x3,'filled')
title('Sampling Below Nyquist Rate (Aliasing)')
grid on
MATLAB Code:
Python Code:
import numpy as np
import [Link] as plt
fm = 5
t = [Link](0, 1, 0.001)
x = [Link](2*[Link]*fm*t)
fs1 = 2*fm
fs2 = 5*fm
fs3 = fm
t1 = [Link](0, 1, 1/fs1)
t2 = [Link](0, 1, 1/fs2)
t3 = [Link](0, 1, 1/fs3)
x1 = [Link](2*[Link]*fm*t1)
x2 = [Link](2*[Link]*fm*t2)
x3 = [Link](2*[Link]*fm*t3)
[Link]()
[Link](3,1,1)
[Link](t1,x1)
[Link]('Sampling at Nyquist Rate')
[Link](3,1,2)
[Link](t2,x2)
[Link]('Sampling Above Nyquist Rate')
[Link](3,1,3)
[Link](t3,x3)
[Link]('Sampling Below Nyquist Rate (Aliasing)')
plt.tight_layout()
[Link]()
Expected Output:
• At Nyquist rate, the signal is just adequately sampled
• Above Nyquist rate, the signal is accurately represented
• Below Nyquist rate, aliasing occurs and the signal is distorted
Result:
The sinusoidal signal was successfully sampled at different rates, and the effects of Nyquist
sampling and aliasing were observed.
Conclusion:
The experiment demonstrated the importance of Nyquist rate in signal sampling. It showed
that sampling below the Nyquist rate leads to aliasing, while sampling at or above the
Nyquist rate ensures proper signal representation and reconstruction.
Experiment 9
Aim: To study and implement interpolation (upsampling) and decimation (downsampling) of
a discrete-time signal using MATLAB and Python.
Requirements:
• MATLAB
• Python
• NumPy
• Matplotlib
Theory: Multirate digital signal processing involves changing the sampling rate of a signal.
The two basic operations are interpolation and decimation. Interpolation is the process of
increasing the sampling rate of a signal by inserting additional samples between existing
samples. Decimation is the process of decreasing the sampling rate by removing some of the
samples.
In interpolation by a factor 𝐿, 𝐿 − 1zeros are inserted between each sample of the original
sequence. This operation increases the sampling rate, but introduces spectral images, which
are removed using a low-pass filter. The mathematical representation of interpolation is
𝑥(𝑛/𝐿), 𝑛 = 0, ±𝐿, ±2𝐿, …
𝑦(𝑛) = {
0, otherwise
In decimation by a factor 𝑀, every 𝑀-th sample is retained and the rest are discarded. Before
decimation, a low-pass filter is applied to avoid aliasing. The mathematical representation is
𝑦(𝑛) = 𝑥(𝑛𝑀)
These operations are widely used in applications such as audio processing, communication
systems, image processing, and efficient implementation of digital filters.
MATLAB Code:
clc;
clear;
close all;
% Original signal
x = [1 2 3 4];
n = 0:length(x)-1;
% Interpolation factor
L = 2;
% Upsampling (inserting zeros)
x_up = zeros(1, L*length(x));
x_up(1:L:end) = x;
% Decimation factor
M = 2;
% Downsampling
x_down = x(1:M:end);
figure
subplot(3,1,1)
stem(n,x,'filled')
title('Original Signal')
grid on
subplot(3,1,2) stem(0:length(x_up)-
1,x_up,'filled') title('Interpolated
Signal (Upsampled)') grid on
subplot(3,1,3) stem(0:length(x_down)-1,x_down,'filled') title('Decimated Signal
(Downsampled)') grid on
MATLAB Output:
Python Code:
import numpy as np
import [Link] as plt
# Original signal
x = [Link]([1, 2, 3,
4])
n = [Link](len(x))
# Interpolation factor
L = 2
# Upsampling
x_up = [Link](L*len(x))
x_up[::L] = x
# Decimation factor
M = 2
# Downsampling
x_down = x[::M]
[Link]()
[Link](3,1,1)
[Link](n,x)
[Link]('Original Signal')
[Link](3,1,2)
[Link]([Link](len(x_up)),x_up)
[Link]('Interpolated Signal (Upsampled)')
[Link](3,1,3)
[Link]([Link](len(x_down)),x_down)
[Link]('Decimated Signal (Downsampled)')
plt.tight_layout() [Link]()
Expected Output:
• Interpolated signal contains inserted zeros between samples
• Sampling rate increases after interpolation
• Decimated signal contains fewer samples
• Sampling rate decreases after decimation
Result:
The interpolation and decimation of the given signal were successfully performed, and the
changes in sampling rate were observed.
Conclusion:
The experiment demonstrated how multirate DSP techniques modify the sampling rate of a
signal. Interpolation increases the number of samples, while decimation reduces them. These
techniques are essential in modern digital signal processing applications.
Experiment 10
Aim: To design and implement IIR filters using MATLAB Filter Designer and analyse their
frequency response.
Requirements:
• MATLAB
• MATLAB Simulator
Theory: Infinite Impulse Response (IIR) filters are digital filters whose impulse response
extends indefinitely due to the presence of feedback. They are derived from analog filter
prototypes such as Butterworth, Chebyshev, and Elliptic filters and converted into digital
form.
The general transfer function of an IIR filter is
H(z) = (b₀ + b₁z⁻¹ + … + bMz⁻M) / (1 + a₁z⁻¹ + … + aNz⁻N)
IIR filters are computationally efficient and require fewer coefficients compared to FIR
filters. Different types of IIR filters include low-pass, high-pass, band-pass, and band-stop
filters, each used to allow or reject specific frequency ranges.
In MATLAB, IIR filters can be designed using the Filter Designer tool, which provides a
graphical interface to select filter specifications and visualize responses such as magnitude,
phase, and impulse response.
Procedure:
1. Open MATLAB and type:
filterDesigner
2. In the Filter Designer window:
o Select Response Type: Lowpass Bandstop
o Select Filter Type: IIR
3. Choose Design Method:
o Butterworth (commonly used in labs)
o Chebyshev Type I or II
o Elliptic
4. Enter Specifications:
o Sampling Frequency (Fs)
o Passband Frequency (Fp)
o Stopband Frequency (Fs)
o Passband Ripple (Ap)
o Stopband Attenuation (As)
5. Click “Design Filter”
6. Analyse results:
o Magnitude Response
o Phase Response
o Impulse Response
7. Export filter coefficients if required.
Output:
IIR Lowpass Stop band filter
Impulse response:
Step response:
Pole-Zero plot:
Expected Output:
• Magnitude response shows clear passband and stopband regions
• Phase response is non-linear
• Filter attenuates unwanted frequencies effectively
• Different filter types show different frequency characteristics
Result:
The IIR filter was successfully designed using MATLAB Filter Designer and its frequency
response was obtained.
Conclusion:
The experiment demonstrated the design and implementation of IIR filters using MATLAB
simulator. It helped in understanding different filter types and their frequency characteristics.
IIR filters are efficient and widely used in practical signal processing applications.