Converting a set of audio signals to images and saving them.
18 views (last 30 days)
Show older comments
Hello friends. I want to do spectral conversion on my audio signals and then save the output images somewhere else. But I don't know how to read and write in the images.
% make a list of wave files in training_data folder
folderInfo = dir('**/*.wav');
folderInfo1 = dir('**/*.tsv');
folderInfo2 = dir('**/*.txt');
% fir bandpass filter design with fc1 = 20/fs/2 and fc2 = 500/fs/2 with
f = [0 0.005 0.015 0.245 0.255 1];
a = [0 0 1 1 0 0];
b = firpm(100,f,a);
% feature vector calculation
x = audioread(folderInfo(i).name);
% signal filtering
xf = filter(b,1,x);
Jan on 6 Feb 2023
"But I don't know how to read and write in the images." - use imread and imwrite.
Avoid to add a folder to Matlab's path only to read or write some files. This is a source of unexpected behavior, if the folders contain m-files. Use full paths instead and do not change the current folder:
folder = cd; % Or prefer an absolute path here also
folderInfo = dir(fullfile(folder, 'training_data_out', '**/*.wav');
Remember that cd() commands can be called unexpectedly in callbacks of timers or GUIs during your code runs. This is a typical source of bugs and can be avoided easily.
DGM on 6 Feb 2023
I don't know what st() is, but I have to assume it's a function -- possibly an STFT tool? If so, then it won't be a function anymore. You've just created a variable with the same name.
If that's a correct assumption, then I'd expect st to be a 2D array. I would have no reason to expect that each file would produce a 3D array with as many pages as there are audio files in the directory. So I'd have to conclude that this isn't the way to address m.
To generate a pseudocolored image from real-valued data on an arbitrary scale:
% a page
st = 10*randn(100,100); % random fake data (2D)
st = abs(st);
% convert to an RGB image using uniform quantization
N = 256; % specify quantization levels
CT = jet(N); % specify colormap to use
outpict = ind2rgb(gray2ind(mat2gray(st),N),CT);
% do something with it
Just a guess, but this may be relevant. Sometimes similar questions pop up at the same time when multiple people are working on the same assignment.
Find more on Hilbert and Walsh-Hadamard Transforms in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!