
Figure 1. Proposed Methodology (extracted from IEEE paper)
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%.
paper/โ Full IEEE paper (PDF)notebooks/โ Jupyter/Kaggle notebooks for preprocessing, feature extraction & classificationgui_app/โ Ready-to-deploy GUI (lungsound_gui.py)data/โ Example lung sound samples (optional small demo files)results/figures/โ Extracted figures and generated plots
We recommend using Anaconda.
# Create environment
conda env create -f environment.yml
conda activate lungsound-envKey libraries: numpy, scipy, librosa, matplotlib, scikit-learn, tkinter.
Open notebooks/preprocessing.ipynb in Jupyter/Kaggle. It demonstrates:
- Normalization (MinโMax scaling)
- Segmentation (250 ms frames)
- Butterworth bandpass filtering (250 Hz โ 2 kHz)
This notebook focuses on preprocessing lung sound recordings for respiratory disease classification.
The workflow consists of three key stages:
- Normalization โ removing amplitude variations.
- Segmentation โ dividing signals into frames.
- 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.
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.
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.
Signals for different classes (Normal, Asthma, Pneumonia) after preprocessing, plotted in the time domain.
Similarly, in the frequency domain we observe different spectral patterns among the classes.
- Normal: Clear periodic bursts.
- Asthma: Weak, noisy signal with irregular patterns.
- Pneumonia: Distorted and suppressed signal structure.
Each respiratory condition shows a distinct spectral signature:
- Normal: Strong low-frequency energy.
- Asthma: Broader spread with weaker energy.
- Pneumonia: Different high-frequency attenuation.
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.
We extract nine spectral features: Spectral Centroid, Spectral Crest, Spectral Decrease, Spectral Entropy, Spectral Flatness, Spectral Flux, Spectral Rollโoff, Spectral Slope, Spectral Spread.
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:
- Time-domain features
- Frequency-domain features
- Spectral descriptors
The dataset was processed class-wise, with 100% completion for all categories.
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:
Demonstrates how Spectral Centroid relates to Spectral Crest, differentiating lung conditions.
Shows correlation between Spectral Centroid and Spectral Entropy, highlighting Asthmaโs distinct pattern.
Visualizes spectral fluctuations and their distribution across conditions.
Understanding inter-feature dependencies is crucial for model selection and dimensionality reduction.
- Overall correlation (all classes):
Strong correlations between SCN, SDC, SEN, and SRO.
- Class-wise correlations:
- 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.
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.
The dataset was divided into training and testing sets:
- Training samples: 14,879
- Testing samples: 6,378
The following models were tested:
- LD โ Linear Discriminant
- KNB โ Kernel Naรฏve Bayes
- FT โ Fine Tree
- GNB โ Gaussian Naรฏve Bayes
- FKNN โ Fine K-Nearest Neighbors
- BT โ Bagged Trees
- SKNN โ Subspace K-Nearest Neighbors
Confusion matrices illustrate the classification performance of each model.
Performance of each classifier was evaluated with Accuracy, Precision, Recall, and F1-score.
To ensure differences in classifier performance are not due to chance, McNemarโs Test was applied.
All models showed statistically significant differences compared to SVM at 95% confidence.
Fine Tree was compared against all other models, and the results confirm its superiority with statistically significant differences.
- 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.
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
@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.







































