I need to write a function that can create noise and then add that noise to the sound signal in my MATLAB code below:
% Creating 5 seconds of pleasant sound
% Sampling frequency more than twice of the frequency
fs = 2000;
t = [0:1/fs:5/15-1/fs]; % 5 seconds of peaceful music
% Defining variables for notes
G = sin(2*pi*392*t);
A = sin(2*pi*440*t);
B = sin(2*pi*493.9*t);
C = sin(2*pi*261.6*t);
% Notes for the piece of music
line1 = [G,G,A,G,F,A,A,B,A,G,B,B,C,B,A];
% Combining the notes to create the song
song = [line1];
% Playing the music
sound(song, fs);
% Normalizing the sound matrix to make it within the range of 16-bit precision
max_value = max(abs(song));
song = song./max_value;
% Declaring the file name to save the audio
filename = 'myAudioFile.wav';
% Writing the audio to file "myAudioFile.wav"
audiowrite(filename, song, fs);
% Reading the audio file
[tune, fs] = audioread(filename);