0% found this document useful (0 votes)
6 views12 pages

Group Activity Report

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)
6 views12 pages

Group Activity Report

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/ 12

Differential and Difference Equations

(MAT2001)
Winter Semester 2024-2025

Multimodal Signal Processing and Compression using Python


Slot: B11+B12

Submitted by:
• Lakshya Sahu (23BAI10250)
• Pratham Kashyap (23BAI10455)
• Garv Anand (23BAI10605)
• Priyanshu Ranjan (23BAI10691)
• Shrish (23BAI11284)

Submitted to:
Dr. Sheerin Kayenat
Table of Content
S.no Topics
1. Introduction
• Objective
• Overview of Signal Processing and Image Compression
• Scope and Mathematical Applications
2. Libraries Used
• NumPy • Sounddevice
• Matplotlib • PIL
• SciPy • Scikit-learn
• Soundfile
3. Test Data
• Description of Audio Signals (Noisy, Impulse, Step)
• Description of Image Pattern

4. Data Preparation
• Generating Test Signals
• Creating the Test Image Pattern
5. Audio Filtering Module
• Filter Design (Lowpass, Highpass, Bandpass)
• Applying Digital Filters

6. Image Compression Module


• PCA-based Compression
• Compression Ratio Calculation

7. Visualization
• Time and Frequency Domain Plots
• Original vs Compressed Image

8. Code Implementation
• Signal Generation Scripts
• Filtering and Compression Scripts
9. Results
• Filtered Audio Outputs
• Compressed Image and Ratio
10. Conclusion
• Summary of Observations
• Potential Improvements and Future Scope
Project Report: Multimodal Signal Processing and
Compression Using Python

Introduction

The objective of this project is to explore signal processing techniques on both


audio and image data using Python. The focus lies on generating and analyzing
synthetic audio signals (such as noisy, impulse, and step signals) and compressing
images using PCA. The work demonstrates how classical signal processing and
dimensionality reduction methods can be effectively applied in digital filters and
image compression tasks.

Scope and Mathematical Applications


This project applies three key mathematical areas across distinct modules:

• Fourier Transform (Audio Analysis): Used to convert audio signals from


time domain to frequency domain, enabling spectral analysis, noise
reduction, and signal reconstruction.
• Z-Transform (Digital Filters): Forms the mathematical basis for designing
and analyzing digital filters, allowing implementation of low-pass, high-
pass, and band-pass filtering.
• Eigenvalues & Eigenvectors (Image Compression): Core to PCA, they are
used to reduce image dimensionality by identifying the most significant
patterns in pixel variation.
Libraries Used
The following libraries were used in this project:

Ø NumPy: Fundamental for numerical computations, especially with arrays


and signal generation.
Ø Matplotlib: Used for visualizing time and frequency domain signals as well
as compressed image outputs.
Ø SciPy: Applied for digital filtering (Butterworth filters) and frequency
analysis via FFT.
Ø SoundFile & SoundDevice: For reading/writing and playback of audio
signals.
Ø Pillow (PIL): Used for image creation and manipulation, especially for
creating test patterns.
Ø Scikit-learn: Specifically the PCA module, employed for dimensionality
reduction in image compression.

Test Data Generation


This project does not use third-party datasets. Instead, synthetic data was
generated for controlled evaluation of audio filters and image compression:

Ø Audio Signals:

Þ Noisy Signal: Mix of sine waves at various frequencies with added


white noise.
Þ Impulse Signal: Single pulse to test filter impulse responses.
Þ Step Signal: Sudden amplitude shift used to assess filter step
response behavior.

Ø Image Pattern:

Þ A synthetic grayscale pattern (512x512) with vertical, horizontal, and


diagonal stripes was created to evaluate PCA-based compression
efficiency.
Preprocessing
Before applying models and algorithms, basic preprocessing steps were carried
out to ensure the test signals and images were analysis-ready:

Ø Audio Normalization: All audio signals were normalized to standardize


amplitude ranges for accurate visualization and filtering.

Ø Noise Simulation: Controlled noise was introduced to test the noise-


handling capability of digital filters.

Ø Grayscale Conversion: The test image was converted to grayscale to reduce


complexity for PCA-based compression.

Ø Data Storage: Processed signals and images were stored in standard


formats (.wav, .png) to ensure reusability and modular processing.

Audio Filtering and Image Compression Module


The project implements two key modules: Audio Filtering and Image
Compression using Python.

Ø The Audio Filtering Module processes signals like impulse, step, and noisy
waveforms using digital filters (low-pass, high-pass, band-pass) designed
with SciPy. The filtered results are visualized in both time and frequency
domains, showcasing noise reduction and signal clarity.
Ø The Image Compression Module uses PCA (Principal Component Analysis)
to reduce the dimensionality of image data. Each color channel is
compressed independently, retaining essential features while minimizing
file size.
Ø The Compression Ratio is computed by dividing the original image size by
the compressed size, highlighting the efficiency of the method.
Visualization

Image Compression - Pixel Intensity Visualization


This plot compares the original and compressed pixel intensities to evaluate the
performance of the image compression model.

In the plot:

Ø 🔵 Blue Dots: Show the actual compressed pixel values against original
ones.
Ø 🔴 Red Line: Represents perfect reconstruction (ideal 1:1 mapping).
Ø The closer the dots are to the red line, the more accurate the compression.

This visualization helps assess how well the model captures the trend and
highlights the overall correlation between variables.
Digital Filters - Frequency and Time Domain Visualization

The plots demonstrate the effect of a low-pass filter on an audio signal in both
time and frequency domains.

Top Plot (Time Domain):

Ø 🔵 Original: Unfiltered noisy waveform.


Ø 🔴 Filtered: Smoothened output after applying the low-pass filter.

