当前位置:网站首页>Matlab sound classification based on short-time neural network
Matlab sound classification based on short-time neural network
2022-07-27 10:20:00 【User 9925864】
This example shows how to use the deep learning process to classify sounds .
1、 Dataset generation
Generate 1000 A white noise signal 、1000 A brown noise signal and 1000 A pink noise signal . Suppose the sampling rate is 44.1 kHz, Each signal indicates 0.5 Second duration .
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);2、 Data visualization
Listen to the sound signal , And use melSpectrogram Function to visualize it .
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')3、 The data set is divided into training set and verification set
Create a by 800 A white noise signal 、800 A brown noise signal and 800 A training set of pink noise signals .
audioTrain = [wNoise(:,1:800),bNoise(:,1:800),pNoise(:,1:800)];
labelsTrain = [wLabels(1:800);bLabels(1:800);pLabels(1:800)];Use the rest of 200 A white noise signal 、200 A brown noise signal and 200 A pink noise signal creates a verification set .
audioValidation = [wNoise(:,801:end),bNoise(:,801:end),pNoise(:,801:end)];
labelsValidation = [wLabels(801:end);bLabels(801:end);pLabels(801:end)];4、 Signal extraction
Audio data is high dimensional , Usually contains redundant information . By first extracting features , Then use the extracted features to train the model , It can reduce the dimension . establish audioFeatureExtractor Object to extract mel The centroid and slope of the spectrum over time .
aFE = audioFeatureExtractor("SampleRate",fs, ...
"SpectralDescriptorInput","melSpectrum", ...
"spectralCentroid",true, ...
"spectralSlope",true);call extract Extract features from audio training data .
featuresTrain = extract(aFE,audioTrain);
[numHopsPerSequence,numFeatures,numSignals] = size(featuresTrain)5、 Data preparation
In the next step , You will treat the extracted features as sequences , And use sequenceInputLayer As the first layer of the deep learning model . When using SequenceInputLayers As the first layer in the network ,trainNetwork You want to format the training and validation data into a sequence of cell arrays , Each sequence is composed of eigenvectors over time .sequenceInputLayer The time dimension is required to follow the second dimension .
featuresTrain = permute(featuresTrain,[2,1,3]);
featuresTrain = squeeze(num2cell(featuresTrain,[1,2]));
numSignals = numel(featuresTrain)
numSignals = 2400
[numFeatures,numHopsPerSequence] = size(featuresTrain{1})
numFeatures = 2
numHopsPerSequence = 42The extracted features
featuresValidation = extract(aFE,audioValidation);
featuresValidation = permute(featuresValidation,[2,1,3]);
featuresValidation = squeeze(num2cell(featuresValidation,[1,2]));6、 Define and train networks
Define network architecture .
layers = [ ...
sequenceInputLayer(numFeatures)
lstmLayer(50,"OutputMode","last")
fullyConnectedLayer(numel(unique(labelsTrain)))
softmaxLayer
classificationLayer];To define the train Options , Please use option Options ( Deep learning toolbox ).
options = trainingOptions("adam", ...
"Shuffle","every-epoch", ...
"ValidationData",{featuresValidation,labelsValidation}, ...
"Plots","training-progress", ...
"Verbose",false);To train the network , Please use trainNetwork( Deep learning toolbox ).
net = trainNetwork(featuresTrain,labelsTrain,layers,options);7、 Verify the network
Use a trained network for new white noise 、 Brown noise and pink noise signals are classified .
wNoiseTest = 2*rand([N,1]) - 1;
classify(net,extract(aFE,wNoiseTest)')
ans = categorical
white
bNoiseTest = filter(1,[1,-0.999],wNoiseTest);
bNoiseTest= bNoiseTest./max(abs(bNoiseTest),[],'all');
classify(net,extract(aFE,bNoiseTest)')
ans = categorical
brown
pNoiseTest = pinknoise(N);
classify(net,extract(aFE,pNoiseTest)')
ans = categorical
pink边栏推荐
- Mathematical reasoning: five couples get together and shake hands when they meet
- Huawei switch dual uplink networking smart Link Configuration Guide
- Summary of binary tree exercises
- Shell variables, system predefined variables $home, $pwd, $shell, $user, custom variables, special variables $n, $, $*, [email protected],
- wind10配置adb命令
- There is no CUDA option in vs2019+cuda11.1 new project
- 01_ Movie recommendation (contentbased)_ Object portrait
- Two architectures of ETL (ETL architecture and ELT Architecture)
- hdu5288(OO’s Sequence)
- window平台下本地连接远程服务器数据库(一)
猜你喜欢

Pytorch installation (very detailed)

NFS 服务器的搭建

Two architectures of ETL (ETL architecture and ELT Architecture)

Open3d library installation, CONDA common instructions, importing open3d times this error solving environment: failed with initial frozen solve Retrying w

Oracle查看硬解析

Matlab底层源代码实现图像的中值滤波(用于消除图像上一些杂点)

Pygame: alien invasion

Oracle调整数据文件大小杂谈

Metaaploit-后渗透技知识

Program translation and execution, from editing, preprocessing, compilation, assembly, linking to execution
随机推荐
【英雄哥六月集训】第 27天: 图
Color segmentation using kmeans clustering
声音处理之-梅尔频率倒谱系数(MFCC)
Leetcode.814. binary tree pruning____ DFS
Preparation for Android interview (including the whole process of interview, interview preparation, interview questions and materials, etc.)
After one year, the paper was finally accepted by the international summit
Dcgan paper improvements + simplified code
Shell流程控制(重点)、if 判断、case 语句、let用法、for 循环中有for (( 初始值;循环控制条件;变量变化 ))和for 变量 in 值 1 值 2 值 3… 、while 循环
NVIDIA geforce experience login error: the verifier failed to load. Please check your browser settings, such as the advertisement interceptor (solution)
Understanding of batchnorm2d() function in pytorch
Pygame: alien invasion
程序的翻译和执行,从编辑、预处理、编译、汇编、链接到执行
pytorch的安装(非常详细)
使用 Kmeans聚类实现颜色的分割
hdu5288(OO’s Sequence)
Live countdown 3 days sofachannel 29 P2P based file and image acceleration system Dragonfly
活体检测综述
Matlab/simulink sample sharing for solving differential equations
语音数据采集-实时语音数据可视化
邮件服务器