0% found this document useful (0 votes)
14 views38 pages

DSP EXP

The document outlines three experiments conducted using MATLAB to study digital signals, including basic signals, operations on square pulses, and composite signals with FFT analysis. Each experiment includes objectives, theoretical background, source code, observations, applications, and conclusions. The experiments demonstrate the generation, manipulation, and analysis of various signals in the digital domain.

Uploaded by

anuragak021
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)
14 views38 pages

DSP EXP

The document outlines three experiments conducted using MATLAB to study digital signals, including basic signals, operations on square pulses, and composite signals with FFT analysis. Each experiment includes objectives, theoretical background, source code, observations, applications, and conclusions. The experiments demonstrate the generation, manipulation, and analysis of various signals in the digital domain.

Uploaded by

anuragak021
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/ 38

​ ​ ​ ​ ​ ​ ​ ​ ​ Anubhav Pathak (2K22/EC/045)

EXPERIMENT - 01
AIM:
To study and analyse various basic signals in the digital domain using MATLAB.

SOFTWARE USED:
MATLAB Online

THEORY:
In digital signal processing, various basic signals are used as building blocks for constructing more
complex signals. These signals have different properties and can be represented mathematically as
follows:

1.​ Unit Step Signal (u[n]): ​


The step signal is a discontinuous signal that takes 0 for n<0 and 1 for n≥0.
𝑢[𝑛] = {1, 𝑛 >= 0 0, 𝑛< 0

2.​ Unit Ramp Signal (r[n]): ​


The ramp signal increases linearly with time for n≥0 and is 0 for n<0.
𝑟[𝑛] = {𝑛, 𝑛 >= 0 0, 𝑛< 0

3.​ Discrete Time Unit Impulse Signal: ​


It is denoted as δ[n]. The mathematical equation and graph of the discrete-time unit impulse
signal are shown below.
δ[n] = 1 for n = 0
δ[n] = 0 for n ≠ 0

4.​ Sine Signal: ​


The sine signal is a periodic oscillatory signal represented as:
x[n] = A⋅𝑆𝑖𝑛 (2π𝑓𝑛 + ϕ) ​
where A is the amplitude, f is the frequency, and ϕ is the phase shift.

5.​ Exponential Signal: ​


The exponential signal has the form:
𝑎𝑛
x[n]=A⋅ⅇ
where A is the amplitude and α is the growth/decay rate.

1
​ ​ ​ ​ ​ ​ ​ ​ ​ Anubhav Pathak (2K22/EC/045)
SOURCE CODE:
clc; clear all;
close all;
x1 = linspace(-2*pi, 0, 20);
x2 = linspace(0, 2*pi, 20);
X = [x1, x2];
% Define Unit Step Function
u1 = 0*x1 + 1;
u2 = 0*x2;
U = [u2, u1];
% Define Sine Function
S = sin(X);
% Define Exponential Function
E = exp(X);
% Define Unit Ramp Function
r1 = 0*x1;
r2 = 1*x2;
R = [r1, r2];
% Define Unit Impulse Function
I = X == 0; % Plot Sine Function
subplot(3,2,1);
stem(X, S, 'r')
grid on;
xlabel 'Time'
ylabel 'Amplitude'
title 'Sine function (Anubhav Pathak EC/45)'
% Plot Unit Step Function
subplot(3,2,2);
stem(X, U, 'b')
grid on;
xlabel 'Time'
ylabel 'Amplitude'
title 'Unit Step Function (Anubhav Pathak EC/45)'
ylim([-1.5 1.5]);
% Plot Unit Ramp Function
subplot(3,2,3);
stem(X, R, 'g')
grid on;
xlabel 'Time'
ylabel 'Amplitude'
title 'Unit Ramp Function (Anubhav Pathak EC/45)'
ylim([-1 3]);
% Plot Exponential Function
subplot(3,2,4);
stem(X, E, 'c')
grid on;
xlabel 'Time'
ylabel 'Amplitude'
title 'Exp Function (Anubhav Pathak EC/45)'
ylim([-1 3]);
% Plot Unit Impulse Function
subplot(3,2,5);

2
​ ​ ​ ​ ​ ​ ​ ​ ​ Anubhav Pathak (2K22/EC/045)
stem(X, I, 'm')
grid on;
xlabel 'Time'
ylabel 'Amplitude'
title 'Unit Impulse Function (Anubhav Pathak EC/45)'
subplot(3,2,6);
stem(X, S, 'r.') % Sine function
hold on;
stem(X, U, 'b.') % Unit Step
hold on;
stem(X, R, 'g.') % Unit Ramp
hold on;
stem(X, I, 'm.') % Unit Impulse
hold on;
stem(X, E, 'c.') % Exponential Function
ylim([-3 3]);
grid on;
xlabel 'Time'
ylabel 'Amplitude'
title 'All Signals (Anubhav Pathak EC/45)'
legend('Sine Function', 'Unit Step', 'Unit Ramp', 'Unit Impulse', 'Exponential')

OUTPUT:

3
​ ​ ​ ​ ​ ​ ​ ​ ​ Anubhav Pathak (2K22/EC/045)
OBSERVATIONS:
1.​ Step Signal (u[n]): ​
It has a value of 0 for n<0 and 1 for n>=0 (for non-negative values).

2.​ Ramp Signal (r[n]): ​


It starts from 0 for n<=0 and zero till it reaches a time which is > 0, and then increases
linearly as n increases

3.​ Unit Impulse Signal (δ[n]):​


It exists only at t=0 and zero everywhere else, and at t=0 unit impulse signal rises to infinity.

4.​ Sine Signal (x[n]): ​


It oscillates sinusoidally with a specified frequency and phase.

5.​ Exponential Signal (x[n]): ​


which shows the exponentially increasing function

APPLICATIONS:
1.​ Step Signal: The step function is used to model signals that suddenly change at a specific
point in time (e.g., turning on a switch).
2.​ Ramp Signal: The ramp function is useful in representing signals that increase linearly over
time, often used in control systems.
3.​ Delta Signal: The delta function is an idealised signal used in systems analysis, such as in
convolution or impulse response studies.
4.​ Sine Signal: The sine wave is a fundamental signal in signal processing, widely used to
represent periodic phenomena like sound waves.
5.​ Exponential Signal: The exponential signal is often used in systems analysis, particularly in
characterising growth and decay processes (e.g., in electronics or population dynamics).

CONCLUSION:
The signals were successfully generated and plotted in MATLAB, showing expected characteristics
and behaviour. This study analyzed different types of signals used in digital signal processing. Each
signal has unique applications in system modelling, analysis, and design.

4
​ ​ ​ ​ ​ ​ ​ ​ ​ Anubhav Pathak (2K22/EC/045)
EXPERIMENT - 02
AIM:
To perform basic operations such as Time Shifting, Time Reversal, and Time Scaling on a Square
Pulse in MATLAB

SOFTWARE USED:
MATLAB Online

THEORY:
1.​ Square Pulse Definition:
A square pulse is a signal with constant amplitude (usually 1) over a specific time interval
and zero elsewhere.
a.​ Mathematical Representation:
​ 𝑥(𝑡) = {1, 𝑖𝑓 − 1 ≤ 𝑡 ≤ 1; 0, 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒
b.​ MATLAB LOGIC:
​ 𝑥(𝑡) = (𝑡 ≥ − 1) & (𝑡 ≤ 1)

2.​ Time Shifting: Shifts the signal along the time axis.
a.​ Right Shift (Delay): 𝑥(𝑡 − 𝑡o) shifts the pulse right by 𝑡o.
b.​ Left Shift (Advance): 𝑥(𝑡 + 𝑡o) shifts it left.
c.​ Example:
​ ​ 𝒙_𝒔𝒉𝒊𝒇𝒕 = (𝒕 ≥ (−𝟏 + 𝟐)) & (𝒕 ≤ (𝟏 + 𝟐)) % shifts right by 2

3.​ Time Reversal (Folding): Flips the signal around the vertical axis.
a.​ Formula: 𝑥(−𝑡)
b.​ Example:
𝒙_𝒓ⅇ𝒗ⅇ𝒓𝒔ⅇ = (−𝒕 ≥ −𝟏 ) & (−𝒕 ≤ 𝟏)

4.​ Time Scaling: Compresses or stretches the signal along the time axis.
a.​ Compression: 𝑥(𝑘𝑡) 𝑓𝑜𝑟 𝑘>1.
b.​ Stretching: 𝑥(𝑘𝑡) 𝑓𝑜𝑟 0<𝑘<1. ​
c.​ Example:
x_𝒔𝒄𝒂𝒍ⅇ = (𝟐∗𝒕 ≥ −𝟏 ) & (𝟐∗𝒕 ≤ 𝟏)

SOURCE CODE:
% Time vector for continuous plotting
t = -5:0.01:5;
x = (t >= -1) & (t <= 1);
% Plot Original Square Pulse
subplot(4,1,1);
plot(t, x, 'b', 'LineWidth', 2);
grid on;
5
​ ​ ​ ​ ​ ​ ​ ​ ​ Anubhav Pathak (2K22/EC/045)
xlabel('Time');
ylabel('Amplitude');
title('Original Square Pulse (Anubhav Pathak EC/45)');
ylim([-0.5 1.5]); % Adjust Y-axis for clarity
% Time Shifting: Shift Right by 2 Units (x(t - 2))
x_shift = (t >= ( -1 + 2)) & (t <= (1 + 2)); % Shifted to the right by 2 units
subplot(4,1,2);
plot(t, x_shift, 'r', 'LineWidth', 2);
grid on;
xlabel('Time');
ylabel('Amplitude');
title('Time Shifted Square Pulse: x(t - 2)');
ylim([-0.5 1.5]);
% Time Reversal: Flip Signal (x(-t))
x_reverse = (-t >= -1) & (-t <= 1); % Time-reversed pulse
subplot(4,1,3);
plot(t, x_reverse, 'g', 'LineWidth', 2);
grid on;
xlabel('Time');
ylabel('Amplitude');
title('Time Reversed Square Pulse: x(-t)');
ylim([-0.5 1.5]);
%Time Scaling: Compress by Factor of 2 (x(2t))
x_scale = ((2*t) >= -1) & ((2*t) <= 1); % Compressed in time
subplot(4,1,4);
plot(t, x_scale, 'm', 'LineWidth', 2);
grid on;
xlabel('Time');
ylabel('Amplitude');
title('Time Scaled Square Pulse: x(2t)');
ylim([-0.5 1.5]);

OUTPUT:

6
​ ​ ​ ​ ​ ​ ​ ​ ​ Anubhav Pathak (2K22/EC/045)
OBSERVATIONS:
1.​ Original Square Pulse:
●​ Defined between 1-1−1 and 111 with amplitude 1.
●​ Acts as a basic building block for many signals.
2.​ Time Shifting (𝑥(𝑡 − 𝑡o)):
●​ Right Shift (Delay): Pulse moves to the right by t0t_0t0 units.
●​ Left Shift (Advance): Pulse moves to the left.
●​ Observation: The shape remains unchanged, only its position changes.
3.​ Time Reversal (𝑥(−𝑡)):
●​ Flips the pulse around the vertical axis (mirror image).
●​ Observation: Useful for analyzing system responses in reverse order.
4.​ Time Scaling (𝑥(𝑘𝑡)):
●​ Compression (k > 1): Pulse becomes narrower.
●​ Stretching (0 < k < 1): Pulse becomes wider.
●​ Observation: Affects the duration of the pulse without changing its amplitude.

APPLICATIONS:
1.​ Communication Systems:
●​ Pulse Modulation (e.g., PAM): Square pulses carry information in digital communication.
●​ Time Shifting: Synchronizing signals during transmission and reception.
2.​ Signal Processing:
●​ Filters: These are used to design and analyze filters (like rectangular window functions).
●​ Time Reversal: Helps determine system outputs in convolution operations.
3.​ Control Systems:
●​ Testing System Response: Square pulses serve as input signals to observe the system
behavior.
4.​ Radar and Sonar Systems:
●​ Pulse Compression: Enhances resolution by using time-scaled pulses.
5.​ Embedded Systems:
●​ Clock Signals: Square pulses act as timing references in microcontrollers and digital Circuits.

CONCLUSIONS:

Basic signal operations were successfully performed and visualized using MATLAB. These
operations are foundational in signal processing, with numerous real-world applications in
communication, image processing, and control systems.

7
​ ​ ​ ​ ​ ​ ​ ​ ​ Anubhav Pathak (2K22/EC/045)
EXPERIMENT - 03
AIM:
Take a Composite signal (Fs = 2Hz, 5 Hz, 10 Hz), compute the FFT & identify Frequency
components in MATLAB

SOFTWARE USED:
MATLAB Online

THEORY:
Composite Signal:
A composite signal is a combination of multiple sinusoidal signals with different frequencies. In this
case, the composite signal is composed of three frequencies: 2 Hz, 5 Hz, and 10 Hz. The signal can
be represented as:
x(t)=A1 sin(2πf1t) +A2 sin(2πf2t) +A3 sin(2πf3t)
where f1 =2 Hz, f2 =5 Hz, and f3=10 Hz, and A1, A2, A3 are the amplitudes of the respective
signals.

Fast Fourier Transform (FFT):


The Fast Fourier Transform (FFT) is an efficient algorithm to compute the Discrete Fourier
Transform (DFT) of a signal. The DFT converts a time-domain signal into its frequency-domain
representation, revealing the frequency components present in the signal. The FFT is widely used in
signal processing to analyze the frequency content of signals.

The Fourier Transform (FT) is a mathematical tool that decomposes a function (often a signal or
waveform) into its constituent frequencies. It converts a time-domain signal into its
frequency-domain representation.

Sampling Frequency:
The sampling frequency (Fs) is the number of samples per second taken from the continuous signal
to convert it into a discrete signal. According to the Nyquist-Shannon sampling theorem, the
sampling frequency should be at least twice the highest frequency present in the signal to avoid
aliasing.

SOURCE CODE:
% Step 1: Define Signal Parameters
Fs = 100;
% Sampling frequency (Hz)
T = 1;
t = 0:1/Fs:T-1/Fs;
f1 = 2;
f2 = 5;
f3 = 10;
% Time duration (seconds)

8
​ ​ ​ ​ ​ ​ ​ ​ ​ Anubhav Pathak (2K22/EC/045)
% Time vector
% Frequency component 1 (Hz)
% Frequency component 2 (Hz)
% Frequency component 3 (Hz)
% Step 2: Generate the Composite Signal in Time Domain
signal = sin(2*pi*f1*t) + sin(2*pi*f2*t) + sin(2*pi*f3*t);
% Step 3: Compute the FFT for Frequency Domain Analysis
N = length(signal);
% Number of samples
fft_result = fft(signal);
% Compute FFT
fft_magnitude = abs(fft_result); % Magnitude of FFT
frequencies = (0:N-1)*(Fs/N);
% Frequency vector
% Step 4: Plot Time Domain Signal
figure;
subplot(3, 1, 1);
plot(t, signal, 'LineWidth', 1.5);
xlabel('Time (s)');
ylabel('Amplitude');
title('Time Domain: Composite Signal (2 Hz, 5 Hz, 10 Hz)');
grid on;
% Step 5: Plot Frequency Domain (Magnitude Spectrum)
subplot(3, 1, 2);
stem(frequencies, fft_magnitude, 'LineWidth', 1.5);
xlabel('Frequency (Hz)');
ylabel('Magnitude');
title('Frequency Domain: FFT (Stem) of Composite Signal');
xlim([0 15]); % Limit x-axis to show frequencies up to 15 Hz
grid on;
subplot(3, 1, 3);
plot(frequencies, fft_magnitude, 'LineWidth', 1.5);
xlabel('Frequency (Hz)');
ylabel('Magnitude');
title('Frequency Domain: FFT (Plot) of Composite Signal');
xlim([0 15]); % Limit x-axis to show frequencies up to 15 Hz
grid on;
sgtitle('Fig 3.1 Composite Signals by Anubhav Pathak EC/45');
% Step 6: Display Identified Frequency Components
disp('Identified Frequency Components (Hz):');
significant_frequencies = frequencies(fft_magnitude > 1); % Threshold to identify significant
frequencies
disp(significant_frequencies);

9
​ ​ ​ ​ ​ ​ ​ ​ ​ Anubhav Pathak (2K22/EC/045)
OUTPUT:

OBSERVATION:
1.​ The input signal is constructed as:
​ ​ x(t)=A1 sin(2πf1t) +A2 sin(2πf2t) +A3 sin(2πf3t)
where A1, A2, and A3 are the amplitudes of the sine waves.
2.​ The FFT is computed, and its magnitude spectrum is plotted.
3.​ Peaks in the frequency spectrum are observed at 2Hz, 5Hz, and 10Hz, confirming the
presence of these components.

CONCLUSION:
1.​ The FFT successfully identifies the frequency components of the composite signal.
2.​ The peaks in the magnitude spectrum correspond to the expected frequencies.
3.​ This experiment validates that FFT can decompose a time-domain signal into its
frequency components.

10
​ ​ ​ ​ ​ ​ ​ ​ ​ Anubhav Pathak (2K22/EC/045)
EXPERIMENT - 04
AIM:
Generate a Sine wave at multiple frequencies (Fs = 2Hz, 5Hz, 10Hz), sample it at
a) Greater than
b) Equal To
c) below Nyquist and observe the aliasing effect.
Then, reconstruct the signal using interpolation in MATLAB