Bottom Plot (Frequency Domain):

Ø 🔵 Original Spectrum: Contains multiple high-frequency components.


Ø 🔴 Filtered Spectrum: Shows suppression of high-frequency noise after
filtering.
Time and Frequency Domain Analysis of a Chirp Signal

This graph represents the analysis of a chirp signal, which is a signal in which the
frequency increases with time.

Top Plot: Time Domain

Ø Shows how the signal varies over 2 seconds.


Ø Initially, the waveform oscillates slowly, then gets denser as frequency
increases.
Ø This indicates the chirp sweeping from a low to a high frequency.
Ø The amplitude remains constant (~±1).

Bottom Plot: Frequency Domain (FFT)

Ø Shows the frequency content after applying FFT (Fast Fourier Transform).
Ø Frequencies are spread across a wide band (up to ~8000 Hz), confirming a
wide frequency sweep.
Ø Magnitude is relatively constant across that band (~800), showing equal
energy distribution.

This dual-view (time and frequency) confirms that the chirp signal was generated
and analyzed correctly.
Code Implementation
The project includes two main code components: signal generation and
processing scripts.

The Signal Generation Scripts create synthetic audio signals such as impulse, step,
and chirp signals using NumPy and SciPy. These signals are saved as WAV files and
visualized in both time and frequency domains.

The Filtering and Compression Scripts apply digital filters (lowpass, highpass,
bandpass) to these signals using Butterworth filter design from SciPy. For images,
PCA-based compression is implemented by reducing dimensionality and
reconstructing images using selected principal components, along with
compression ratio calculation to evaluate efficiency.

Here are concise Python code snippets for both Signal Generation and
Filtering/Compression modules:

Signal Generation Scripts


import numpy as np
from scipy.signal import chirp
import soundfile as sf
import matplotlib.pyplot as plt

t = np.linspace(0, 2, 44100 * 2)
signal = chirp(t, f0=20, f1=20000, t1=2, method='linear')
sf.write("chirp_signal.wav", signal, 44100)

plt.subplot(2, 1, 1)
plt.plot(t, signal, color='blue')
plt.title("Chirp Signal - Time Domain")
plt.xlabel("Time [s]"); plt.ylabel("Amplitude")

plt.subplot(2, 1, 2)
fft = np.abs(np.fft.rfft(signal))
freq = np.fft.rfftfreq(len(t), 1/44100)
plt.plot(freq, fft, color='red')
plt.title("Chirp Signal - Frequency Domain (FFT)")
plt.xlabel("Frequency [Hz]"); plt.ylabel("Magnitude")

plt.tight_layout()
plt.show()
Filtering Script (DigitalFilter Class Sample)
from scipy.signal import butter, lfilter

class DigitalFilter:
def __init__(self, filter_type, cutoff, fs, order=5):
self.b, self.a = butter(order, np.array(cutoff) / (0.5 *
fs), btype=filter_type)

def apply_filter(self, signal):


return lfilter(self.b, self.a, signal)

PCA-based Image Compression Script


from sklearn.decomposition import PCA
import numpy as np
from PIL import Image

def compress_image(image_path, n_components):


img = Image.open(image_path).convert('L')
data = np.asarray(img) / 255.0
pca = PCA(n_components=n_components)
transformed = pca.fit_transform(data)
reconstructed = pca.inverse_transform(transformed)
return (reconstructed * 255).astype(np.uint8), pca

compressed_img, pca_model = compress_image("test_pattern.png",


n_components=50)
Image.fromarray(compressed_img).save("compressed.png")

Compression Ratio Calculation


def compression_ratio(original_shape, n_components):
original_size = np.prod(original_shape)
compressed_size = n_components * (original_shape[0] + 1)
return original_size / compressed_size

The image compression script uses PCA (Principal Component Analysis) to


reduce image dimensionality. It reads a grayscale image, applies PCA to retain key
components, and reconstructs the image with fewer features—effectively
reducing data size while preserving structure.
Results

The project successfully implemented audio signal filtering and image


compression techniques using Python. Audio filtering improved signal quality by
effectively removing noise and preserving essential frequency components.
Visualizations confirmed cleaner outputs for step, impulse, and noisy signals. In
image compression, PCA significantly reduced image size while retaining essential
visual structure. Compression ratios demonstrated substantial data reduction
with minimal visual degradation, validating PCA's effectiveness.

Conclusion
This project explored foundational techniques in signal processing and data
compression using Python. Audio filtering using digital filters improved signal
clarity, while PCA-based image compression achieved meaningful data reduction.
Python libraries such as NumPy, SciPy, Matplotlib, and scikit-learn enabled
efficient development and visualization.

Future work could include real-time signal filtering, color image compression, or
using neural networks for more adaptive and intelligent compression and
enhancement systems across multiple modalities.
Contributions

• Lakshya Sahu (23BAI10250)


Compiled the final project report and conducted theoretical research.
Focused on organizing results and ensuring that the overall presentation
clearly reflected the technical achievements of the team.

• Pratham Kashyap (23BAI10455)


Responsible for the image compression module, implementing PCA and
calculating compression ratios. Critical contribution in showcasing data
reduction while preserving essential visual features.

• Garv Anand (23BAI10605)


Led the entire code implementation, overseeing the integration of signal
processing and compression modules. Ensuring the accuracy, functionality,
and coherence of the project’s core components.

• Priyanshu Ranjan (23BAI10691)


Supported the technical build by managing visualizations and assisting in
code debugging. Helped maintain quality and ensured effective
demonstration of the project results.

• Shrish (23BAI11284)
Handled data cleaning and preparation, enabling smoother model
performance. Ensuring all modules received well-structured and clean
input for accurate processing.

You might also like