- 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.
- Call the Function: Replace the call to helperCreateRGBfromTF in your script with helperCreateImagesFromDWT, passing the audio datastore and the new output folder path.
Feature Extraction in Time-Frequency Domain - Audio Classification
4 views (last 30 days)
Show older comments
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
0 Comments
Answers (1)
Hornett
on 18 Sep 2024
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
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.
0 Comments
See Also
Categories
Find more on Wavelet Toolbox in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!