필터 지우기
필터 지우기

Feature Extraction in Time-Frequency Domain - Audio Classification

조회 수: 3 (최근 30일)
Ren Xiang Lee
Ren Xiang Lee 2021년 6월 1일
답변: Yash Sharma 2024년 5월 2일
Hi, I'm fairly new to MATLAB, really appreciate if I can get some help here.
I'm doing a project on audio classification, where I have loaded labelled audio datasets into MATLAB. I am currently encountering an issue where I want to apply discrete wavelet transform on all the signals in the datasets and convert them to images, subsequently saving them in a folder according to their labels. The images will then be fed into a neural network for classification learning.
I am trying to replicate another projet where they created a function to automatically convert CWT coefficients into images but I'm having no luck trying to make it work for DWT.
Thanks in advance for helping, and if I'm missing out any details please let me know.
my code:
The function code for CWT

답변 (1개)

Yash Sharma
Yash Sharma 2024년 5월 2일
To convert audio signals to Discrete Wavelet Transform (DWT) images and save them according to their labels, you can modify the function you provided for CWT. Below is a concise guide and a modified function tailored for DWT.
Modified Function for DWT
This function, helperCreateImagesFromDWT, processes audio files, applies DWT, and saves the coefficients as images in labeled folders.
function helperCreateImagesFromDWT(ads, outputFolder)
for i = 1:length(ads.Files)
[audioIn, info] = audioread(ads.Files{i}); % Read audio file
[cA, cD] = dwt(audioIn, 'db1'); % Apply DWT with 'db1' wavelet
% Process and normalize coefficients
coeffs = [cA; cD];
coeffsNorm = (coeffs - min(coeffs)) / (max(coeffs) - min(coeffs));
img = im2uint8(mat2gray(coeffsNorm)); % Convert to image
% Prepare image file path
label = char(ads.Labels(i));
imgFileName = strcat(label, '_', num2str(i), '.png');
imgFolderPath = fullfile(outputFolder, label);
if ~exist(imgFolderPath, 'dir'), mkdir(imgFolderPath); end % Ensure folder exists
imwrite(imresize(img, [224, 224]), fullfile(imgFolderPath, imgFileName)); % Save image
end
end
Applying the Function
  1. Set Up the Output Folder: Change datafolder_scallogram to a new folder name that reflects you're working with DWT images, for example, datafolder_dwtImages.
  2. Call the Function: Replace the call to helperCreateRGBfromTF in your script with helperCreateImagesFromDWT, passing the audio datastore and the new output folder path.
datafolder_dwtImages = "C:\Users\leere\Documents\MATLAB\DWT_Images"; % New folder for DWT images
helperCreateImagesFromDWT(ads, datafolder_dwtImages); % Process and save DWT images
This approach applies DWT to your audio signals, normalizes and processes the coefficients to create images, and organizes these images in folders based on their labels, ready for neural network classification.

카테고리

Help CenterFile Exchange에서 AI for Signals and Images에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by