DSP Music Genre Classifier
Handcrafted DSP features plus a mel-spectrogram CNN for real-time genre detection.
A hybrid system in MATLAB that combines classical models (KNN, SVM, boosted trees) on DSP features with a CNN on mel-spectrograms, trading off the accuracy of deep learning against the low latency of classical classifiers.
README · rendered from GitHub
DSP-Based Music Genre Classifier
Abstract
This project presents a real-time DSP-based music genre classification system that combines handcrafted feature extraction with deep learning techniques. The system integrates classical machine learning models—K-Nearest Neighbors (KNN), Support Vector Machines (SVM), and Boosted Trees—with a lightweight Convolutional Neural Network (CNN) trained on mel-spectrograms. The hybrid model achieves high accuracy and low latency suitable for real-time applications such as music streaming platforms, DJ software, and media organization tools.
Problem Statement
Classical approaches used features like MFCCs and models such as k-NN or SVM to achieve ~70% accuracy. With the rise of deep learning, CNNs operating on spectrogram images boosted performance beyond 85%. However, real-time constraints limit deep model usage on low-resource platforms. This work proposes a hybrid DSP + CNN solution to achieve both speed and performance. So the goal is to design a music genre classification system that balances:
- High accuracy using deep learning
- Low latency using classical models
- Real-time feasibility for live applications
System Overview
DSP Features Extracted
- Mel-Frequency Cepstral Coefficients (MFCCs) – captures timbral textures
- Spectral Descriptors – centroid, rolloff, flux, ZCR
- Rhythmic Features – beat strength, BPM, tempo variance
- Harmonic Features – pitch histograms, chroma vectors
CNN on Mel-Spectrograms
-
Preprocessing:
- Frame audio with 2048-sample windows, 50% overlap
- Apply FFT, Mel filterbanks, and log compression
- Generate 64×128 mel-spectrogram image for 3s audio clips
-
CNN Architecture:
- Two Conv layers (64 filters, 3×3 and 3×5)
- Max-pooling (2×4)
- One dense layer (32 units) + Softmax
- Dropout: 0.3, Optimizer: Adam (lr = 0.001)
Performance Comparison
| Model | Accuracy | Precision | Recall |
|---|---|---|---|
| k-NN | 60.5% | 0.61 | 0.60 |
| SVM | 68.7% | 0.70 | 0.69 |
| Boosted Trees | 75.4% | 0.76 | 0.75 |
| CNN | 83.0% | 0.84 | 0.83 |
| Hybrid Model | 85.0% | 0.86 | 0.85 |
The hybrid model provides the best overall performance with low latency and high generalization.
Folder Structure
How to Run
Requirements
- MATLAB R2020 or newer
- Signal Processing Toolbox
- Deep Learning Toolbox.
Steps
- Clone the repository:
git clone https://github.com/Awais-Asghar/DSP-Based-Music-Genre-Classifier
- Open MATLAB and add all folders to path:
addpath(genpath('DSP-Based-Music-Genre-Classifier'))
- Run any model:
run('code/KNN.m')
run('code/SVM.m')
run('code/Boosted_Trees.m')
run('CNN/cnn.m')
Dataset
- Based on Free Music Archive (FMA) dataset
- Genres used: Folk, Hip-Hop, Instrumental, International
- Audio clips are processed into 3-second segments for classification
Visual Results
Top influential features include:
- MFCC₂
- Spectral Flux
- Spectral Kurtosis
- Harmonic Ratio
- MFCC₃
These features play a critical role in effectively distinguishing between music genres.
Future Work
- Extend to sub-genres and multilingual music
- Add LSTM/GRU layers for temporal modeling
- Optimize CNN using quantization/pruning for embedded systems
Authors
- Awais Asghar
- Muhammad Ashar Javid
- Muhammad Hammad Sarwar
- Huzaifa Ahmad
Department of Electrical Engineering,
National University of Sciences and Technology (NUST), Islamabad, Pakistan
More in AI / ML
Related projects
Private repoAI / MLSummer 2026Trans-Neptunian Object Detection
A spatiotemporal U-Net that finds faint moving objects in telescope image sequences.
- PyTorch
- Python
- HDF5
- CANFAR
AI / ML2023SkinSense: Skin Cancer Classifier
An ensemble of five models labels a lesion as benign or malignant from one RGB image.
- Python
- Scikit-learn
- XGBoost
- LightGBM
AI / ML2025RecycleVision
EfficientNetB0 transfer learning sorts waste into six recyclable categories.
- Python
- TensorFlow
- Keras
- EfficientNetB0