Skip to content

About

Official repository for the Spectral Analysis of Lung Sounds for Asthma & Pneumonia Classification with code, results, and paper

Topics

Resources

Stars

3 stars

Watchers

0 watching

Forks

Latest commit

ย 

History

44 Commits

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Spectral Analysis of Lung Sounds for Asthma & Pneumonia Classification


Figure 1. Proposed Methodology (extracted from IEEE paper)

๐Ÿ“– Overview

This repository accompanies the IEEE conference paper:

โ€œSpectral Analysis of Lungs sounds for Classification of Asthma and Pneumonia Wheezingโ€ (ICECCE 2025, Istanbul, Turkey).

Lung sounds provide critical diagnostic information. Wheezing is a key indicator of pulmonary illnesses such as Asthma and Pneumonia. This project presents a complete ML pipeline โ€” from preprocessing raw lung sounds, to spectral feature extraction, and classification via Support Vector Machine (SVM) with an accuracy of 96.7%.

Python Code Implementation Video:

Part 1

Part 1

Part 2

Part 2

Part 3

Part 3


IEEE Paper Explained

IEEE Paper Explained


ICECCE Paper Presentaion Video

IEEE Paper Explained

๐Ÿ“‚ Repository Contents

  • paper/ โ†’ Full IEEE paper (PDF)
  • notebooks/ โ†’ Jupyter/Kaggle notebooks for preprocessing, feature extraction & classification
  • gui_app/ โ†’ Ready-to-deploy GUI (lungsound_gui.py)
  • data/ โ†’ Example lung sound samples (optional small demo files)
  • results/figures/ โ†’ Extracted figures and generated plots

โš™๏ธ Environment Setup

We recommend using Anaconda.

# Create environment
conda env create -f environment.yml
conda activate lungsound-env

Key libraries: numpy, scipy, librosa, matplotlib, scikit-learn, tkinter.

๐Ÿ› ๏ธ How to Run


1) Preprocessing

Open notebooks/preprocessing.ipynb in Jupyter/Kaggle. It demonstrates:

  • Normalization (Minโ€“Max scaling)
  • Segmentation (250 ms frames)
  • Butterworth bandpass filtering (250 Hz โ€“ 2 kHz)

๐Ÿ“Œ Overview

This notebook focuses on preprocessing lung sound recordings for respiratory disease classification.
The workflow consists of three key stages:

  1. Normalization โ€“ removing amplitude variations.
  2. Segmentation โ€“ dividing signals into frames.
  3. Filtration โ€“ applying band-pass filtering to isolate useful frequency bands.

The processed signals are later used for feature extraction and classification of respiratory conditions such as Normal, Asthma, and Pneumonia.

๐ŸŽš Step 1: Band-pass Filtering

To remove unwanted low- and high-frequency components, a 10th-order Butterworth band-pass filter was applied.
This retains only frequencies between 150 Hz โ€“ 2000 Hz, where most lung sound information lies.

Band-pass filter response

๐Ÿ“ Step 2: Dimension & Framing Report

Input signals were preprocessed and segmented into overlapping frames:

  • Sampling rate: 44.1 kHz
  • Frame length: 0.25s (11025 samples)
  • Hop size: 0.125s (5512 samples, 50% overlap)

Frames with silence were removed, leaving ~80% of useful frames.

Dimension report

๐Ÿซ Step 3: Preprocessed Lung Sounds (Overlay)

Signals for different classes (Normal, Asthma, Pneumonia) after preprocessing, plotted in the time domain.

Preprocessed time domain overlay

Similarly, in the frequency domain we observe different spectral patterns among the classes.

Preprocessed frequency domain overlay

๐Ÿ“Š Step 4: Class-wise Visualization

Time Domain (per class)

  • Normal: Clear periodic bursts.
  • Asthma: Weak, noisy signal with irregular patterns.
  • Pneumonia: Distorted and suppressed signal structure.

Time domain per class

Frequency Domain (per class)

Each respiratory condition shows a distinct spectral signature:

  • Normal: Strong low-frequency energy.
  • Asthma: Broader spread with weaker energy.
  • Pneumonia: Different high-frequency attenuation.

Frequency domain per class

โœ… Summary

The preprocessing pipeline ensures that lung sound signals are:

  • Normalized to remove amplitude variations.
  • Segmented into meaningful frames.
  • Filtered to retain medically relevant frequency ranges.

This structured approach lays the foundation for robust feature extraction and classification in later stages.


2) Feature Extraction

We extract nine spectral features: Spectral Centroid, Spectral Crest, Spectral Decrease, Spectral Entropy, Spectral Flatness, Spectral Flux, Spectral Rollโ€‘off, Spectral Slope, Spectral Spread.

๐Ÿ“Œ Overview

This notebook extends the preprocessing pipeline by extracting meaningful features from lung sound recordings.
Feature extraction bridges the gap between raw signals and machine learning models, enabling accurate classification of respiratory conditions (Normal, Asthma, Pneumonia).

The workflow covers:

  1. Time-domain features
  2. Frequency-domain features
  3. Spectral descriptors

โš™๏ธ Processing Status

The dataset was processed class-wise, with 100% completion for all categories.

Processing Status


๐Ÿ“‘ Extracted Features

