-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathnoise_add.m
35 lines (28 loc) · 878 Bytes
/
noise_add.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
close all;
clear all;
prompt = 'enter directory path of the dataset of each instrument: ';
directory_in=input(prompt,'s');
%directory_in = '/home/simran/SMAI/Learning Instrument Recognition/Dataset/Waves/';
prompt2 = 'enter directory path for the noisy data of each instrument: ';
directory_noisy=input(prompt2,'s');
dir(directory_in);
d = dir(directory_in);
isub = [d(:).isdir];
nameFolds = {d(isub).name}';
nameFolds(ismember(nameFolds,{'.','..'})) = [];
for i = 1:size(nameFolds)
nums = [nameFolds{i,:}];
s = strcat(directory_in,nums);
allFiles = dir(s);
allNames = {allFiles.name};
allNames(ismember(allNames,{'.','..'})) = [];
[rows, columns] = size(allNames);
for j = 1:columns
audio_path = strcat(s,'/',[allNames{:,j}]);
[y,Fs] = audioread(audio_path);
zz = randn(size(y))/50;
yy = y + zz;
c = [directory_noisy,[allNames{:,j}]];
audiowrite(c,yy,Fs);
end
end