introduce new values into an array and shift the others

Hello,
i have a 256x2840 matrix, this matrix contain values of an eeg signal almost periodic and each coloumn (256 samples) contain each period.
I should introduce random values (for ex. 9 samples) with mean zero and standard deviation of 1,2 or 10ms at the beginning of the signal, so that all the other value are shifted and the periods of the signal are no more in phase..
I turned the matrix in the vector ev and i did:
x=randn(9,1);
for i=1:9
ev(1:9)=x(i)';
end
but i guess that in this way the code changes just the first 9 values and the other doesn't shift...help me please!!!! Tks!!

 Accepted Answer

Do you want to insert the same random signal at the start of each channel?
Signal = rand(256, 2840);
x = randn(1, 9) * 1.2;
Signal = [repmat(x, 256, 1), Signal];
Or a random signal, which is different for each channel?
Signal = [randn(256, 9) * 1.2, Signal];
[EDITED] Another approach:
x = rand(256, 2840); % Original signal
lenX = size(x, 2);
for i = 1:256
lenInsert = floor(rand * 10);
xInsert = randn(1, lenInsert);
x(i, :) = cat(2, xInsert, x(i, 1:lenX - lenInsert));
end

3 Comments

Sorry
i have a 256x2840 matrix, containing values of an eeg signal almost periodic and each coloumn (256 samples) contain each period.
I should introduce random values (for ex. 9 samples) with mean zero and standard deviation of 2 or 10ms at the beginning of each coloumn, that is at the beginning of each period of 256 samples.
The problem is that the aim is to introduce a change in the phase of the signal, so that each period (coloumn) of the signal are not anymore aligned.
Then i thought to variate the dimension of the rand vector.
I tried doing this, but i obtain a vector with all the coloumns, except the first, of zeros. can ypu explain me why? i can use the code that you wrote before as well for what i need now?
vent=256; %number of rows
n=2840; %number of coloumn
ds=1;
pot_ev2=zeros(vent, n);
dis=zeros(n,1);
dis(1)=1; %to realize the first disalignement (for the first %coloumn)
j=1; %index for the cloumns
for i=dis(1)+1:vent
pot_ev2(i,j) = pot_ev(i-dis(j)); %to shift the values
if i==vent;
j=j+1; %when arrives at the end of the coloumn, change coloumn and change the value of the disalignement (dis)
dis(j)=dis(j)+ds;
end
end
for j=1:n
for i=1:dis(j)
x=randn(dis(j),1); %defines a vector of random values, its dimension varies with the coloumn (+coloumn, +dimension, +disalignement)
pot_ev2(1:dis(j))=x(i)';
end
end
Sorry for the annoyance!! Thank you very much!
I'm still confused about the "2 or 10ms".
How is the length of the signal to be inserted defined?
See [EDITED] in my answer above.
What have you written in [EDITED] solve my problem, thank you very much! But i don't understand if xInsert changes its length depending on the index i, that is if lenInsert changes with i, or it's a fixed value. Because i would need a vector of random values whose length (1-9 samples is ok) is variable and changes, randomly, with i (for ex. for 1=1, lenInsert=5; for i=2, lenInsert=9; ...)

Sign in to comment.

More Answers (0)

Categories

Find more on Signal Processing in Help Center and File Exchange

Asked:

on 4 Dec 2011

Community Treasure Hunt

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

Start Hunting!