Each audio frame was characterized using spectral descriptors, including:

  • SCN: Spectral Centroid
  • SCR: Spectral Crest
  • SDC: Spectral Decrease
  • SEN: Spectral Entropy
  • SFL: Spectral Flatness
  • SFLUX: Spectral Flux
  • SRO: Spectral Roll-off
  • SSL: Spectral Slope
  • SSP: Spectral Spread

Example snapshot of extracted features:

Feature Table

๐Ÿ“Š Feature Visualization

SCN vs SCR

Demonstrates how Spectral Centroid relates to Spectral Crest, differentiating lung conditions.

SCN vs SCR

SCN vs SEN

Shows correlation between Spectral Centroid and Spectral Entropy, highlighting Asthmaโ€™s distinct pattern.

SCN vs SEN

SCN vs SFLUX

Visualizes spectral fluctuations and their distribution across conditions.

SCN vs SFLUX

๐Ÿ”— Feature Correlations

Understanding inter-feature dependencies is crucial for model selection and dimensionality reduction.

  • Overall correlation (all classes):
    Strong correlations between SCN, SDC, SEN, and SRO.

Correlation Heatmap All Classes

  • Class-wise correlations:

Normal
Normal Heatmap

Asthma
Asthma Heatmap

Pneumonia
Pneumonia Heatmap

โœ… Summary

  • Extracted time-domain, frequency-domain, and spectral features.
  • Demonstrated feature separability across conditions via scatter plots.
  • Analyzed feature correlations to guide further dimensionality reduction and classification.

This feature set forms the foundation for Notebook 3: Feature Selection & Classification.


3) Classification

๐Ÿ“Œ Overview

This notebook demonstrates the classification of respiratory conditions (Normal, Asthma, Pneumonia) using spectral features extracted in Notebook 2.
Multiple machine learning algorithms are applied, and their performance is evaluated using confusion matrices, accuracy, precision, recall, F1-score, and statistical significance testing.

๐Ÿ“Š Dataset Split

The dataset was divided into training and testing sets:

  • Training samples: 14,879
  • Testing samples: 6,378

Train-Test Split

๐Ÿง  Classifiers Evaluated

The following models were tested:

  1. LD โ€“ Linear Discriminant
  2. KNB โ€“ Kernel Naรฏve Bayes
  3. FT โ€“ Fine Tree
  4. GNB โ€“ Gaussian Naรฏve Bayes
  5. FKNN โ€“ Fine K-Nearest Neighbors
  6. BT โ€“ Bagged Trees
  7. SKNN โ€“ Subspace K-Nearest Neighbors

๐Ÿ“‰ Confusion Matrices

Confusion matrices illustrate the classification performance of each model.

  • LD
    LD Confusion Matrix

  • KNB
    KNB Confusion Matrix

  • FT
    FT Confusion Matrix

  • GNB
    GNB Confusion Matrix

  • FKNN
    FKNN Confusion Matrix

  • BT
    BT Confusion Matrix

  • SKNN
    SKNN Confusion Matrix

๐Ÿ“‘ Performance Metrics

Performance of each classifier was evaluated with Accuracy, Precision, Recall, and F1-score.

Performance Table

Accuracy Comparison

Accuracy Comparison

F1-Score Comparison

F1-Score Comparison

๐Ÿ“Š Statistical Significance Testing

To ensure differences in classifier performance are not due to chance, McNemarโ€™s Test was applied.

๐Ÿ”Ž McNemarโ€™s Test vs SVM

All models showed statistically significant differences compared to SVM at 95% confidence.

McNemar vs SVM

๐Ÿ”Ž McNemarโ€™s Test vs FT (Fine Tree)

Fine Tree was compared against all other models, and the results confirm its superiority with statistically significant differences.

McNemar vs FT


โœ… Summary & Insights

  • Best Performing Models:
    • Bagged Trees (BT) and Fine Tree (FT) achieved the highest accuracy (~98%) and F1-scores (~0.97โ€“0.98).
  • Moderate Performance:
    • FKNN and SKNN scored ~85% accuracy and F1 ~0.82.
  • Weaker Performance:
    • LD, KNB, GNB underperformed (<65% accuracy, low F1).
  • Statistical Testing:
    • Confirmed FT and BT significantly outperform other models.

๐Ÿ“Œ Conclusion:
Tree-based ensemble methods (BT, FT) provide the most reliable classification of lung sounds, with results statistically validated using McNemarโ€™s Test.


4) GUI Application ๐ŸŽ›๏ธ

Run the GUI app to classify any .wav lung sound file:

conda activate lungapp
streamlit run gui_app/spectral-lungsound-gui.py

Features:

  • Load lung sound file

  • View preprocessing plots and timing

  • Extract and visualize features

  • Run trained models

  • Display final classification (Asthma / Pneumonia / Normal) with metrics

    1 1 1 1 1 1 1

๐Ÿ“œ Reference

@inproceedings{naqvi2020spectral, title={Spectral analysis of lungs sounds for classification of asthma and pneumonia wheezing}, author={Naqvi, Syed Zohaib Hassan and Arooj, Misha and Aziz, Sumair and Khan, Muhammad Umar and Choudhary, Mohammad Ahmad and others}, booktitle={2020 International Conference on Electrical, Communication, and Computer Engineering (ICECCE)}, pages={1--6}, year={2020}, organization={IEEE} }


This repository is designed as an educational resource for students and researchers in Biomedical Engineering & Signal Processing.

About

Official repository for the Spectral Analysis of Lung Sounds for Asthma & Pneumonia Classification with code, results, and paper

Topics

Resources

Stars

3 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages