How to control the variation speed of a generated random signal ?
5 views (last 30 days)
Show older comments
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 Comments
Jan
on 3 May 2022
How slow is "slow"? Would this solve your needs:
x = sort(R_lp_base);
This is the slowest possible version.
Answers (1)
Jan
on 4 May 2022
Edited: Jan
on 4 May 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)))
mean(abs(diff(y)))
function [b,a] = swap(a,b)
end
What an ugly hack. Call it "mudsort".
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!