Question

In: Computer Science

Deep leraning/LSTM/Matlab There is a Matlab code that is doing the following steps for deep learning...

Deep leraning/LSTM/Matlab

There is a Matlab code that is doing the following steps for deep learning and applying LSTM, I need to change first three steps to use our dataset to train this model and you don't need to change other.

I need to apply that for .ogg audio files so Create and Use some audio files with .ogg format as sample data and give me the code.

The following steps is for your information:

  1. Three classes of audio signals are generated and labeled as 'white', 'brown', and 'pink'. Each class has 1000 samples.
  2. 800 samples from each class are used as the training samples to train the deep neural network, so total 800*3=2400 samples in the training dataset. Their labels are their class names 'white', 'brown', and 'pink'. (Lines 29 and 30)
  3. 200 samples from each class are used as the validation samples to test the performance of deep neural network, so total 600 samples in the validation dataset. Their labels are their class names 'white', 'brown', and 'pink' (Lines 32 and 33)
  4. Extract features from the training dataset and validation dataset.
  5. define the structure of the neural network model (LSTM)
  6. set training options
  7. train the model iteratively using the training dataset and test the model using the validation dataset every iteration.
  8. finish training and get the trained model.
  9. generate test dataset and use the trained model to classify the test dataset into three classes, 'white', 'brown', and 'pink'.

Code:

fs = 44.1e3;

duration = 0.5;

N = duration*fs;

wNoise = 2*rand([N,1000]) - 1;

wLabels = repelem(categorical("white"),1000,1);

bNoise = filter(1,[1,-0.999],wNoise);

bNoise = bNoise./max(abs(bNoise),[],'all');

bLabels = repelem(categorical("brown"),1000,1);

pNoise = pinknoise([N,1000]);

pLabels = repelem(categorical("pink"),1000,1)

sound(wNoise(:,1),fs)

melSpectrogram(wNoise(:,1),fs)

title('White Noise')

sound(bNoise(:,1),fs)

melSpectrogram(bNoise(:,1),fs)

title('Brown Noise')

sound(pNoise(:,1),fs)

melSpectrogram(pNoise(:,1),fs)

title('Pink Noise')

featuresTrain = extract(aFE,audioTrain);

[numHopsPerSequence,numFeatures,numSignals] = size(featuresTrain)

audioTrain = [wNoise(:,1:800),bNoise(:,1:800),pNoise(:,1:800)];

labelsTrain = [wLabels(1:800);bLabels(1:800);pLabels(1:800)];

audioValidation = [wNoise(:,801:end),bNoise(:,801:end),pNoise(:,801:end)];

labelsValidation = [wLabels(801:end);bLabels(801:end);pLabels(801:end)];

aFE = audioFeatureExtractor("SampleRate",fs, ...

"SpectralDescriptorInput","melSpectrum", ...

"spectralCentroid",true, ...

"spectralSlope",true);

featuresTrain = permute(featuresTrain,[2,1,3]);

featuresTrain = squeeze(num2cell(featuresTrain,[1,2]));

numSignals = numel(featuresTrain)

[numFeatures,numHopsPerSequence] = size(featuresTrain{1})

featuresValidation = extract(aFE,audioValidation);

featuresValidation = permute(featuresValidation,[2,1,3]);

featuresValidation = squeeze(num2cell(featuresValidation,[1,2]));

layers = [ ...

sequenceInputLayer(numFeatures)

lstmLayer(50,"OutputMode","last")

fullyConnectedLayer(numel(unique(labelsTrain)))

softmaxLayer

classificationLayer];

options = trainingOptions("adam", ...

"Shuffle","every-epoch", ...

"ValidationData",{featuresValidation,labelsValidation}, ...

"Plots","training-progress", ...

"Verbose",false);

net = trainNetwork(featuresTrain,labelsTrain,layers,options);

wNoiseTest = 2*rand([N,1]) - 1;

