You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
How to input noise during the audio transmission process ?
1 view (last 30 days)
Show older comments
Hello everyone
I do audio compression with bit per sample variations like this:
[y,Fs]=audioread('water.wav');
audiowrite('testing.flac',y,Fs,'BitsPerSample', 8);
Now I also want to input noise into the process
Does anyone know how the code should be used?
thank you
Accepted Answer
Mathieu NOE
on 21 Sep 2021
hello
if you simply want to add some white noise you can do this
[y,Fs]=audioread('water.wav');
y = y + 0.1*randn(size(y)); % adjust amplitude to your needs
y = y./max(abs(y)); % normalize data to avoid saturation (may be depend on output format)
audiowrite('testing.flac',y,Fs,'BitsPerSample', 8);
you can also add a low or high or bandpass filter on the random noise if you want to have noise in a certain frequency range.
19 Comments
Sisi Misi
on 22 Sep 2021
Edited: Sisi Misi
on 22 Sep 2021
alright Mr, thank you
But I have another question, when I listen to the results I completely lose the original audio. What if we want to input noise into the audio but the original audio is still heard and can keep the audio in 2 channels, because my original audio is 2 channels?
I'm confused because I'm using lossless compression here
Mathieu NOE
on 22 Sep 2021
hello
could you share your wav file ? the amount (amplitude) of noise must be adapted to the amplitude of your sgnal so you must probably do some trials
if you can share your wav file I can further help you;
Sisi Misi
on 22 Sep 2021
This is the audio folder Mr
This audio is obtained from the music cloud
This audio consists of two channels, I did a lossless compression process (into a .flac format codec) with variations in bits per sample (24, 16, and 8 bits) and in the transmission process I had to put noise into it. Then decompress it back into a wav file
I want to see the performance of the lossless audio codec how resistant the audio is to noise, because what I read for lossless compression is noise resistance
I hope you can help me because I'm still confused about what I'm doing now
Thank you very much Mr
Mathieu NOE
on 22 Sep 2021
hello
I simply reduced the noise amplitude so it's now clearly audible in the flac version , without hiding the audio content. You can still adjust the amplitude (here 0.01) to your needs and play with flac resolution
[y,Fs]=audioread('water.wav');
y = y + 0.01*randn(size(y)); % adjust noise amplitude to your needs
y = y./max(abs(y)); % normalize data to avoid saturation (may be depend on output format)
audiowrite('testing.flac',y,Fs,'BitsPerSample', 8);
Sisi Misi
on 22 Sep 2021
alright Mr
how to keep the new audio that is saved in two channels?
is there any code to add?
Mathieu NOE
on 22 Sep 2021
the output in flac is stereo , I didn't changed anything to the audio size (2 channels)
Sisi Misi
on 22 Sep 2021
ok Mr
In matlab 2015b there is an error like this :
but after i tried it in matlab online
everything is fine
I'm sorry Mr
Thank you so much
Image Analyst
on 22 Sep 2021
There should be no difference between local and online versions of MATLAB. Can you reproduce this error?
Mathieu NOE
on 22 Sep 2021
Maybe my fault
this should avoid any issue now :
replace
y = y./max(abs(y)); % normalize data to avoid saturation (may be depend on output format)
with
y = y./max(abs(y),[],'all'); % normalize data to avoid saturation (may be depend on output format)
Sisi Misi
on 23 Sep 2021
I don't know Mr
There is still an error here, when I use
[y,Fs]=audioread('water.wav');
y = y + 0.01*randn(size(y)); % adjust noise amplitude to your needs
y = y./max(abs(y),[],'all');% normalize data to avoid saturation (may be depend on output format)
audiowrite('testing8.flac',y,Fs,'BitsPerSample', 8);
audiowrite('testing8.wav',y,Fs)
so I try another code like this, but still errorr
[y,Fs]=audioread('water.wav');
y = y + 0.01*randn(size(y)); % adjust noise amplitude to your needs
y = y./max(abs(y),[],'omitnan');% normalize data to avoid saturation (may be depend on output format)
audiowrite('testing8.flac',y,Fs,'BitsPerSample', 8);
audiowrite('testing8.wav',y,Fs)
but in matlab online, everything is fine Mr
Mathieu NOE
on 23 Sep 2021
hello
I think the older 2015 release is not compatible with the syntax max(abs(y),[],'all');
I use the R2020b with works fine.
in case you stick to R2015 , try this modification :
% normalize data to avoid saturation (may be depend on output format)
% m = max(abs(y),[],'all'); % R2020
m = max(abs(y(:))); % R2015 and below
y = y./m; % normalize data
Sisi Misi
on 30 Sep 2021
Hi Mr Mathieu NOE
I want to ask you again
I got instructions again to input noise into the audio when we transmit
it means when we do compression
in the "audiowrite" function and in that function we directly input the noise
can we do that Mr ?
Mathieu NOE
on 30 Sep 2021
hello
the compression is done inside the audiowrite function , depending of the format (flac is compressed)
you don't have to do anything in your own code as compression is done by audiowrite function
Sisi Misi
on 1 Oct 2021
yes Mr
I mean, we input noise into the compressed audio instead of the original audio
or maybe when we save the compressed audio we input the noise,
the point is that the input noise is not original audio but compressed audio, immediately when we save the compressed audio
do you understand what I mean Mr ?
sorry I'm confused how to convey it, I hope you understand
because really I need your help
thank you Mr
Mathieu NOE
on 1 Oct 2021
hello
so far the code will add the noise to the original audio , not the compressed audio
the compression is done after the noise is added (y = y + 0.01*randn(size(y));) , because as explained above , the compression is done inside audiowrtite when you select a certain type of format (wav and flac are both compressed audio formats)
More Answers (0)
See Also
Categories
Find more on Audio I/O and Waveform Generation in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)