How to control the variation speed of a generated random signal ?

5 vues (au cours des 30 derniers jours)
youcha
youcha le 3 Mai 2022
Modifié(e) : Jan le 4 Mai 2022
Hello:
I want to generate a random signal that 1) follows a Normal distribution 2) has slow variations. So I have did this:
pd_lp = makedist('Normal','mu',2,'sigma',1);
R_lp_base = random(pd_lp,5000,1);
figure
plot(R_lp_base)
The variation of this signal is rapid and I need it to be slow. Does anyone knows how to control the variation´s speed of the random generated signals in matlab ?
  2 commentaires
Jan
Jan le 3 Mai 2022
How slow is "slow"? Would this solve your needs:
x = sort(R_lp_base);
This is the slowest possible version.
youcha
youcha le 4 Mai 2022
Hello:
I want something similar to the effect of creating a signal with 50 points and then interpolate the signal to expand the points and get 5000 points.
The idea of interpolation is not correct for my case because it modify the statistical distribution of the original signal (R_lp_base is Gaussian but R_lp is not Gaussian)
pd_lp = makedist('Normal','mu',2,'sigma',1);
R_lp_base = random(pd_lp,50,1);
figure()
plot(R_lp_base)
R_lp=interp1(1:50,R_lp_base,linspace(1,50,5000)','spline');
figure
plot(R_lp)

Connectez-vous pour commenter.

Réponses (1)

Jan
Jan le 4 Mai 2022
Modifié(e) : Jan le 4 Mai 2022
Start with sorting the random values. Then mix the result partially:
x = rand(1, 500);
y = sort(x);
z1 = [y(1:2:500), flip(y(2:2:500))];
z2 = [z1(1:2:500), flip(z1(2:2:500))];
t = 1:500;
plot(t, x, 'b', t, y+1.1, 'g', t, z1+2.2, 'c', t, z2+3.3, 'r')
This has the wanted distribution and you can increase the "speed" with applying [zi(1:2:500), flip(zi(2:2:500))] repeatedly.
Alternative:
x = rand(1, 500);
y = x;
s = 0.01;
for k = 2:500
match = find(abs(y(k:500) - y(k-1)) < s);
if ~isempty(match)
r = match(randi([1, numel(match)])) + k - 1;
[y(k), y(r)] = swap(y(k), y(r));
end
end
t = 1:500;
plot(t, x, 'b', t, y+1, 'c')
mean(abs(diff(x)))
ans = 0.3521
mean(abs(diff(y)))
ans = 0.0432
function [b,a] = swap(a,b)
end
What an ugly hack. Call it "mudsort".
  1 commentaire
youcha
youcha le 4 Mai 2022
I did not understand your code.
If you have ploted the code I added in the last comment you will be able to see the meaning of slow variation that I want.
My question is there anyway to adjust the argumento or the parameters of the makedist function to control the speed variation of the signal?

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by