classify(net,extract(aFE,wNoiseTest)')

bNoiseTest = filter(1,[1,-0.999],wNoiseTest);

bNoiseTest= bNoiseTest./max(abs(bNoiseTest),[],'all');

classify(net,extract(aFE,bNoiseTest)')

pNoiseTest = pinknoise(N);

classify(net,extract(aFE,pNoiseTest)')

Solutions

Expert Solution

sound(wNoise(:,1),fs)
title('White Noise')
melSpectrogram(wNoise(:,1),fs)
 
 
sound(bNoise(:,1),fs) title('Brown Noise')
 
melSpectrogram(bNoise(:,1),fs)
 
 
sound(pNoise(:,1),fs) title('Pink Noise')
melSpectrogram(pNoise(:,1),fa)
 
audioTrain = [wNoise(:,1:800),bNoise(:,1:800),pNoise(:,1:800)];
labelsTrain = [wLabels(1:800);bLabels(1:800);pLabels(1:800)];
 
 
audioValidation = [wNoise(:,801:end),bNoise(:,801:end),pNoise(:,801:end)];
labelsValidation = [wLabels(801:end);bLabels(801:end);pLabels(801:end)];
 
aFE = audioFeatureExtractor("SampleRate",fs, ...
    "SpectralDescriptorInput","melSpectrum", ...
    "spectralCentroid",true, ...
    "spectralSlope",true);
 
featuresTrain = extract(aFE,audioTrain);
[numHopsPerSequence,numFeatures,numSignals] = size(featuresTrain)
 
featuresTrain = permute(featuresTrain,[2,1,3]);
featuresTrain = squeeze(num2cell(featuresTrain,[1,2]));

numSignals = numel(featuresTrain)
 
numFeatures,numHopsPerSequence] = size(featuresTrain{1})
 
featuresValidation = extract(aFE,audioValidation);
featuresValidation = permute(featuresValidation,[2,1,3]);
featuresValidation = squeeze(num2cell(featuresValidation,[1,2]));
 
layers = [ ...
    sequenceInputLayer(numFeatures)
    lstmLayer(50,"OutputMode","last")
    fullyConnectedLayer(numel(unique(labelsTrain)))
    softmaxLayer
    classificationLayer];
 
options = trainingOptions("adam", ...
    "Shuffle","every-epoch", ...
    "ValidationData",{featuresValidation,labelsValidation}, ...
    "Plots","training-progress", ...
    "Verbose",false);
 
net = trainNetwork(featuresTrain,labelsTrain,layers,options);
 
For testing the network:
 
wNoiseTest = 2*rand([N,1]) - 1;
classify(net,extract(aFE,wNoiseTest)')
 
 
bNoiseTest = filter(1,[1,-0.999],wNoiseTest);
bNoiseTest= bNoiseTest./max(abs(bNoiseTest),[],'all');
classify(net,extract(aFE,bNoiseTest)')
 
pNoiseTest = pinknoise(N);
classify(net,extract(aFE,pNoiseTest)')
In first go 

Your answer will be:

ans= categorial white 

In second go

Your answer will be:

ans= categorial brown

In third go

Your answer will be:

ans= categorial pink


Related Solutions

When doing Machine Learning and Deep Learning (AI) research which language is better to use Java...
When doing Machine Learning and Deep Learning (AI) research which language is better to use Java or Python? When would you use Java and when would you use Python?
Write a matlab code to do following steps; i) Record your voice by sampling frequency 22...
Write a matlab code to do following steps; i) Record your voice by sampling frequency 22 kHz ii) Down sample the voice by 2 listen to your voice iii) Down sample the voice by 3 listen to your voice Please explain the code clearly. Thank you.
This is a Matlab Exercise problem. Please create the Matlab code and figure for the following...
This is a Matlab Exercise problem. Please create the Matlab code and figure for the following problem using problem specifications: Plot x vs y when y=sin(x), y=cos(x), y=sin (2*x), and y=2*sin(x) when x = 1:0.1:10. Use 2 by 2 subplot, sin(x) is in location 1, cos(x) is in location 2, sin(2*x) is in location 3 and 2*sin(x) is in location 4. The plot should have: (1) x label = ‘x value’, y label = ‘y value’, legend ‘y=sin(x)’,’ y=cos(x)’,’ y=sin...
MATLAB CODE FOR E xtreme learning machine using for classification task. image processing electrical. if you...
MATLAB CODE FOR E xtreme learning machine using for classification task. image processing electrical. if you know then try or leave for other
The following code must be written using matlab How to loop through a vector in matlab...
The following code must be written using matlab How to loop through a vector in matlab and assigning a value to every 4th entry. The vector could be of any length. Thanks
Matlab code for Gauss Siedel with solved example in Matlab
Matlab code for Gauss Siedel with solved example in Matlab
solve in MATLAB and screenshot code ?′′ −??′ +??= ???(????−?????)
solve in MATLAB and screenshot code ?′′ −??′ +??= ???(????−?????)
Face detection code in Matlab
Face detection code in Matlab
MATLAB code for the following question. In the game of Monopoly, a pair of dice are...
MATLAB code for the following question. In the game of Monopoly, a pair of dice are rolled to move a player's piece around the board. If a double is rolled (the dice show the same number), the player receives another roll of the dice. If a double is rolled a second time, a third roll of the dice is received. If a double is rolled on the third occasion, the player forfeits their turn (and goes to Jail). Write a...
Fill in the blanks in the MATLAB code below.
Fill in the blanks in the MATLAB code below. (Do not type unnecessary words or blank spaces in your response. The correct answers are case-sensitive.) % Consider a row vector v. % Complete the lines of code below to find the average and standard deviation of the elements of vector v such that these two values are assigned to variables M and S, respectively. E = G =
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT