To generate a Pseudorandom sequence based on some constraints

I have 4 base triplets- ABC, DEF, GHI, JKL. Also there are catch word- Z. I want a pseudorandomixed sequence generated such that: * a) Each triplet should be repeated 40 times * b)No repeated triplets should be present (e.g. …T1T1…) * c)No repeated pairs of triplets should be present (e.g. …T1T2T1T2…). * d)The catch should also be presented 40 times
Also can the code give me the transitional probability of first letter in each triplet? Eg. if a part of the random sequence is- ABC and DEF, what is the transitional (conditional) probability of D|C?
Can anyone help me do this?

 Accepted Answer

Here's one possibility. The transition probabilities are always 1/5, except for every 5th transition, which are 1/4
function out = myfunc(N)
if nargin<1, N=40; end
A=zeros(5,N);
A(:,1)=randperm(5).';
for ii=2:N
A(1,ii)=randi(5);
z=(1:5).';
z(A(1,ii))=[];
A(2:end,ii) = z(randperm(4));
end
triplets={'ABC','DEF','GHI','JKL','Z'};
out=reshape(triplets(A),1,[]);

3 Comments

Thanks Matt, What if I had to change the number of triplets? make it 6 triplets? and had to increase the number of repetition?
Not a problem. Just change the 5s to 6s and so forth.
my abc, def triplets are actually music notes abc=C#, D#, E; def=F#, A, B; ghi=C,G#,A and jkl=D, G,F#. I used this code to generate them:
Fs=8000;
Ts=1/Fs;
t=[0:Ts:0.3];
F_A = 440; %Frequency of note A is 440 Hz
F_B = 493.88;
F_Csharp = 554.37;
F_D = 587.33;
F_E = 659.26;
F_F = 698.5;
F_G = 784.0;
F_Dsharp=622.3;
F_Fsharp = 739.9;
F_Gsharp=830.6;
F_C=523.3;
trip_ABC=[F_Csharp;F_Dsharp;F_E];
trip_DEF=[F_F;F_A;F_B];
trip_GHI=[F_C;F_Gsharp;F_A];
trip_JKL=[F_D; F_G; F_Fsharp];
abc=cos(2*pi*trip_ABC*t);
def=cos(2*pi*trip_DEF*t);
ghi=cos(2*pi*trip_GHI*t);
jkl=cos(2*pi*trip_JKL*t);
sig_abc = reshape(abc',3*length(t),1);
sig_def = reshape(def',3*length(t),1);
sig_ghi = reshape(ghi',3*length(t),1);
sig_jkl = reshape(jkl',3*length(t),1);
my question is how do I now generate the same pseudorandom sequence (with notes instead of alphabets) with same constraints AND have outputs for the TP? i.e TP of first note of a triplet|last note of any of the remaining three triplets? eg TP F|E, TP F|A, TP F|F#.

Sign in to comment.

More Answers (0)

Categories

Find more on Random Number Generation in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!