Skip to content
Awais Asghar.
AI & Machine Learning2025

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.

DSP Music Genre Classifier thumbnail

README · rendered from GitHub

DSP-Based Music Genre Classifier

Status Tech Stack Platform Language License

Image

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

Image

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
Image

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

ModelAccuracyPrecisionRecall
k-NN60.5%0.610.60
SVM68.7%0.700.69
Boosted Trees75.4%0.760.75
CNN83.0%0.840.83
Hybrid Model85.0%0.860.85

The hybrid model provides the best overall performance with low latency and high generalization.

Folder Structure

Image

How to Run

Requirements

  • MATLAB R2020 or newer
  • Signal Processing Toolbox
  • Deep Learning Toolbox.

Steps

  1. Clone the repository:
git clone https://github.com/Awais-Asghar/DSP-Based-Music-Genre-Classifier
  1. Open MATLAB and add all folders to path:
addpath(genpath('DSP-Based-Music-Genre-Classifier'))
  1. 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. Image

Image Image Image

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
Image

More in AI / ML

Related projects

See all
  • AI / ML2025

    RecycleVision

    EfficientNetB0 transfer learning sorts waste into six recyclable categories.

    • Python
    • TensorFlow
    • Keras
    • EfficientNetB0