How to generate noise with particular frequency?
38 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Nur Fauzira Saidin
le 21 Sep 2015
Commenté : alon cohen
le 12 Avr 2020
Hi. I want to generate a noise with a certain frequency, for example 10kHz but I do not know how to. So I just proceed with this code:
% Open standard demo sound that ships with MATLAB.
[perfectSound, freq] = audioread('music.wav');
noise = 0.1*randn(size(perfectSound));
% Play noise
soundsc(noise, freq);
% Get sampling frequency
t=0:1/freq:(length(noise)-1)/freq;
figure(1);
plot(t,noise);
title('Noise');
ylabel('Amplitude');
xlabel('Length (in Second)');
% Graph it
n=length(noise)-1;
f=0:freq/n:freq;
wavefft=abs(fft(noise));%perform Fourier Transform
figure(2);
plot(f,wavefft);%plot Fourier Transform
xlabel('Frequency in Hz');
ylabel('Magnitude');
title('Noise FFT');
Then, result that I got is:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/149279/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/149281/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/149282/image.png)
From workspace, the noise frequency is 44100 Hz. What should I do if I want to generate noise with different frequency?
1 commentaire
mobin
le 28 Sep 2016
hi I think that the sampling frequency is 44100 Hz, It's the rate of your sampling. in fact your noise constitutes lots of frequencies, I think you might already have your designed noise frequency. My answer has no contradiction with the answer proposed by @Star Strider
Réponse acceptée
Star Strider
le 21 Sep 2015
Noise (‘white’ noise) is by definition broadband, so it does not have a specific frequency. You can create a 10 kHz signal with noise, but that is as close as you can get to doing what you want.
For example:
len = 15; % Length (sec)
f = 1E+4; % Frequency (Hz)
Fs = 8192; % Sampling Frequency (Hz)
t = linspace(0, len, Fs*len); % Time Vector
signal = sin(2*pi*f*t); % Signal (10 kHz sine)
sound(signal, Fs) % Original Signal
noise = signal + 0.1*randn(size(signal));
pause(15) % Wait For First Sound To Finish Playing
sound(noise, Fs) % Noisy Signal
You could also create and use an audiplayer object with playblocking, instead of inserting a pause call.
1 commentaire
alon cohen
le 12 Avr 2020
why did you choose specificly Fs=44100 (or 48000) ?
how does changing Fs affect the real frequency i hear out of my computer?
thanks.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Spectral Measurements dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!