EEE3100 - BIO SIGNAL AND IMAGE
PROCESSING LABORATORY
LAB ASSESMENT
Name : SAYANI CHATTERJEE
Registration No. : 23BOE10042
Slot No. : C11+C12+C13
Semester : Winter 2024-2025
[Type here]
LIST OF EXPERIMENTS
Serial No. List of experiments Page No.
01. Basic signal processing operations 1-2
02. FFT and IFFT 3-4
03. Linear and Circulation convolution 5-6
04. Autocorrelation and Crosscorrelation 7-8
05. Implementation of PAN Tompkins algorithm 9-11
for QRS detection
06. Application of IIR(Butterworth) 12-13
LPF,HPF,Band pass and Band reject filter
07. Image segmentation using different methods 14-16
08. Medical Image enhancement 17-19
09. Analysis of Spatial and intensity resolution 20-21
of images
10. Image sampling and quantization 22-24
EXPERIMENT NO.: 01
Aim: To perform basic signal processing operations such as addition, multiplication,
shifting, and scaling.
Components Required: MATLAB software
Short Theory: Signal processing involves various fundamental operations applied to
signals such as addition, multiplication, shifting, and scaling. These operations help in
understanding the behavior of signals in different conditions .
Procedure: 1. Open MATLAB.
2. Define signals as arrays.
3. Perform addition, multiplication, shifting, and scaling operations.
4. Display and plot the results.
MATLAB Program:
clc; clear; t
= 0:0.01:1;
x1 = sin(2*pi*5*t); % Signal 1 x2
= cos(2*pi*5*t); % Signal 2
% Addition x_add
= x1 + x2; %
Multiplication
x_mult = x1 .*
x2; % Scaling
x_scaled = 2 * x1;
% Shifting
x_shifted = [zeros(1,10) x1(1:end-10)];
% Plotting
subplot(3,2,1); plot(t, x1); title('Signal 1');
1|Page
subplot(3,2,2); plot(t, x2); title('Signal 2');
subplot(3,2,3); plot(t, x_add); title('Addition');
subplot(3,2,4); plot(t, x_mult); title('Multiplication');
subplot(3,2,5); plot(t, x_scaled); title('Scaling');
subplot(3,2,6); plot(t, x_shifted); title('Shifting');
Result:
2|Page
EXPERIMENT NO.:02
Aim: To implement Fast Fourier Transform (FFT) and Inverse Fast Fourier Transform
(IFFT) in MATLAB.
Components Required: MATLAB software
Short Theory: FFT is an efficient algorithm to compute the Discrete Fourier
Transform (DFT). The IFFT is used to reconstruct the original signal from its frequency
components.
Procedure: 1. Define a signal in MATLAB.
2. Compute its FFT.
3. Compute IFFT to reconstruct the signal.
4. Display and analyze the results.
MATLAB Program:
clc; clear; t =
0:0.01:1; x =
sin(2*pi*5*t);
% Compute FFT
X = fft(x);
% Compute IFFT
x_reconstructed = ifft(X);
% Plotting
subplot(3,1,1); plot(t, x); title('Original Signal'); subplot(3,1,2);
plot(abs(X)); title('Magnitude of FFT');
subplot(3,1,3); plot(t, x_reconstructed); title('Reconstructed Signal using IFFT');
3|Page
Results:
4|Page
EXPERIMENT NO.: 03
Aim: To implement linear and circular convolution in MATLAB.
Components Required: MATLAB software
Short Theory: Convolution is a mathematical operation used in signal processing.
Linear convolution computes the response of a system to an input signal, while circular
convolution is used for periodic signals and in DFT computations.
Procedure: 1. Define two signals in MATLAB.
2. Compute linear convolution using conv().
3. Compute circular convolution using cconv().
4. Plot the results.
MATLAB Program:
clc; clear; x = [1
2 3 4]; h = [0 1
0.5 0.2];
% Linear Convolution y_linear
= conv(x, h);
% Circular Convolution N =
max(length(x), length(h));
y_circular = cconv(x, h, N);
% Plotting subplot(2,1,1); stem(y_linear); title('Linear
Convolution'); subplot(2,1,2); stem(y_circular); title('Circular
Convolution');
5|Page
Results:
6|Page
EXPERIMENT NO.: 04
Aim: To compute autocorrelation and crosscorrelation of signals using MATLAB.
Components Required: MATALAB Software
Short Theory: Autocorrelation measures how a signal correlates with itself at different
time shifts, providing insights into periodicity. Crosscorrelation measures the similarity
between two different signals over time shifts.
Procedure: 1. Define signals in MATLAB.
2. Compute autocorrelation using xcorr().
3. Compute crosscorrelation using xcorr().
4. Plot and analyze the results.
MATLAB Program:
clc; clear; x =
[1 2 3 4 5]; y =
[2 3 4 5 6];
% Autocorrelation rxx
= xcorr(x);
% Crosscorrelation rxy
= xcorr(x, y);
% Plotting subplot(2,1,1); stem(rxx);
title('Autocorrelation'); subplot(2,1,2); stem(rxy);
title('Crosscorrelation');
7|Page
Result:
8|Page
EXPERIMENT NO.: 05
Aim: To implement the PAN Tompkins algorithm for QRS complex detection in an
ECG signal using MATLAB.
Components Required: 1. MATLAB Software
2. ECG Signal Dataset
Short Theory: The PAN Tompkins algorithm is a widely used method for detecting
the QRS complex in ECG signals. It consists of several steps, including filtering,
differentiation, squaring, integration, and thresholding to identify R-peaks accurately.
Procedure: 1. Load the ECG signal into MATLAB.
2. Apply a bandpass filter to remove noise.
3. Compute the derivative of the signal to highlight rapid changes.
4. Square the signal to amplify peaks.
5. Apply a moving window integration to smooth the signal.
6. Use thresholding to detect QRS complexes.
7. Plot the results.
MATLAB Program:
clc; clear;
close all;
% Sampling parameters
fs = 360; % Sampling frequency
duration = 10; % ECG duration in seconds t
= 0:1/fs:duration-1/fs;
% Simulated ECG-like waveform (for demonstration) ecg
= 1.5*sin(2*pi*1.2*t) + 0.5*sawtooth(2*pi*1.7*t, 0.5); ecg
= ecg + 0.1*randn(size(t)); % Add slight noise
% Normalize the signal
9|Page
ecg = ecg - mean(ecg); ecg
= ecg / max(abs(ecg));
%% 1. Bandpass Filtering (5-15 Hz)
[b, a] = butter(1, [5 15]/(fs/2), 'bandpass'); ecg_filtered
= filtfilt(b, a, ecg);
%% 2. Derivative ecg_diff =
diff(ecg_filtered);
ecg_diff(end+1) = ecg_diff(end);
%% 3. Squaring ecg_squared
= ecg_diff.^2;
%% 4. Moving Window Integration window_size
= round(0.150 * fs); % 150 ms ecg_mwi =
movmean(ecg_squared, window_size);
%% 5. QRS Detection threshold
= 0.5 * max(ecg_mwi);
[qrs_peaks, qrs_locs] = findpeaks(ecg_mwi, 'MinPeakHeight', threshold,
'MinPeakDistance', round(0.2 * fs));
%% Plotting figure;
subplot(3,1,1); plot(t,
ecg);
title('Simulated ECG Signal'); xlabel('Time
(s)'); ylabel('Amplitude');
subplot(3,1,2);
plot(t, ecg_mwi); hold on; plot(qrs_locs/fs,
ecg_mwi(qrs_locs), 'ro'); title('Integrated
10 | P a g e
Signal with QRS Detections'); xlabel('Time
(s)'); ylabel('Amplitude');
subplot(3,1,3); plot(t, ecg); hold on;
plot(qrs_locs/fs, ecg(qrs_locs), 'r*');
title('Detected QRS Complexes on ECG');
xlabel('Time (s)'); ylabel('Amplitude');
Result:
11 | P a g e
EXPERIMENT NO.: 06
Aim: To implement and analyze the performance of IIR Butterworth filters (Low Pass,
High Pass, Band Pass, and Band Reject) in MATLAB.
Components Required: MATLAB Software
Short Theory: IIR (Infinite Impulse Response) filters, such as Butterworth filters, are
commonly used in signal processing for frequency-selective filtering. The Butterworth filter
provides a maximally flat frequency response in the passband, making it ideal for various
biomedical applications.
Procedure: 1. Design a Butterworth Low Pass Filter (LPF) with a cutoff frequency.
2. Design a Butterworth High Pass Filter (HPF) with a cutoff frequency.
3. Design a Butterworth Band Pass Filter (BPF) with specified lower and
upper cutoff frequencies.
4. Design a Butterworth Band Reject Filter (Notch filter) to remove a
specific frequency component.
5. Apply these filters to a sample signal.
6. Plot the magnitude and phase response of each filter.
7. Display the filtered signals.
MATLAB Program:
clc; clear;
close all;
fs = 1000; % Sampling frequency f_low
= 50; % Low cutoff frequency f_high =
200; % High cutoff frequency
% Generate sample signal (combination of multiple frequencies) t
= 0:1/fs:1; % 1-second duration
signal = sin(2*pi*30*t) + sin(2*pi*100*t) + sin(2*pi*300*t);
% Design Butterworth Filters
[b_lpf, a_lpf] = butter(4, f_low/(fs/2), 'low');
[b_hpf, a_hpf] = butter(4, f_high/(fs/2), 'high');
12 | P a g e
[b_bpf, a_bpf] = butter(4, [f_low f_high]/(fs/2), 'bandpass');
[b_notch, a_notch] = butter(4, [f_low-10 f_low+10]/(fs/2), 'stop');
% Apply Filters filtered_lpf = filtfilt(b_lpf, a_lpf,
signal); filtered_hpf = filtfilt(b_hpf, a_hpf,
signal); filtered_bpf = filtfilt(b_bpf, a_bpf,
signal); filtered_notch = filtfilt(b_notch, a_notch,
signal);
% Plot Results figure; subplot(5,1,1); plot(t, signal); title('Original Signal');
xlabel('Time (s)'); ylabel('Amplitude'); subplot(5,1,2); plot(t, filtered_lpf);
title('Low Pass Filtered Signal'); subplot(5,1,3); plot(t, filtered_hpf); title('High
Pass Filtered Signal'); subplot(5,1,4); plot(t, filtered_bpf); title('Band Pass
Filtered Signal'); subplot(5,1,5); plot(t, filtered_notch); title('Band Reject (Notch)
Filtered Signal');
Result:
13 | P a g e
EXPERIMENT NO.: 07
Aim: To implement different image segmentation techniques using MATLAB.
Components Required: 1. MATLAB Software
2. Sample Images
Short Theory: Image segmentation is the process of partitioning an image into
meaningful regions based on certain criteria such as intensity, color, or texture. Common
segmentation methods include:
1. Thresholding - Separates objects based on intensity values.
2. Edge-based Segmentation - Uses edge detection techniques like Sobel, Prewitt, or
Canny.
3. Region-based Segmentation - Uses techniques like Watershed and Region Growing.
4. Clustering-based Segmentation - Uses algorithms like K-Means clustering.
Procedure: 1. Load the image into MATLAB.
2. Convert the image to grayscale if necessary.
3. Apply different segmentation techniques:
• Global and adaptive thresholding.
• Edge detection using Sobel, Prewitt, and Canny filters.
• Region-based segmentation using Watershed and Region Growing.
• K-Means clustering-based segmentation.
4. Display the segmented images.
MATLAB Program:
clc;
clear;
close all;
% Load
14 | P a g e
image
img =
imread('c
[Link]'
); % You
can
replace
with any
grayscale
or RGB
image
% Convert to grayscale if
necessary if size(img, 3) == 3
gray_img = rgb2gray(img); else
gray_img = img; end
% Resize for better visualization (optional)
gray_img = imresize(gray_img, [256 256]);
%% 1. Thresholding level =
graythresh(gray_img); % Otsu's method
bw_thresh = imbinarize(gray_img, level);
%% 2. Edge Detection - Canny
edges = edge(gray_img, 'Canny');
%% 3. Watershed Segmentation
hy = fspecial('sobel'); hx = hy';
Iy = imfilter(double(gray_img), hy, 'replicate');
Ix = imfilter(double(gray_img), hx,
'replicate'); gradmag = sqrt(Ix.^2 + Iy.^2); L =
15 | P a g e
watershed(gradmag); watershed_seg =
label2rgb(L);
%% 4. K-means Clustering img_vec
= double(gray_img(:)); nClusters =
2;
[cluster_idx, ~] = kmeans(img_vec, nClusters, 'MaxIter', 100);
kmeans_seg = reshape(cluster_idx, size(gray_img));
kmeans_seg = mat2gray(kmeans_seg);
%% Display Results figure('Name', 'Image Segmentation
Methods', 'NumberTitle', 'off');
subplot(2,3,1); imshow(gray_img); title('Original Grayscale');
subplot(2,3,2); imshow(bw_thresh); title('Thresholding (Otsu)');
subplot(2,3,3); imshow(edges); title('Canny Edge Detection');
subplot(2,3,4); imshow(watershed_seg); title('Watershed Segmentation');
subplot(2,3,5); imshow(kmeans_seg); title('K-means Clustering');
Result:
16 | P a g e
EXPERIMENT NO.: 08
Aim: To implement medical image enhancement techniques using MATLAB.
Components Required: 1. MATLAB Software
2. Medical image dataset (e.g., X-ray, MRI, CT scan)
Short Theory: Image enhancement is used to improve the visual appearance of images
or to convert the image to a form better suited for analysis. In medical imaging, this helps in
highlighting important features like tissues, bones, or abnormalities. Common enhancement
techniques include:
1. Histogram Equalization
2. Contrast Adjustment
3. Noise Reduction (Filtering)
4. Sharpening
Procedure: 1. Load the medical image.
2. Convert the image to grayscale (if needed).
3. Apply different enhancement techniques:
• Histogram equalization
• Contrast stretching
• Gaussian filtering for noise reduction
• Image sharpening
4. Display and compare the original and enhanced images
MATLAB Program:
clc; clear;
close all;
% Load a built-in medical-like image img = imread('[Link]');
% Replace with your image if needed
% Convert to grayscale if needed
17 | P a g e
if size(img, 3) == 3
gray_img = rgb2gray(img);
else gray_img = img; end
% Resize gray_img = imresize(gray_img,
[256 256]);
% Enhancement steps eq_img =
histeq(gray_img); adjusted_img =
imadjust(gray_img); gauss_filtered =
imgaussfilt(gray_img, 2); sharpened_img
= imsharpen(gray_img);
% Display figure('Name','Medical Image
Enhancement','NumberTitle','off'); subplot(2,3,1);
imshow(gray_img); title('Original Grayscale Image'); subplot(2,3,2);
imshow(eq_img); title('Histogram Equalization'); subplot(2,3,3);
imshow(adjusted_img); title('Contrast Adjustment'); subplot(2,3,4);
imshow(gauss_filtered); title('Gaussian Filtered'); subplot(2,3,5);
imshow(sharpened_img); title('Sharpened Image'); subplot(2,3,6);
imhist(gray_img); title('Original Histogram');
18 | P a g e
Result:
19 | P a g e
EXPERIMENT NO.: 09
Aim: To analyze the spatial and intensity resolution of images using MATLAB. Components
Required: 1. MATLAB Software
2. Sample grayscale image
Short Theory: 1. Spatial Resolution refers to the number of pixels used to represent an
image. Higher spatial resolution means more pixels and finer details.
2. Intensity Resolution refers to the number of different gray levels (usually 8-bit = 256 levels)
available to represent image intensities. Analyzing both helps in understanding the quality and
information content of an image.
Procedure: 1. Load the original image.
2. Resize the image to lower resolutions to observe spatial resolution effects.
3. Quantize the image using different bit depths to simulate different intensity
resolutions.
4. Display and compare the results.
MATLAB Program:
clc; clear;
close all;
% Load original image img =
imread('[Link]');
% Spatial resolution analysis img_64
= imresize(img, [64 64]); img_32 =
imresize(img, [32 32]); img_16 =
imresize(img, [16 16]); % Intensity
resolution analysis img_8bit =
uint8(img); img_4bit =
uint8(floor(double(img)/16)*16);
20 | P a g e
img_2bit =
uint8(floor(double(img)/64)*64);
% Display spatial resolution figure; subplot(2,3,1); imshow(img);
title('Original Image'); subplot(2,3,2); imshow(imresize(img_64, size(img)));
title('64x64 Resolution'); subplot(2,3,3); imshow(imresize(img_32, size(img)));
title('32x32 Resolution'); subplot(2,3,4); imshow(imresize(img_16, size(img)));
title('16x16 Resolution');
% Display intensity resolution subplot(2,3,5);
imshow(img_4bit); title('4-bit Intensity'); subplot(2,3,6);
imshow(img_2bit); title('2-bit Intensity');
Result:
21 | P a g e
EXPERIMENT NO.: 10
Aim: To understand and implement image sampling and quan za on using MATLAB. Components
Required: 1. MATLAB Software
2. Sample grayscale image
Short Theory: 1. Sampling refers to reducing the number of pixels in an image, i.e.,
lowering spatial resolution.
2. Quantization refers to reducing the number of possible intensity levels of pixels, i.e.,
lowering intensity resolution. Both are crucial in image compression and representation in
digital systems.
Procedure: 1. Load the grayscale image.
2. Perform downsampling at various levels.
3. Quantize the image using different bit depths.
4. Display and analyze the visual effects.
MATLAB Program:
clc; clear;
close all;
% Load image img =
imread('[Link]');
% Ensure grayscale if
size(img, 3) == 3 img
= rgb2gray(img); end
% Sampling - Downsample image
img_ds2 = img(1:2:end, 1:2:end); img_ds4
= img(1:4:end, 1:4:end); img_ds8 =
img(1:8:end, 1:8:end);
22 | P a g e
% Resize for visualization img_ds2 =
imresize(img_ds2, size(img)); img_ds4 =
imresize(img_ds4, size(img)); img_ds8 =
imresize(img_ds8, size(img));
% Quantization img_4bit =
uint8(floor(double(img)/16)*16); img_2bit =
uint8(floor(double(img)/64)*64);
% Display Results figure('Name','Sampling and
Quantization','NumberTitle','off'); subplot(2,3,1);
imshow(img); title('Original Image'); subplot(2,3,2);
imshow(img_ds2); title('Sampling by 2'); subplot(2,3,3);
imshow(img_ds4); title('Sampling by 4'); subplot(2,3,4);
imshow(img_ds8); title('Sampling by 8'); subplot(2,3,5);
imshow(img_4bit); title('4-bit Quantization'); subplot(2,3,6);
imshow(img_2bit); title('2-bit Quantization');
23 | P a g e
Result:
24 | P a g e