From: alkan alkaya on
How can I apply an adaptive threshold to signal (one dimension signal).
From: ImageAnalyst on
On Dec 19, 4:29 pm, "alkan alkaya" <alkanalk...(a)hotmail.com> wrote:
> How can I apply an adaptive threshold to signal (one dimension signal).
-----------------------------------------------------------------------------------------------------------
You can use a for loop to change the threshold as a function of index
number in the array. The threshold may vary depending on only the
index number (probably not likely), or it may vary depending on what
is in the signal in a window around the current index (the more common
situation).
From: alkan alkaya on
can you explain me clearly or give me an example please.

thanks..
From: ImageAnalyst on
% Demo for one arbitrary way to adaptively threshold a signal
% by ImageAnalyst
% IMPORTANT: Be sure to join any lines broken into two by the
newsreader.
clc;
close all;
clear all;
% Create sample data in the range 20-100
signalLength = 50;
signal = 100*rand(signalLength, 1) + 20;
subplot(2, 1, 1);
bar(signal);
% Set x axis to end at last bar.
set(gca,'xlim',[1 signalLength])
title('Original signal');
set(gcf, 'Position', get(0,'Screensize')) ; % Maximize figure window.

thresholdedSignal = signal;
windowWidth = 7;
halfWidth = floor(windowWidth/2);
% Do an adaptive threshold.
% As an example, this gives an output equal to the input
% if the signal is above the mean in a window.
% If the signal is below the mean it sets the output equal to 10;
% Totally arbitrary - you have to decide what you want to do.
thresholdValues = zeros(1, signalLength);
for index = (halfWidth + 1) : (signalLength - halfWidth)
leftIndex = index - halfWidth;
rightIndex = index + halfWidth;
signalWithinWindow = signal(leftIndex : rightIndex);
meanInWindow = mean(signalWithinWindow);
thresholdValues(index) = meanInWindow;
if signal(index) > meanInWindow
thresholdedSignal(index) = signal(index);
else
thresholdedSignal(index) = 10;
end
end
subplot(2, 1, 2);
bar(thresholdedSignal);
% Set x axis to end at last bar.
set(gca,'xlim',[1 signalLength])
hold on;
plot(thresholdValues, 'ro');
title('Example of one way to adaptively threshold a signal');
From: alkan alkaya on
thank you very much ImageAnalyst. I will try to use this program for my input signal. Have you got any other way to adaptively threshold a signal? and what is this methods name? again thank you very very much.


ImageAnalyst <imageanalyst(a)mailinator.com> wrote in message <c6fe1e95-489d-48d3-9fef-107228ee1362(a)j24g2000yqa.googlegroups.com>...
> % Demo for one arbitrary way to adaptively threshold a signal
> % by ImageAnalyst
> % IMPORTANT: Be sure to join any lines broken into two by the
> newsreader.
> clc;
> close all;
> clear all;
> % Create sample data in the range 20-100
> signalLength = 50;
> signal = 100*rand(signalLength, 1) + 20;
> subplot(2, 1, 1);
> bar(signal);
> % Set x axis to end at last bar.
> set(gca,'xlim',[1 signalLength])
> title('Original signal');
> set(gcf, 'Position', get(0,'Screensize')) ; % Maximize figure window.
>
> thresholdedSignal = signal;
> windowWidth = 7;
> halfWidth = floor(windowWidth/2);
> % Do an adaptive threshold.
> % As an example, this gives an output equal to the input
> % if the signal is above the mean in a window.
> % If the signal is below the mean it sets the output equal to 10;
> % Totally arbitrary - you have to decide what you want to do.
> thresholdValues = zeros(1, signalLength);
> for index = (halfWidth + 1) : (signalLength - halfWidth)
> leftIndex = index - halfWidth;
> rightIndex = index + halfWidth;
> signalWithinWindow = signal(leftIndex : rightIndex);
> meanInWindow = mean(signalWithinWindow);
> thresholdValues(index) = meanInWindow;
> if signal(index) > meanInWindow
> thresholdedSignal(index) = signal(index);
> else
> thresholdedSignal(index) = 10;
> end
> end
> subplot(2, 1, 2);
> bar(thresholdedSignal);
> % Set x axis to end at last bar.
> set(gca,'xlim',[1 signalLength])
> hold on;
> plot(thresholdValues, 'ro');
> title('Example of one way to adaptively threshold a signal');