Adding a Vector at Certain Points of a Sequence

4 Ansichten (letzte 30 Tage)
Troy Handlovic
Troy Handlovic am 6 Jul. 2022
Bearbeitet: Jan am 6 Jul. 2022

I am trying to simulate an expirnment, where a signal (gaussian peak) is added to itself in accordance to a random binary sequence. I have already generated the binary sequence, but need assistance with the addtion of the signal to itself.
Details:
Binary sequence is 0 or 1 at a 50% probablity.
The gaussian peak is generate by normpdf with a total x value of 1000.
When the binary sequence is at 1, I would like for the gaussian peak to be added to the original and when the binary sequence is at 0 nothing happens. This means that the sequence's start point would be offset by the location of the 1. So, if the 1 is the at location 100 of the sequence, the gaussian peak would have to start 100 points ahead of the orginal.
The signals need to be added to eachother sequentially. This means the third 1 value must be added to a signal that already has the first two 1 values summed into it.

  4 Kommentare
Walter Roberson
Walter Roberson am 6 Jul. 2022
Sure. But first you need to define how big you want the result to be. If you have a signal of length 1000 and you delay it by 100 points, do you want the first 100 points to be 0, then the next 1000 are the data, for a total of 1100 points? And if you had a second delay of (say) 150, then should it look like
zeros, length 100 (first delay)
first 50 of signal
signal position 51 to 1000, PLUS signal position 1 to 950 (both delays are in effect)
signal position 951 to 1000 (first delay has worn off, second is not finished yet)
for a total of 100 + 50 + 950 + 50 = 1150 ?
Troy Handlovic
Troy Handlovic am 6 Jul. 2022
Thanks for the help.
I essentially want to add 0s to the original sequence to offset its stating point according to the random binary sequence and then sum all of the offset signals up. Here is a small example but I would like to do this on the scale of thousands of points with a more complicated signal. The final output should be 2x the original minus 1.
Sequence:
1010011001
Signal:
0001210000
Output
0001210000 first 1, original signal
000001210000 second 1
000000001210000 third 1
0000000001210000 fourth 1
0000000000001210000 fifth 1
Then sum them up for an output of
0001222113311210000

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Jan
Jan am 6 Jul. 2022
Bearbeitet: Jan am 6 Jul. 2022
seq = [1 0 1 0 0 1 1 0 0 1];
signal = [0 0 0 1 2 1 0 0 0 0];
seq = randi([0,1], 1, 1e5);
signal = randi([0, 10], 1, 1e2)
signal = 1×100
10 4 4 9 10 2 0 4 8 8 3 6 5 8 2 6 1 7 0 6 6 6 10 7 7 10 3 2 6 2
w = numel(signal);
q = find(seq);
result = zeros(1, q(end) + w - 1);
for k = 1:numel(q)
p = q(k);
result(p:p+w-1) = result(p:p+w-1) + signal;
end
Walter has mentioned CONV:
result2 = conv(seq, signal); % Size is: numel(seq)+numel(signal)-1
result2 = result2(1:find(seq, 1, 'last') + w - 1); % Crop trailing non-signal
isequal(result, result2)
ans = logical
1

Kategorien

Mehr zu Signal Generation and Preprocessing finden Sie in Help Center und File Exchange

Produkte


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by