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

6 ビュー (過去 30 日間)
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!

採用された回答

Mathieu NOE
Mathieu NOE 2022 年 9 月 7 日
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');
  2 件のコメント
Kuei-Yang Tseng
Kuei-Yang Tseng 2022 年 9 月 7 日
How brilliant way to solve it! I would never thought of it that way.
Thanks your reply!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMathematics についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by