Adding white noise to a wav file??? URGENT!
4 views (last 30 days)
Show older comments
Hi,
I need to add white gaussian noise to a wav file. I've managed to do this by adding the two together
freq = 9000;
duration = 0.4;
S2 = rand(1,(freq * duration));
S1 = audioread('drum.wav');
S = S1;
S(1:length(S2), 2) = S2;
soundsc(S)
but the sound signal in the wav.file when they are both played together turns into a really low distorted pitch. I understand now that if i was [y,fs] = audioread('drum.wav') then it will play normally but im not sure how to add white noise to this??? I have tried several ways but nothing seems to work apart from the above which distorts it!!
please help!!! URGENT!!
* I preferably want someone using the program to change the white noise using some kind of Standard Deviation so i dont want to just use awgn*
0 Comments
Accepted Answer
Image Analyst
on 5 Dec 2014
You didn't use randn and you didn't pass in the frequency. Try this:
% Open standard demo sound that ships with MATLAB.
[perfectSound, freq] = audioread('guitartune.wav');
% Add noise to it.
noisySound = perfectSound + 0.01 * randn(length(perfectSound), 1);
% Find out which sound they want to play:
promptMessage = sprintf('Which sound do you want to hear?');
titleBarCaption = 'Specify Sound';
button = questdlg(promptMessage, titleBarCaption, 'Perfect', 'Noisy', 'Perfect');
if strcmpi(button, 'Perfect')
% Play the perfect sound.
soundsc(perfectSound, freq);
else
% Play the noisy sound.
soundsc(noisySound, freq);
end
More Answers (0)
See Also
Categories
Find more on Audio and Video Data in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!