Filter noise in logical vector

1 visualización (últimos 30 días)
Randy Kwa
Randy Kwa el 23 de En. de 2020
Editada: Agustin Canalis el 15 de Mayo de 2021
I have a logical vector that is meant to run over time (ms). It looks like this:
0000000000000110000000000001111111111111111111111111111111111111100000000000000000001000000000
'Time in ms--->'
In this example I only want a signal that ran 'true' longer then 3ms. The rest I want filtered back to zero's becuase I still need to plot it against time.
How should I do this?

Respuestas (2)

KALYAN ACHARJYA
KALYAN ACHARJYA el 23 de En. de 2020
Do Modification: Just Hint here (May Be)
loop
data_generation(i)=present_data;
if present_data==1
tic
while toc==
end
end

Agustin Canalis
Agustin Canalis el 15 de Mayo de 2021
Editada: Agustin Canalis el 15 de Mayo de 2021
An interesting choice is to use movmin and movmax, which work along a sliding window in your vector:
A = [0 0 0 0 1 1 0 0 0 0 0 1 1 1 1 1 1 1 1 1 0 0 1 1 1 1 1 1 1 0 0 1 0 1 0 0]
window_size = 3 % or scale to your needs
B = movmin(A,window_size)
C = movmax(B,window_size)
imshow([A;B;C]) % This is just to graph the result
Here's the result:
The idea is that movmin "triggers" when the sliding window contains 3 consecutive 1's, otherwise the minimum is 0.
However, this also clips useful portions of your signal at the start and end, which is why I have to use movmax to add them back.
Because it's vectorized I guess the performance is better than in a loop, but I haven't tested it.
Cheers!

Categorías

Más información sobre Matched Filter and Ambiguity Function en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by