SOFTWARE USED:
MATLAB online

THEORY:
The Nyquist-Shannon Sampling Theorem states that to accurately reconstruct a continuous signal
from its samples, the sampling frequency (F ) must be at least twice the highest frequency (Fₙ)
present in the signal (F ≥ 2Fₙ).
●​ If F > 2Fₙ, the signal is properly sampled and can be perfectly reconstructed.
●​ If F = 2Fₙ, the signal is sampled at the Nyquist rate, but reconstruction is challenging due
to Quantization and noise.
●​ If F < 2Fₙ, aliasing occurs, where higher frequencies appear as lower frequencies in the
sampled signal.
This experiment demonstrates the effect of sampling on sine waves of 2 Hz, 5Hz, and 10Hz at three
different sampling rates:
1.​ Above Nyquist (F > 2Fₙ)
2.​ At Nyquist (F = 2Fₙ)
3.​ Below Nyquist (F < 2Fₙ)
We will then reconstruct the signal using interpolation to observe the impact of sampling rates.
Aliasing Effect
If Fs<2Fmax, the reconstructed signal appears at a lower frequency (aliased frequency):
f alias=∣f−kFs∣
where k is an integer.
Reconstruction Using Interpolation
Interpolation reconstructs the continuous signal from samples. Common methods include:
Linear interpolation (piecewise linear approximation) Sinc interpolation (ideal reconstruction)

