How to create white noise and pink noise ?

40 views (last 30 days)
薫
on 24 Jan 2025
Commented: on 6 Feb 2025
I would like to know how to make pink noise and white noise.
I would also like to know how to put the created noise on the acquired tunnel current z.
I own DSP System Toolbox and Signal Processing Toolbox.
%Parameter Setting
pixel_image = 256; %Input the number of pixels in the image obtained by raster scanning (input 2^n)
dr = 1/(2*sqrt(3)); %Enter dither circle radius [grid].
a_fast_grid = 10; %fast axis scanning range [grid]
a_slow_grid = 10; %Slow axis scanning range [grid]
fm=5000; %Dither circle modulation frequency [Hz]
fs= fm * 240 ; %Sampling frequency [Hz]
f_fast = 10.2; %Input scanning frequency [Hz] (1 line scanning count in 1[s])
start_point_x = 0; %Input x-coordinate of scanning start point (input 1 if you want to move by 1[grid])
start_point_y = 0; %Input y-coordinate of scanning start point (input 1 if you want to move by 1[grid])
%Parameter setting for fast-axis triangular wave
amplitude_fast = a_fast_grid/2; %fast axis amplitude
%Parameter setting for slow-axis triangular wave
amplitude_slow = a_slow_grid/2; %slow axis amplitude
f_slow = (f_fast)/(2*pixel_image); %Slow axis triangular wave frequency
% Generation of time vectors
total_time=256/f_fast; %Total Scan Time
t = linspace(0, total_time, fs * total_time);
x_raster = start_point_x + amplitude_fast*(2/pi)*acos(cos(2*pi*f_fast*t));
y_raster = start_point_y + amplitude_slow*(2/pi)*acos(cos(2*pi*f_slow*t));
x_dither = dr*cos(2*pi*fm*t);
y_dither = dr*sin(2*pi*fm*t);
x = x_raster + x_dither;
y = y_raster + y_dither;
z1 = cos(2*pi*((x-y)/(sqrt(3))));
z2 = cos(2*pi*(2*y/(sqrt(3))));
z3 = cos(2*pi*((x+y)/(sqrt(3))));
z = (z1 + z2 + z3);

Accepted Answer

Ishaan
Ishaan on 28 Jan 2025
Hey @大地,
I realise that you intend to generate noises and add them to the acquired tunnel current.
To generate noise, you can use ColoredNoise function from DSP System Toolbox.
To generate pink noise, you can use the following code.
pinkNoiseGenerator = dsp.ColoredNoise('Color', 'pink', 'SamplesPerFrame', length(z));
pinkNoise = pinkNoiseGenerator();
And to generate white noise you can use therandn function like so.
noiseAmplitude = 0.1;
whiteNoise = noiseAmplitude * randn(size(z));
Additionally, "ColoredNoise" function can be used generate white noise as well by changing the Colorparameter to ‘white’.
To add these noises to acquired tunnel current `z` value. You can use simple array addition.
z_with_white_noise = z + whiteNoise;
z_with_pink_noise = z + pinkNoise;
NOTE: since z is a row vector and the noise, we generated from ColoredNoise function is a column vector, we would require transposing the noise vector.
You can refer to the documentation, as shared by @prabhat kumar sharma for more information on the function.
  1 Comment
薫
on 6 Feb 2025
Thanks for the advice.
We were able to create pink noise and white noise.
Thank you very much.

Sign in to comment.

More Answers (0)

Products


Release

R2024b

Community Treasure Hunt

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

Start Hunting!