introduce new values into an array and shift the others

조회 수: 5 (최근 30일)
Sara
Sara 2011년 12월 4일
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!!

채택된 답변

Jan
Jan 2011년 12월 4일
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
Jan
Jan 2011년 12월 4일
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.
Sara
Sara 2011년 12월 5일
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; ...)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Signal Processing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by