SOURCE CODE:
clear all;
close all;
clc;
%% Generate a continuous composite signal
fs_cont = 1000; % High sampling rate for the original signal
t_cont = linspace(0, 1, fs_cont); % 1-second duration
signal = sin(2*pi*2*t_cont) + sin(2*pi*5*t_cont) + sin(2*pi*10*t_cont);
%% Define sampling rates
fs_high = 50; % Above Nyquist rate
fs_nyquist = 20; % At Nyquist rate (for a maximum frequency of 10Hz, Nyquist rate is 20Hz)
11
​ ​ ​ ​ ​ ​ ​ ​ ​ Anubhav Pathak (2K22/EC/045)
fs_low = 12; % Below Nyquist rate (Aliasing occurs)
%% Sample the signal at different rates
t_high = linspace(0, 1, fs_high);
signal_high = sin(2*pi*2*t_high) + sin(2*pi*5*t_high) + sin(2*pi*10*t_high);
t_nyquist = linspace(0, 1, fs_nyquist);
signal_nyquist = sin(2*pi*2*t_nyquist) + sin(2*pi*5*t_nyquist) + sin(2*pi*10*t_nyquist);
t_low = linspace(0, 1, fs_low);
signal_low = sin(2*pi*2*t_low) + sin(2*pi*5*t_low) + sin(2*pi*10*t_low);
%% FFT Analysis to observe frequency components
function plot_fft(signal, fs, title_text)
N = length(signal);
fft_vals = abs(fft(signal));
freqs = (0:N-1)*(fs/N);
figure;
plot(freqs(1:N/2), fft_vals(1:N/2)); % Plot only positive frequencies
xlabel('Frequency (Hz)');
ylabel('Magnitude');
title(title_text);
grid on;
end
%% Plot original and sampled signals
figure('Position', [100, 100, 1000, 600]);
plot(t_cont, signal, 'LineWidth', 1.5, 'DisplayName', 'Original Signal - Anubhav Pathak
(2K22/EC/45)');
hold on;
scatter(t_high, signal_high, 'r', 'o', 'filled', 'DisplayName', 'Sampled (Above Nyquist)');
scatter(t_nyquist, signal_nyquist, 'g', 's', 'filled', 'DisplayName', 'Sampled (At Nyquist)');
scatter(t_low, signal_low, 'b', 'x', 'DisplayName', 'Sampled (Below Nyquist - Aliased)');
xlabel('Time (s)');
ylabel('Amplitude');
title('Original Signal and Sampled Versions - Anubhav Pathak (2K22/EC/45)');
legend('Location', 'best');
grid on;
hold off;
%% FFT Plots to observe aliasing
plot_fft(signal_high, fs_high, 'FFT - Above Nyquist - Anubhav Pathak (2K22/EC/45)');
plot_fft(signal_nyquist, fs_nyquist, 'FFT - At Nyquist - Anubhav Pathak (2K22/EC/45)');
plot_fft(signal_low, fs_low, 'FFT - Below Nyquist (Aliasing Expected) - Anubhav Pathak
(2K22/EC/45)');
%% Interpolation for signal reconstruction from the Nyquist sampled data
t_interp = linspace(0, 1, fs_cont);
reconstructed_signal = interp1(t_nyquist, signal_nyquist, t_interp, 'linear', 'extrap');
%% Plot reconstructed signal
figure('Position', [100, 100, 1000, 500]);
plot(t_cont, signal, 'LineWidth', 1.5, 'DisplayName', 'Original Signal - Anubhav Pathak
(2K22/EC/45)');

12
​ ​ ​ ​ ​ ​ ​ ​ ​ Anubhav Pathak (2K22/EC/045)
hold on;
plot(t_interp, reconstructed_signal, '--', 'LineWidth', 1.5, 'Color', 'r', 'DisplayName', 'Reconstructed
Signal (Linear Interpolation)');
xlabel('Time (s)');
ylabel('Amplitude');
title('Signal Reconstruction using Interpolation - Anubhav Pathak (2K22/EC/45)');
legend('Location', 'best');
grid on;
hold off;

OUTPUT:

13
​ ​ ​ ​ ​ ​ ​ ​ ​ Anubhav Pathak (2K22/EC/045)

14
​ ​ ​ ​ ​ ​ ​ ​ ​ Anubhav Pathak (2K22/EC/045)
OBSERVATION:
1.​ An original signal with multiple frequencies is simulated
2.​ When sampling above the Nyquist rate (fs=50Hz), the signal is captured accurately.
3.​ When sampling at the Nyquist rate (fs=20Hz), the signal is still reconstructed
correctly but may have minor distortions.
4.​ When sampling below the Nyquist rate (fs=12Hz), aliasing occurs, meaning
high-frequency components appear as lower frequencies, distorting the original signal.

5.​ Using interpolation, we can reconstruct the original signal from the sampled points.

CONCLUSION:
●​ The Nyquist theorem holds true: sampling below the Nyquist rate leads to aliasing.
●​ Higher sampling rates improve accuracy but require more storage and processing.
●​ Interpolation can reconstruct signals, but if aliasing has already occurred, the original signal
cannot be fully recovered.

15
​ ​ ​ ​ ​ ​ ​ ​ ​ Anubhav Pathak (2K22/EC/045)
EXPERIMENT - 05
AIM:
To implement discrete-time convolution in the digital domain

SOFTWARE USED:
MATLAB Online

THEORY:
Discrete Time Convolution
Discrete-time convolution is a fundamental operation in digital signal processing that describes how
an input signal is modified by a system's impulse response. The convolution operation combines two
sequences to produce a third sequence that represents how the shape of one is modified by the other.
Mathematical Definition
For two discrete-time signals x[n] (input signal) and h[n] (impulse response), the convolution y[n] is
defined as:
y[n] = x[n] * h[n] = ∑ x[k]·h[n-k] for k = -∞ to ∞
In practice, for finite-length sequences of length M and N, the convolution result has length M+N-1.
Key Properties:-
1.​ Commutative: x[n] * h[n] = h[n] * x[n]
2.​ Associative: (x[n] * h1[n]) * h2[n] = x[n] * (h1[n] * h2[n])
3.​ Distributive: x[n] * (h1[n] + h2[n]) = x[n] * h1[n] + x[n] * h2[n]
Fast Fourier Transform (FFT):
The Fast Fourier Transform (FFT) is an efficient algorithm to compute the Discrete Fourier
Transform (DFT) of a signal. The DFT converts a time-domain signal into its frequency-domain
representation, revealing the frequency components present in the signal. The FFT is widely used in
signal processing to analyze the frequency content of signals.

The Fourier Transform (FT) is a mathematical tool that decomposes a function (often a signal or
waveform) into its constituent frequencies. It converts a time-domain signal into its
frequency-domain representation

SOURCE CODE:
x = [1, 2, 3, 4];
h = [0.5, 0.5, 0.5];
% Zero-padding to length M+N-1
M = length(x);
N = length(h);
L = M + N - 1;
% FFT-based convolution
X = fft(x, L);
H = fft(h, L);
Y = X .* H;
y_freq = ifft(Y, 'symmetric');
% Compare with time domain
y_time = conv(x, h);

16
​ ​ ​ ​ ​ ​ ​ ​ ​ Anubhav Pathak (2K22/EC/045)
disp('Frequency domain result:'); disp(y_freq);
disp('Time domain result:'); disp(y_time);
disp('Difference:'); disp(y_freq - y_time);
% Plotting
figure;
subplot(3,1,1);
stem(x, 'filled', 'LineWidth', 1.5, 'Color', 'b');
title('Input Signal x[n]');
xlabel('Discrete Time Index (n)');
ylabel('Amplitude');
xlim([0 length(y_freq)+1]);
grid on;
subplot(3,1,2);
stem(h, 'filled', 'LineWidth', 1.5, 'Color', 'r');
title('Impulse Response h[n]');
xlabel('Discrete Time Index (n)');
ylabel('Amplitude');
xlim([0 length(y_freq)+1]);
grid on;
subplot(3,1,3);
stem(y_freq, 'filled', 'LineWidth', 1.5, 'Color', 'r');
title('FFT-Based Convolution Output y[n]');
xlabel('Discrete Time Index (n)');
ylabel('Amplitude');
xlim([0 length(y_freq)+1]);
grid on;
sgtitle('Frequency Domain Convolution - Anubhav Pathak (2K22/EC/45)');

OUTPUT:

17
​ ​ ​ ​ ​ ​ ​ ​ ​ Anubhav Pathak (2K22/EC/045)
OBSERVATION:
1.​ Input Signal x[n] Plot (Blue)
●​ Signal Characteristics: Shows a simple 4-sample ramp signal [1, 2, 3, 4]
●​ Visual Representation: Discrete stem plot with:
-​ Clear marker spacing at n=0,1,2,3
-​ Linear amplitude progression is visible.
Key Feature: The perfect linear increase makes this an ideal test case for verifying
convolution behavior
2.​ Impulse Response h[n] Plot (Red)
●​ Filter Type: 3-tap moving average filter [0.5, 0.5, 0.5]
●​ Visual Characteristics:
-​ Three equal-amplitude samples at n=0,1,2
-​ Symmetrical structure indicates linear phase response
●​ Expected Effect: Will smooth the input signal by averaging neighboring samples
3.​ FFT-Based Convolution Output y[n] Plot (Green)
●​ Output Length: Correctly shows 6 samples (M+N-1 = 4+3-1)
●​ Edge Effects: ​
- Initial ramp-up (n=0,1) as filter "fills" with input samples.
-​ Final ramp-down (n=4,5) as filter "empties"
●​ Steady-State:
-​ The central region (n=2,3) shows proper smoothed values
-​ Output peaks at n=3 with value 3.0 (correct weighted average)
●​ Verification:
-​ Perfect match between frequency/time domain results (zero difference)
-​ Output values: [0.5, 1.5, 3.0, 4.5, 3.5, 2.0]

CONCLUSION:
1.​ Discrete-time convolution is a powerful tool for analyzing and processing digital signals.
2.​ The choice of implementation method depends on:
◦ Sequence lengths
◦ Required precision
◦ Computational resources
3.​ Understanding convolution is fundamental to digital signal processing, as it forms the basis
for:
◦ Filter design and implementation
◦ System analysis
◦ Many image processing operations
4.​ The equivalence of time-domain and frequency-domain methods (via the Convolution
Theorem) provides flexibility in implementation approaches.

This implementation and analysis demonstrate the core concepts of discrete-time convolution and its
practical application in MATLAB, forming a foundation for more advanced digital signal processing
techniques.

18
​ ​ ​ ​ ​ ​ ​ ​ ​ Anubhav Pathak (2K22/EC/045)
EXPERIMENT - 06
AIM:
Write a program to compute in DTFT of the given sequence x[n] and compute an n-point DFT

SOFTWARE USED:
MATLAB Online

THEORY:
The Fourier Transform decomposes signals into frequency components. CTFT handles
continuous-time signals, DTFT processes discrete-time sequences, and DFT (computed via FFT)
analyzes finite discrete signals. Each has forward/inverse formulas, with unique properties like
linearity and convolution. DFT samples DTFT, while FFT optimizes DFT computation. Used in
signal processing, audio, and communications.
Discrete-Time Fourier Transform (DTFT)
The DTFT is a Fourier transform that converts a discrete-time sequence into its frequency domain
representation. For a sequence x[n], the DTFT is given by:
X(ω) = ∑[n=-∞ to ∞] x[n]e^(-jωn)
Where:
●​ X(ω) is the DTFT of x[n]
●​ ω is the angular frequency (radians/sample)
Key properties:
1.​ Periodicity: X(ω) is periodic with period 2π
2.​ Inverse DTFT: x[n] = (1/2π) ∫[-π to π] X(ω)e^(jωn) dω
Discrete Fourier Transform (DFT)
The DFT is a sampled version of the DTFT, computed at N equally spaced frequencies between 0
and 2π. For a finite-length sequence x[n] of length N, the DFT is:
X[k] = ∑[n=0 to N-1] x[n]e^(-j(2π/N)kn), k = 0,1,...,N-1
Inverse DFT:
x[n] = (1/N) ∑[k=0 to N-1] X[k]e^(j(2π/N)kn), n = 0,1,...,N-1
Relationship between DTFT and DFT
The DFT X[k] consists of samples of the DTFT X(ω) at frequencies ω_k = 2πk/N:
X[k] = X(ω)|ω=2πk/N

SOURCE CODE:
% DTFT and DFT Computation Example
% Example sequence
x = [1 2 3 4 5 6 7 8]; % Input sequence
N = length(x); % Length of sequence
% DTFT Computation
w = linspace(-pi, pi, 1000); % Frequency vector (-π to π)
X_DTFT = zeros(1, length(w));
for k = 1:length(w)
for n = 1:N
X_DTFT(k) = X_DTFT(k) + x(n)*exp(-1j*w(k)*(n-1));
end
end
19
​ ​ ​ ​ ​ ​ ​ ​ ​ Anubhav Pathak (2K22/EC/045)
% 8-point DFT Computation
n_point = 8; % Using 8-point DFT
X_DFT = fft(x, n_point); % N-point DFT using FFT
% Plotting
figure('Name','DTFT and DFT Analysis','NumberTitle','off');
% Original Sequence
subplot(3,1,1);
stem(0:N-1, x, 'filled', 'LineWidth', 1.5, 'MarkerSize', 6);
title('Original Sequence x[n] = [1 2 3 4 5 6 7 8]');
xlabel('Sample Index (n)');
ylabel('Amplitude');
grid on;
sgtitle('DTFT and DFT Analysis - Anubhav Pathak (2K22/EC/45)');
% DTFT Magnitude
subplot(3,1,2);
plot(w, abs(X_DTFT), 'LineWidth', 1.5);
title('Magnitude of DTFT - Atharv');
xlabel('Normalized Frequency (rad/sample)');
ylabel('|X(\ω)|');
grid on;
% 8-point DFT Magnitude
subplot(3,1,3);
stem(0:n_point-1, abs(X_DFT), 'filled', 'LineWidth', 1.5, 'MarkerSize', 6);
title('Magnitude of 8-point DFT');
xlabel('Frequency Bin (k)');
ylabel('|X[k]|');
grid on;
% Display Results
disp('Original sequence x[n]:');
disp(x);
disp('8-point DFT:');
disp(X_DFT);
disp('Magnitude of 8-point DFT:');
disp(abs(X_DFT));
disp('Phase of 8-point DFT (radians):');
disp(angle(X_DFT));

20
​ ​ ​ ​ ​ ​ ​ ​ ​ Anubhav Pathak (2K22/EC/045)
OUTPUT:

OBSERVATION:
1.​ Original Sequence Plot
• The input sequence x[n] = [1 2 3 4 5 6 7 8] is plotted as discrete stems.
• The amplitude increases linearly from 1 to 8.

2.​ DTFT Magnitude Plot


• The DTFT magnitude |X(ω)| is continuous and periodic with a period of 2π.
• The plot shows variations in magnitude across different frequencies.

3.​ 8-point DFT Magnitude Plot


• The DFT magnitude |X[k]| is discrete and sampled at 8 frequency bins (k = 0 to k = 7).
• DC Component (k=0): The magnitude at k=0 is the sum of all samples (1+2+...+8 = 36).

CONCLUSION:
1.​ DTFT vs. DFT:
◦ The DTFT gives a continuous frequency representation, while the DFT provides a sampled
version at discrete frequencies.
◦ The 8-point DFT matches the DTFT at 8 equally spaced frequencies (ω = 2πk/8).
2.​ Effect of Input Signal:
◦ The linearly increasing input (1,2,...,8) produces a non-symmetric spectrum with energy
distributed across all frequency bins.
◦ The DC component (k=0) is large because the signal has a strong average value.
3.​ Key Findings:
◦ Real signals produce symmetric magnitude spectra (observed in both DTFT and DFT).
◦ DFT resolution depends on the number of points (N=8 here). Increasing N (via zero
padding) would interpolate more frequency samples but not improve true resolution.

4.​ Practical Implications:


◦ DFT (via FFT) is computationally efficient for analyzing finite-length signals.
◦ DTFT is useful for theoretical analysis, but requires numerical approximation in
MATLAB
21
​ ​ ​ ​ ​ ​ ​ ​ ​ Anubhav Pathak (2K22/EC/045)
EXPERIMENT - 07
AIM:
Write a MATLAB program to compute the Inverse Discrete Fourier Transform (IDFT) of a given
sequence X[k] to recover the original time-domain signal x[n] in MATLAB.

SOFTWARE USED:
MATLAB Online

THEORY:
The Inverse Discrete Fourier Transform (IDFT) converts a frequency-domain sequence X[k] back
to its time-domain representation x[n].

The mathematical formula for IDFT is:


x[n]=1/N∑X[k]⋅e^(j 2πkn/N) from k=0 to N-1 where n = 0,1,….,N-1
where:
• x[n] = Time-domain signal
• X[k] = Frequency-domain signal
• N = Length of the sequence

Interpretation:
●​ IDFT is used in signal reconstruction from frequency components.
●​ It is the reverse operation of the DFT.
●​ In practice, the Inverse Fast Fourier Transform (IFFT) is used for fast computation of the
IDFT.

Applications:
●​ Signal reconstruction in communication systems.
●​ Audio/image decoding.
●​ Filtering and spectral shaping.
●​ Signal compression algorithms.

MATLAB provides the ifft() function to compute IDFT efficiently.

SOURCE CODE:
% Original time-domain signal
x = [1, 2, 3, 4];
N = length(x);
% Compute DFT using the formula
X = zeros(1, N);
for k = 0:N-1
for n = 0:N-1
X(k+1) = X(k+1) + x(n+1) * exp(-1j * 2 * pi * k * n / N);
end
end
% Compute IDFT manually

22
​ ​ ​ ​ ​ ​ ​ ​ ​ Anubhav Pathak (2K22/EC/045)
x_idft = zeros(1, N);
for n = 0:N-1
for k = 0:N-1
x_idft(n+1) = x_idft(n+1) + X(k+1) * exp(1j * 2 * pi * k * n / N);
end
x_idft(n+1) = x_idft(n+1) / N;
end
% Plotting Input, DFT, and IDFT results
figure('Position', [100, 100, 800, 600]);
% Plot original input signal
subplot(3, 1, 1);
stem(0:N-1, x, 'b', 'LineWidth', 1.5, 'MarkerFaceColor', 'b');
title('Original Input Sequence x[n]');
xlabel('n');
ylabel('x[n]');
grid on;
% Plot DFT (Magnitude Spectrum)
subplot(3, 1, 2);
stem(0:N-1, abs(X), 'r', 'LineWidth', 1.5, 'MarkerFaceColor', 'r');
title('DFT Magnitude |X[k]|');
xlabel('k');
ylabel('|X[k]|');
grid on;
% Plot reconstructed signal using IDFT
subplot(3, 1, 3);
stem(0:N-1, real(x_idft), 'g', 'LineWidth', 1.5, 'MarkerFaceColor', 'g');
title('Reconstructed Sequence using IDFT');
xlabel('n');
ylabel('Re x[n]');
grid on;
% Terminal output for verification
disp('Original Input x[n]:');
disp(x);
disp('DFT X[k]:');
disp(X);
disp('Reconstructed x[n] using IDFT:');
disp(x_idft);
% Add super title
sgtitle('DFT and IDFT Computation');
% Adjust layout
set(gcf, 'Color', 'w'); % White background
set(findall(gcf, 'Type', 'axes'), 'FontSize', 10);
set(findall(gcf, 'Type', 'text'), 'FontWeight', 'bold');
sgtitle('IDFT Computation - Anubhav Pathak (2K22/EC/45)');

23
​ ​ ​ ​ ​ ​ ​ ​ ​ Anubhav Pathak (2K22/EC/045)
OUTPUT:

OBSERVATION:
1.​ Original Input Signal x[n]
◦ The plot shows a discrete-time signal with values [1, 2, 3, 4] at time indices n = 0, 1, 2, 3.
◦ The signal is purely real and increases linearly.

2.​ DFT Magnitude |X[k]|


◦ The magnitude spectrum shows the frequency components of the input signal.
◦ The DFT output is complex, but we plot only the magnitude.

3.​ Reconstructed Signal using IDFT


◦ The IDFT successfully reconstructs the original signal x[n] from X[k].
◦ The reconstructed signal matches the original input exactly (within floating-point
precision).

24
​ ​ ​ ​ ​ ​ ​ ​ ​ Anubhav Pathak (2K22/EC/045)

CONCLUSION:
1.​ Successful Reconstruction:
◦ The IDFT perfectly reconstructs the original time-domain signal from its DFT coefficients,
demonstrating the reversibility of the DFT-IDFT pair.
2.​ Numerical Accuracy:
◦ The manual computation of DFT and IDFT matches MATLAB’s expected behavior,
confirming the correctness of the implementation.
◦ Small numerical errors (if any) are due to floating-point precision limitations.
3.​ Key Learnings:
◦ DFT-DFT Duality: The forward DFT and inverse DFT are mathematically consistent.
◦ Time-Frequency Representation: The plots clearly distinguish between the time-domain and
frequency-domain representations.
◦ Indexing in MATLAB: Unlike Python (0-based), MATLAB uses 1-based indexing,
requiring adjustments in loop indices.
4.​ Applications:
◦ This experiment validates the fundamental concept of Fourier analysis, which is crucial in:
▪ Signal filtering
▪ Spectral analysis
▪ Digital communications
▪ Image processing

25
​ ​ ​ ​ ​ ​ ​ ​ ​ Anubhav Pathak (2K22/EC/045)

EXPERIMENT - 08
AIM:
To design and analyze Finite Impulse Response (FIR) low-pass and high-pass filters by
approximating a Butterworth filter’s impulse response, and observing their frequency responses
(magnitude and phase) using MATLAB.

SOFTWARE USED:
MATLAB Online

THEORY:
FIR Filter Design Using Butterworth Approximation
Finite Impulse Response (FIR) filters can be designed by approximating the impulse response of an
analog Butterworth filter. The Butterworth filter is known for its maximally flat frequency response
in the passband.

Butterworth Filter Characteristics:


The magnitude-squared response of an Nth-order Butterworth low-pass filter is:
|Hₐ(jΩ)|² = 1 / [1 + (Ω/Ω )²ᴺ]
Where:
• Ωₙ is the cutoff frequency (rad/s)
• N is the filter order
• Ω is the angular frequency (rad/s)
Impulse Invariance Method
To create an FIR approximation of the Butterworth filter, we can use the impulse invariance method:
1.​ Design an analog Butterworth filter with cutoff frequency Ωₙ.
2.​ Compute its impulse response hₐ(t).
3.​ Sample hₐ(t) to obtain the discrete-time impulse response h[n] = T ·hₐ(nT ).
4.​ Truncate the infinite impulse response to create a finite-length FIR filter.
The impulse response of an analog Butterworth filter is:

hₐ(t) = ℒ⁻¹{Hₐ(s)}

Where ℒ⁻¹ denotes the inverse Laplace transform.


Frequency Response of FIR Filters
The frequency response of an FIR filter with coefficients h[n] is:
​​ ​ ​ ​ H(eʲʷ) = Σ h[n]e⁻ʲʷⁿ
Where the summation is from n=0 to M-1 for an M-tap filter.

Low-Pass to High-Pass Transformation


A high-pass FIR filter can be derived from a low-pass prototype using the transformation:
hₕₚ[n] = (-1)ⁿ·hₗₚ[n]
This shifts the frequency response by π radians/sample.

26
​ ​ ​ ​ ​ ​ ​ ​ ​ Anubhav Pathak (2K22/EC/045)

SOURCE CODE:
% FIR Low-Pass & High-Pass Filter Design using Butterworth Approximation
clc;clear all;close all;
% Parameters
fs = 1000;
fc = 100;
order = 4;
fir_length = 101;
% Sampling frequency (Hz)
% Cutoff frequency (Hz)
% Butterworth filter order
% FIR filter length (odd for symmetry)
% Normalized cutoff frequency
wc = 2*pi*fc/fs;
% Design an analog Butterworth filter
[b, a] = butter(order, wc, 's');
% Time vector for impulse response
t = 0:1/fs:(fir_length-1)/fs;
% Compute analog impulse response
h_analog = impulse(tf(b, a), t);
% Create FIR filter (sampled & truncated impulse response)
h_fir_lp = h_analog(1:fir_length) * fs;
% High-pass transformation
h_fir_hp = h_fir_lp .* (-1).^(0:fir_length-1)';
% Frequency response analysis
N_fft = 1024;
[H_lp, w] = freqz(h_fir_lp, 1, N_fft);
[H_hp, w] = freqz(h_fir_hp, 1, N_fft);
f = w * fs / (2*pi); % Convert to Hz
% Magnitude Response (dB)
figure;
subplot(2, 1, 1);
plot(f, 20*log10(abs(H_lp)), 'b', 'LineWidth', 1.5);
hold on;
plot(f, 20*log10(abs(H_hp)), 'r', 'LineWidth', 1.5);
grid on;
title('Magnitude Response (dB)');
xlabel('Frequency (Hz)');
ylabel('Magnitude (dB)');
legend('Low-Pass FIR', 'High-Pass FIR');
xlim([0 fs/2]);
% Phase Response (Radians)
subplot(2, 1, 2);
plot(f, unwrap(angle(H_lp)), 'b', 'LineWidth', 1.5);
hold on;

27
​ ​ ​ ​ ​ ​ ​ ​ ​ Anubhav Pathak (2K22/EC/045)
plot(f, unwrap(angle(H_hp)), 'r', 'LineWidth', 1.5);
grid on;
title('Phase Response (Radians)');
xlabel('Frequency (Hz)');
ylabel('Phase (rad)');
legend('Low-Pass FIR', 'High-Pass FIR');
xlim([0 fs/2]);
sgtitle('FIR Filter Design using Butterworth Approximation - Anubhav Pathak (2K22/EC/45)');

OUTPUT:

OBSERVATIONS:
Magnitude Response Plot
• The low-pass filter (blue) shows:
◦ Near 0 dB gain in the passband (0-100 Hz)
◦ Gradual roll-off starting at the cutoff frequency (100 Hz)
◦ Increasing attenuation in the stopband (>100 Hz)
• The high-pass filter (red) shows:
◦ High attenuation in the stopband (0-100 Hz)
◦ Passband gain near 0 dB above 100 Hz
◦ Mirror-image behavior compared to the low-pass filter
​ • Both filters exhibit:
◦ Some ripple in the passband and stopband
◦ Non-ideal transition steepness at cutoff
28
​ ​ ​ ​ ​ ​ ​ ​ ​ Anubhav Pathak (2K22/EC/045)

Phase Response Plot


• Both filters show:
◦ Generally linear phase in the passband
◦ Phase discontinuities at frequency points where the magnitude approaches zero
◦ The high-pass filter has an additional π phase shift due to spectral inversion
• The unwrapped phase reveals:
◦ Consistent group delay across most frequencies.
◦ Non-linearities near the cutoff frequency and stopband.

CONCLUSION:
1.​ Successful Filter Implementation:
◦ Both low-pass and high-pass FIR filters were effectively designed using Butterworth analog
prototypes.
◦ The spectral inversion technique properly transformed the low-pass response to a high-pass.
2.​ Frequency Response Characteristics:
◦ Filters exhibited the expected passband and stopband behavior.
◦ Low-pass filter showed smooth roll-off at the cutoff frequency (100 Hz).
◦ High-pass filter demonstrated proper attenuation below 100 Hz.
3.​ Phase Response:
◦ Linear phase characteristics were maintained in the passbands.
◦ Phase discontinuities observed in stopband regions (expected behavior).
4.​ Design Trade-offs:
◦ Achieved good frequency selectivity with reasonable filter length (101 taps).
◦ Visible trade-off between transition bandwidth and computational complexity.

29
​ ​ ​ ​ ​ ​ ​ ​ ​ Anubhav Pathak (2K22/EC/045)

EXPERIMENT - 09
AIM:
To design and implement Infinite Impulse Response (IIR) low-pass and high-pass filters using the
Butterworth filter design method, and to study their magnitude and phase responses along with their
Effect on a test signal using MATLAB.

SOFTWARE USED:
MATLAB Online

THEORY:
Butterworth IIR Filters

Key Feature:

●​ Maximally flat frequency response in the passband (no ripples).


●​ Smooth transition from passband to stopband.

Magnitude Response:

​ ​ ​ ​ |H(ω)|² = 1 / [1 + (ω/ωc)^(2N)]

where:

• ω is the angular frequency (rad/s)


• ωc is the cutoff frequency (rad/s)
• N is the filter order

Filter Design Steps

The design process typically involves:

1. Designing an analog Butterworth low-pass prototype


2. Applying frequency transformation to get the desired filter type (low-pass, high-pass, etc.)
3. Converting to a digital filter using the bilinear transformation.

The bilinear transformation maps the analog s-plane to the digital z-plane:

s = (2/T)·(1 - z⁻¹)/(1 + z⁻¹)

where T is the sampling period.

SOURCE CODE:

% Parameters for the filter design


fs = 1000;
% Sampling frequency (Hz)
order = 4;
fc_low = 100;
fc_high = 200;
30
​ ​ ​ ​ ​ ​ ​ ​ ​ Anubhav Pathak (2K22/EC/045)
% Filter order
% Cutoff frequency for low-pass filter (Hz)
% Cutoff frequency for high-pass filter (Hz)
% Normalize the cutoff frequencies
nyquist = fs / 2;
wc_low = fc_low / nyquist; % Normalized cutoff for low-pass
wc_high = fc_high / nyquist; % Normalized cutoff for high-pass
% Design IIR Low-Pass Butterworth Filter
[b_low, a_low] = butter(order, wc_low, 'low');
% Design IIR High-Pass Butterworth Filter
[b_high, a_high] = butter(order, wc_high, 'high');
% Compute the frequency response of the filters
N = 1024; % Number of frequency points
[H_low, freq_low] = freqz(b_low, a_low, N, fs);
[H_high, freq_high] = freqz(b_high, a_high, N, fs);
% Plotting the results
figure('Position', [100, 100, 800, 600]);
% Magnitude response (dB)
subplot(2, 1, 1);
plot(freq_low, 20*log10(abs(H_low)), 'LineWidth', 1.5);
hold on;
plot(freq_high, 20*log10(abs(H_high)), 'LineWidth', 1.5);
title('Magnitude Response of IIR Butterworth Filters');
xlabel('Frequency (Hz)');
ylabel('Magnitude (dB)');
grid on;
legend('Low-Pass Filter', 'High-Pass Filter');
xlim([0 fs/2]);
% Phase response (degrees)
subplot(2, 1, 2);
plot(freq_low, angle(H_low)*180/pi, 'LineWidth', 1.5);
hold on;
plot(freq_high, angle(H_high)*180/pi, 'LineWidth', 1.5);
title('Phase Response of IIR Butterworth Filters');
xlabel('Frequency (Hz)');
ylabel('Phase (degrees)');
grid on;
legend('Low-Pass Filter', 'High-Pass Filter');
xlim([0 fs/2]);
sgtitle('IIR Butterworth Filter Design - Anubhav Pathak (2K22/EC/45)');
% Optional: Print filter coefficients
subplot(2, 1, 1)
disp('Low-Pass IIR Filter Numerator (b):');
disp(b_low);
disp('Low-Pass IIR Filter Denominator (a):');
disp(a_low);
disp('High-Pass IIR Filter Numerator (b):');
disp(b_high);
disp('High-Pass IIR Filter Denominator (a):');
disp(a_high);
% Optional: Example of applying the filter to a signal
t = linspace(0, 1, fs); % 1-second time vector
input_signal = sin(2*pi*50*t) + 0.5*sin(2*pi*300*t); % 50 Hz + 300 Hz signal
31
​ ​ ​ ​ ​ ​ ​ ​ ​ Anubhav Pathak (2K22/EC/045)
output_low = filter(b_low, a_low, input_signal); % Apply low-pass filter
output_high = filter(b_high, a_high, input_signal); % Apply high-pass filter
% Plot filtered signals (optional)
figure;
plot(t, input_signal, 'LineWidth', 1.5);
hold on;
plot(t, output_low, 'LineWidth', 1.5);
plot(t, output_high, 'LineWidth', 1.5);
%title('Filtered Signals');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
legend('Input Signal', 'Low-Pass Output', 'High-Pass Output');
sgtitle('Filtered Signal Comparison - Anubhav Pathak (2K22/EC/45)');

OUTPUT:

OBSERVATION:
1.​ Magnitude Response Plot
• Low-Pass Filter (Blue Curve):
◦ Passband (0–100 Hz): Flat magnitude response near 0 dB (minimal
attenuation).
◦ Transition Band (100–200 Hz): Gradual roll-off characteristic of Butterworth
filters.
◦ Stopband (>200 Hz): Attenuation increases monotonically (~24 dB/octave
for 4th-order).
• High-Pass Filter (Red Curve):
◦ Stopband (0–200 Hz): Strong attenuation (increasing toward DC).
◦ Passband (>200 Hz): Flat response near 0 dB.
◦ Transition Band (100–200 Hz): Mirror image of the low-pass filter's roll-off.

32
​ ​ ​ ​ ​ ​ ​ ​ ​ Anubhav Pathak (2K22/EC/045)
2.​ Phase Response Plot
• Nonlinear Phase: Both filters exhibit phase distortion, especially near cutoff
frequencies.
◦ Low-Pass: Phase shift ranges from 0° (DC) to -360° (Nyquist) due to
4th-order delay.
◦ High-Pass: Phase starts at +360° (DC) and approaches 0° (Nyquist).
• Phase Wrapping: MATLAB's angle() function shows discontinuities (use unwrap
for smooth plots).
3.​ Filtered Signal Plot (Optional)
• Input Signal: 50 Hz (in passband of low-pass) + 300 Hz (in passband of high-pass).
• Low-Pass Output:
◦ 50 Hz component preserved (amplitude ~1).
◦ 300 Hz component attenuated (~0).
• High-Pass Output:
◦ 50 Hz component attenuated (~0).
◦ 300 Hz component preserved (amplitude ~0.5).

CONCLUSION:
1.​ Frequency Response Analysis:
◦ The magnitude response of the low-pass filter showed a smooth, monotonically
decreasing transition from the passband to the stopband, effectively attenuating
high-frequency components.
◦ The high-pass filter exhibited the opposite behavior, allowing high frequencies to
pass while attenuating low frequencies.
2.​ Filtering a Test Signal:
◦ When applied to a test signal (e.g., a composite signal with multiple frequencies),
the low-pass filter successfully removed high-frequency noise while preserving the
low-frequency components.
◦ The high-pass filter effectively eliminated low-frequency baseline drift or DC
offsets while retaining high-frequency details. .
3.​ MATLAB Implementation:
◦ MATLAB’s butter() function simplified the design process by automatically
computing filter coefficients.
◦ Frequency response visualization using freqz() helped verify the filter
characteristics.

33
​ ​ ​ ​ ​ ​ ​ ​ ​ Anubhav Pathak (2K22/EC/045)
EXPERIMENT - 10
AIM:
To design an FIR filter using different Windowing techniques in MATLAB
1. Rectangular
2. Kaiser
3. Hamming

SOFTWARE USED:
MATLAB Online

THEORY:
FIR filters are designed to have a finite impulse response, meaning their output depends only on a
finite number of input samples. The windowing method is a common approach to designing FIR
filters because it’s straightforward and effective.

Advantages of the Windowing Method:

●​ Simple and easy to implement.


●​ Offers control over filter characteristics by choosing an appropriate window.
●​ Useful for standard low-pass, high-pass, band-pass, and band-stop filters.

1. Rectangular Window
●​ Rectangular window is the simplest windowing method.
●​ It corresponds to no smoothing — abrupt cut-off of the impulse response.
●​ It has high side lobes, leading to more spectral leakage (poor stopband attenuation).
●​ Not recommended when you need sharp frequency separation or low ripple.

Pros: Simple, easy to compute.​


Cons: Poor frequency selectivity.

2. Hamming Window
●​ Hamming window provides better side lobe suppression than a rectangular window.
●​ It reduces the ripple in both the passband and stopband.
●​ Commonly used when moderate attenuation and good performance are needed.

Pros: Good balance between main lobe width and side lobe attenuation.​
Cons: Less sharp cutoff than some other windows.

34
​ ​ ​ ​ ​ ​ ​ ​ ​ Anubhav Pathak (2K22/EC/045)
3. Kaiser Window

●​ Kaiser window is flexible: it has a parameter β (beta) to control the trade-off between main
lobe width and side lobe attenuation.​
●​ Using Kaiserord, you can design filters with precise specs (ripple, attenuation, transition
width).​
●​ Best for custom or optimized filter specs.​

Pros: Tunable, precise control over filter characteristics.​


Cons: Slightly more complex to design.

SOURCE CODE:

% FIR Filter Design Using Different Windowing Techniques


% Parameters for the filter design
fs = 1000; % Sampling frequency (Hz)
N = 51;
% Filter order (number of taps, odd for symmetry)
fc = 100;
% Cutoff frequency for low-pass filter (Hz)
nyquist = fs / 2;
wc = fc / nyquist; % Normalized cutoff frequency
% Kaiser window parameter (beta controls the side-lobe attenuation)
beta = 5.0; % Adjust beta for Kaiser window (higher beta = lower side lobes)
% Design FIR Low-Pass Filters using different windows
h_rect = fir1(N-1, wc, 'low', rectwin(N)); % Rectangular window
h_kaiser = fir1(N-1, wc, 'low', kaiser(N, beta)); % Kaiser window
h_hamming = fir1(N-1, wc, 'low', hamming(N)); % Hamming window
% Compute frequency response of the filters
[H_rect, freq_rect] = freqz(h_rect, 1, 1024, fs);
[H_kaiser, freq_kaiser] = freqz(h_kaiser, 1, 1024, fs);
[H_hamming, freq_hamming] = freqz(h_hamming, 1, 1024, fs);
% Plotting the results
figure('Position', [100, 100, 800, 600]);
% Magnitude response
subplot(2,1,1);
plot(freq_rect, 20*log10(abs(H_rect)), 'm', 'LineWidth', 1.5);
hold on;
plot(freq_kaiser, 20*log10(abs(H_kaiser)), 'g', 'LineWidth', 1.5);
plot(freq_hamming, 20*log10(abs(H_hamming)), 'y', 'LineWidth', 1.5);
title('Magnitude Response of FIR Low-Pass Filters with Different Windows - Anubhav Pathak
(2K22/EC/45)');
xlabel('Frequency (Hz)');
ylabel('Magnitude (dB)');
grid on;
legend('Rectangular Window', ['Kaiser Window (\beta=' num2str(beta) ')'], 'Hamming Window');
ylim([-100, 5]);
% Phase response
subplot(2,1,2);
plot(freq_rect, angle(H_rect)*180/pi, 'LineWidth', 1.5);
35
​ ​ ​ ​ ​ ​ ​ ​ ​ Anubhav Pathak (2K22/EC/045)
hold on;
plot(freq_kaiser, angle(H_kaiser)*180/pi, 'LineWidth', 1.5);
plot(freq_hamming, angle(H_hamming)*180/pi, 'LineWidth', 1.5);
title('Phase Response of FIR Low-Pass Filters with Different Windows - Anubhav Pathak
(2K22/EC/45)');
xlabel('Frequency (Hz)');
ylabel('Phase (degrees)');
grid on;
legend('Rectangular Window', ['Kaiser Window (\beta=' num2str(beta) ')'], 'Hamming Window');
% Optional: Print filter coefficients
disp('Rectangular Window Coefficients:'); disp(h_rect');
disp(['Kaiser Window (\beta=' num2str(beta) ') Coefficients:']); disp(h_kaiser');
disp('Hamming Window Coefficients:'); disp(h_hamming');
% Optional: Apply filters to a test signal
t = linspace(0, 1, fs); % 1-second time vector
input_signal = sin(2*pi*50*t) + 0.5*sin(2*pi*200*t); % 50 Hz + 200 Hz
output_rect = filter(h_rect, 1, input_signal);
output_kaiser = filter(h_kaiser, 1, input_signal);
output_hamming = filter(h_hamming, 1, input_signal);
% Plot filtered signals (optional)
figure;
plot(t, input_signal, 'b', 'LineWidth', 1.5);
hold on;
plot(t, output_rect, 'c', 'LineWidth', 1.5);
plot(t, output_kaiser, 'g', 'LineWidth', 1.5);
plot(t, output_hamming, 'm', 'LineWidth', 1.5);
title('Filtered Signals with Different Windows - Anubhav Pathak 2K22/EC/45');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
legend('Input Signal', 'Rectangular Window Output', 'Kaiser Window Output', 'Hamming Window
Output');

OUTPUT:

36
​ ​ ​ ​ ​ ​ ​ ​ ​ Anubhav Pathak (2K22/EC/045)

OBSERVATION:

1.​ Rectangular Window:


●​ The filter had the narrowest main lobe, indicating a sharp cutoff.
●​ However, it showed high side lobes, resulting in poor stopband attenuation and more
spectral leakage.​

2.​ Hamming Window:


●​ The main lobe was slightly wider than rectangular, but side lobes were significantly
reduced.
●​ Better stopband attenuation was observed, making it more effective for practical
applications.​

3.​ Kaiser Window:


●​ Provided adjustable control over side lobe attenuation and transition width using the β
parameter.
●​ With proper β selection, it achieved a good balance between sharp cutoff and low
ripple.​

4.​ General:
●​ All windows smoothed the transition from passband to stopband differently.
●​ A trade-off exists between transition width (sharpness) and side lobe suppression
(ripple).

CONCLUSION:

In this experiment, FIR filters were successfully designed using different windowing techniques:
Rectangular, Hamming, and Kaiser. Each window demonstrated unique characteristics in terms of
frequency response and filter performance.

●​ The Rectangular window, though simple, showed poor attenuation in the stopband due to
high side lobes.​

●​ The Hamming window offered a good balance with reduced side lobes and improved
stopband performance.​

●​ The Kaiser window provided the most flexibility by allowing control over the filter’s
sharpness and ripple through the β parameter, resulting in superior performance when
properly tuned.​

Overall, window selection plays a crucial role in FIR filter design, affecting both frequency
selectivity and signal quality. Among the three, the Kaiser window proved to be the most efficient
and versatile for practical filter design.

37
​ ​ ​ ​ ​ ​ ​ ​ ​ Anubhav Pathak (2K22/EC/045)

38

You might also like