Dear Colleagues, I have been trying to generate the 1/f noise, where f means frequency. I would appreciate any help and guidance. Kind regards,
Massilon

 Réponse acceptée

Star Strider
Star Strider le 14 Juin 2017
Probably the easiest way is to create a FIR filter that has a ‘1/f’ passband, then filter random noise through it:
fv = linspace(0, 1, 20); % Normalised Frequencies
a = 1./(1 + fv*2); % Amplitudes Of ‘1/f’
b = firls(42, fv, a); % Filter Numerator Coefficients
figure(1)
freqz(b, 1, 2^17) % Filter Bode Plot
N = 1E+6;
ns = rand(1, N);
invfn = filtfilt(b, 1, ns); % Create ‘1/f’ Noise
figure(2)
plot([0:N-1], invfn) % Plot Noise In Time Domain
grid
FTn = fft(invfn-mean(invfn))/N; % Fourier Transform
figure(3)
plot([0:N/2], abs(FTn(1:N/2+1))*2) % Plot Fourier Transform Of Noise
grid
It uses the firls function to design a FIR filter that closely matches the ‘1/f’ passband. See the documentation on the various functions to get the result you want.
Note: The filter is normalised on the open interval (0,1), corresponding to (0,Fn) where ‘Fn’ is the Nyquist frequency, or half your sampling frequency. It should work for any sampling frequency that you want to use with it.
This should get you started. Experiment to get the result you want.

8 commentaires

I have got almost a perfect 1/x plot. Excellent, superb! Great job! Many thanks, Massilon.
Star Strider
Star Strider le 14 Juin 2017
As always, my pleasure!
Simulating ‘1/f’ noise is an interesting problem that I had never before considered.
Hour Elen Sayed
Hour Elen Sayed le 8 Août 2020
Could I ask what does those normalized frequencies represent ?
Star Strider
Star Strider le 8 Août 2020
The frequencies are normalised with respect to the Nyquist frequency. The normalised frequencies represent radian frequencies in the range of radians/time unit.
Antonio D'Amico
Antonio D'Amico le 25 Août 2020
Modifié(e) : Antonio D'Amico le 25 Août 2020
What if I want to add a white noise component, so to play with the corner frequency?
Use the randn function instead of rand:
ns = randn(1, N);
Make appropriate changes to get the result you want.
Antonio D'Amico
Antonio D'Amico le 26 Août 2020
Hello, thank you for your answer. If I understand the script correctly, it applies a 1/f (approximation) roll-off factor to the noise, whether it is uniformilly distributed (rand) or gaussian (randn). However what I would like to achieve is something like (From Wikimedia Commons)
(From Wikimedia Commons)
I hope I was clearer
Antonio D'Amico
Antonio D'Amico le 26 Août 2020
Modifié(e) : Antonio D'Amico le 26 Août 2020
Ok, I think I got it, something like this could work
fv = linspace(0, 1, 20); % Normalised Frequencies
a = zeros(1,20);
a(1:10) = 1./(1 + fv(1:10)*2); % Amplitudes Of 1/fv until 0.5
a(11:20) = a(10); % after 0.5 it gets flat
b = firls(42, fv, a); % Filter Numerator Coefficients
figure(1)
freqz(b, 1, 2^17) % Filter Bode Plot
N = 1E+6;
ns = randn(1, N);
invfn = filtfilt(b, 1, ns); % Create ‘1/f’ Noise
figure(2)
plot([0:N-1], invfn) % Plot Noise In Time Domain
grid
FTn = fft(invfn-mean(invfn))/N; % Fourier Transform
figure(3)
plot([0:N/2], abs(FTn(1:N/2+1))*2) % Plot Fourier Transform Of Noise
grid

Connectez-vous pour commenter.

Plus de réponses (2)

Ali Mostafa
Ali Mostafa le 11 Juin 2018

3 votes

f=0:1/fs:1-1/fs;S=1./sqrt(f); S(end/2+2:end)=fliplr(S(2:end/2)); S=S.*exp(j*2*pi*rand(size(f))); plot(abs(S)) S(1)=0;figure;plot(real(ifft(S)))

2 commentaires

Massimo Ciacci
Massimo Ciacci le 10 Août 2019
Quite ingenious to put the randomness in the phase, and this way the amplitude profile is exact, without the need to average out a lot of noise realizations. Thumbs up!
XIAOHUA HUA
XIAOHUA HUA le 11 Mar 2020
Great, thank you very much for sharing this.

Connectez-vous pour commenter.

James
James le 3 Oct 2023

0 votes

Hi were does 1./(1 + fv*2) come from?

3 commentaires

Star Strider
Star Strider le 3 Oct 2023
It keeps the amplitude vector from becoming infinite at the origin. With that amplitude calculation, it is 1 at the origin. The factor of 2 (that can be anything that works in a particular application), allows the amplitude to decrease differently than simply . If the factor is less than 1, the decrease is slower, if greater than 1, faster.
James
James le 3 Oct 2023
is there any paper or book I could look at to undestand that a bit more, or is this based on your own experience/skill?
Thank you very much for your response!
Star Strider
Star Strider le 3 Oct 2023
It’s entirely my own experience. I remember learning about noise in graduate school, in the context of biomedical instrumentation. I’m certain there must be more recent discussions of it, however I have no specific references.

Connectez-vous pour commenter.

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by