当前位置:网站首页>Matlab-基于短时神经网络的声音分类
Matlab-基于短时神经网络的声音分类
2022-07-27 09:57:00 【用户9925864】
这个例子展示了如何使用深度学习过程对声音进行分类。
1、数据集生成
生成1000个白噪声信号、1000个棕色噪声信号和1000个粉色噪声信号。假设采样率为44.1 kHz,每个信号表示0.5秒的持续时间。
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、数据可视化
听声音信号,并使用melSpectrogram函数将其可视化。
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、将数据集分为训练集和验证集
创建一个由800个白噪声信号、800个棕色噪声信号和800个粉色噪声信号组成的训练集。
audioTrain = [wNoise(:,1:800),bNoise(:,1:800),pNoise(:,1:800)];
labelsTrain = [wLabels(1:800);bLabels(1:800);pLabels(1:800)];使用剩余的200个白噪声信号、200个棕色噪声信号和200个粉色噪声信号创建验证集。
audioValidation = [wNoise(:,801:end),bNoise(:,801:end),pNoise(:,801:end)];
labelsValidation = [wLabels(801:end);bLabels(801:end);pLabels(801:end)];4、信号提取
音频数据是高维的,通常包含冗余信息。通过首先提取特征,然后使用提取的特征训练模型,可以降低维数。创建audioFeatureExtractor对象以提取mel光谱随时间变化的质心和斜率。
aFE = audioFeatureExtractor("SampleRate",fs, ...
"SpectralDescriptorInput","melSpectrum", ...
"spectralCentroid",true, ...
"spectralSlope",true);调用extract从音频训练数据中提取特征。
featuresTrain = extract(aFE,audioTrain);
[numHopsPerSequence,numFeatures,numSignals] = size(featuresTrain)5、数据准备
在下一步中,您将把提取的特征视为序列,并使用sequenceInputLayer作为深度学习模型的第一层。当使用SequenceInputLayers作为网络中的第一层时,trainNetwork希望将训练和验证数据格式化为序列的单元数组,其中每个序列随时间由特征向量组成。sequenceInputLayer要求时间维度沿第二维度。
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 = 42提取特征
featuresValidation = extract(aFE,audioValidation);
featuresValidation = permute(featuresValidation,[2,1,3]);
featuresValidation = squeeze(num2cell(featuresValidation,[1,2]));6、定义和训练网络
定义网络架构。
layers = [ ...
sequenceInputLayer(numFeatures)
lstmLayer(50,"OutputMode","last")
fullyConnectedLayer(numel(unique(labelsTrain)))
softmaxLayer
classificationLayer];要定义train选项,请使用option选项(深度学习工具箱)。
options = trainingOptions("adam", ...
"Shuffle","every-epoch", ...
"ValidationData",{featuresValidation,labelsValidation}, ...
"Plots","training-progress", ...
"Verbose",false);要训练网络,请使用trainNetwork(深度学习工具箱)。
net = trainNetwork(featuresTrain,labelsTrain,layers,options);7、验证网络
使用经过训练的网络对新的白噪声、棕色噪声和粉色噪声信号进行分类。
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边栏推荐
- Matlab- draw superimposed ladder diagram and line diagram
- Shell integrated application cases, archiving files, sending messages
- Ant高级-task
- Shell variables, system predefined variables $home, $pwd, $shell, $user, custom variables, special variables $n, $, $*, [email protected],
- Interview Essentials: shrimp skin server 15 consecutive questions
- vs2019社区版下载教程(详细)
- oracle rac 19c pdb实例当掉
- 超赞的卡尔曼滤波详解文章
- 面试必备:虾皮服务端15连问
- pytorch中对BatchNorm2d()函数的理解
猜你喜欢

Uninstall cuda11.1

并发之线程状态转换

Data visualization

Brush the title "sword finger offer" day04

Metasploit-永恒之蓝攻击

Ant高级-task

LeetCode.1260. 二维网格迁移____原地暴力 / 降维+循环数组直接定位

3D修复论文:Shape Inpainting using 3D Generative Adversarial Network and Recurrent Convolutional Networks

NFS 服务器的搭建

About new_ Online_ Judge_ 1081_ Thoughts on Goldbach's conjecture
随机推荐
Leetcode.1260. 2D grid migration____ In situ violence / dimensionality reduction + direct positioning of circular array
Shell function, system function, basename [string / pathname] [suffix] can be understood as taking the file name in the path, dirname file absolute path, and user-defined function
3D face reconstruction and dense alignment with position map progression network
Why is redis so fast? Redis threading model and redis multithreading
How to create a.Net image with diagnostic tools
安装CUDA失败的情况nsight visual studio edition失败
使用 LSM-Tree 思想基于.NET 6.0 C# 写个 KV 数据库(案例版)
卸载CUDA11.1
Stylegan paper notes + modify code to try 3D point cloud generation
Ant advanced -path and fileset
Live countdown 3 days sofachannel 29 P2P based file and image acceleration system Dragonfly
Qt 学习(二) —— .pro文件详解
oracle rac 19c pdb实例当掉
Final examination paper of engineering materials
[SCM]源码管理 - perforce 分支的锁定
Redis 为什么这么快?Redis 的线程模型与 Redis 多线程
Anchor free detector: centernet
Summary of engineering material knowledge points (full)
Oracle RAC 19C PDB instance is down
Food safety | the more you eat junk food, the more you want to eat it? Please keep this common food calorimeter