0

Can anyone help me with creating a function to apply two thresholds on received signals. These thresholds are then compared with the received power. The thresholds are w1 and w2, where w2>w1. I want this function to give me one of three answers. 0, 1, or X. 0 for the signal power below w1, 1 for the signal power to be above w2 and X for signal to be between w2 and w1.

I would be grateful for any help.

Thanks

om-nom-nom
  • 62,329
  • 13
  • 183
  • 228
  • 4
    In future please add code to show that you have tried to solve the problem yourself – Dan Apr 02 '13 at 12:31

1 Answers1

4
function outSignal = ApplyThreshold(inSignal, w1, w2)
    inSignal(inSignal > w2) = w2;
    inSignal(inSignal < w1) = w1;
    outSignal = inSignal;
end

example usage:

t = 1:0.1:10;
y = sin(t);
plot(t,y);
hold on
plot(t, ApplyThreshold(y, -0.5, 0.5), 'r-');

enter image description here

Dan
  • 45,079
  • 17
  • 88
  • 157