How can we threshold a signal in both positive and negative sides?
8 views (last 30 days)
I have a signal with values in both positive and negative sides. I want to threshold in both sides. I have used this code:
if signal>threshold && -signal>0.5
But I got signal with only positive side. Can anyone help me with thresholding at both sides?
Star Strider on 16 Sep 2022
I am not certain what you want as the result.
The for loop and if block are not necessary. You can do this with logical indexing. The logical indexing here are:
(signal_new >= threshold)
(signal_new <= -threshold)
Try this —
Fs = 256;
t = linspace(0, 1000, 1001)/Fs;
signal = sin(2*pi*t*2);
threshold = 0.5;
signal_new = signal;
signal_new(signal_new >= threshold) = threshold;
signal_new(signal_new <= -threshold) = -threshold;