How can I detect a peak signal inside a periodic pulse array and generate the waveform like the figure below?

8 views (last 30 days)
array_pulse = [0,0,0,0,1,1,1,1,0,0,0,0,1,1,1,1,0,0,0,0,1,1,1,1,0,0,0]
array_signal = [0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,1,0,1,0,0,0,0,0,0,1,0,0]
expect_Out = [0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0]
Hello! Guys!
I need help generate the output waveform like the figure above.
I have two array, one is the periodic pulse modulation and the other is the detected signal peak.
When the peak is generated and inside the pulse width at high (which is 1) the output then go high until the falling edge of the pulse array. But when the peak is generated outside the pulse width (like the second peak) then it is 0. And when there is no signal peak inside the pulse width then it all goes 0.
I have thought about it all night. Hope someone can help me process these array! Thank you very much!

Accepted Answer

Mathieu NOE
Mathieu NOE on 7 Sep 2022
hello
here you are - hope you will sleep better tonight...
array_pulse = [0,0,0,0,1,1,1,1,0,0,0,0,1,1,1,1,0,0,0,0,1,1,1,1,0,0,0];
array_signal = [0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,1,0,1,0,0,0,0,0,0,1,0,0];
expect_Out = zeros(size(array_pulse));
% init
t = 0:numel(array_pulse)-1;
status = 0;
% first sample code
if array_signal(1)>0.5 && array_pulse(1)>0.5
status = 1;
end
if array_signal(1) - 0 <-0.5
status = 0;
end
expect_Out(1) = status;
% second up to last sample code
for ci = 2:numel(array_pulse)
if array_signal(ci)>0.5 && array_pulse(ci)> 0.5
status = 1;
end
if array_pulse(ci) - array_pulse(ci-1) < -0.5
ci
status = 0;
end
expect_Out(ci) = status;
end
figure(1);
subplot(311),plot(t,array_pulse,'b');
subplot(312),plot(t,array_signal,'r');
subplot(313),plot(t,expect_Out,'g');

More Answers (0)

Community Treasure Hunt

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

Start Hunting!