Automatically normalize a range of data into specific values.

1 view (last 30 days)
The system I am working with collects brightness data from a LED that uses three brightness levels to encode binary data along with a clock. The data range is 0 - 255. My intention is extract binary values (along with the clock value) from this range automatically; is it possible to do so?
Example raw brightness data:
[20, 253, 253, 108, 109, 254, 253, 254, 17, 19, 253, 253]
Example working code:
% Normalize raw luminous intensity values into a binary and clock
% representation. (zeros, ones, and twos)
% Note: Equation parameters found through observation.
disp('Normalize data into zeros, ones, twos')
for i = 1:length(raw_data)
if raw_data(i) < 50
normalized_data(i) = 0;
end
if (raw_data(i) > 50) && (raw_data(i) < 200)
normalized_data(i) = 1;
end
if raw_data(i) > 200
normalized_data(i) = 2;
end
end
disp (normalized_data)
Output:
[0, 2, 2, 1, 1, 2, 2, 2, 0, 0, 2, 2]
Is there a way to decide the equation parameters programmatically? Currently, I am bringing up a graph of the raw_data and through observation I am deciding the range where the zeros, ones, and twos should fall.
edit
I should note that lows, mediums, and highs of the raw data vary depending on external conditions and leaving constants as parameters may cause problems in a finalized system.
Thank you.

Accepted Answer

Vivek Selvam
Vivek Selvam on 14 Oct 2013
Yes, it is possible using hist for finding the low, medium and high ranges. I have used your code as a function to calculate the normalized data based on the ranges. It can be optimized using vectoring and logical indexing.
function normalized_data = autoNormalize(raw_data)
% Note: Equation parameters found through histogram binning.
brightnessLevels = 3;
% get number of elements and center of each level
[numElements,centers] = hist(raw_data,brightnessLevels);
% plot a bar graph - to view what happened
bar(centers,numElements)
% compute level edges
width = diff(centers);
edges = centers(1:end-1) + width/2;
% call normalizeMe to classify
normalized_data = normalizeMe(raw_data,edges);
end
function normalized_data = normalizeMe(raw_data,edges)
% Normalize raw luminous intensity values into a binary and clock
% representation. (zeros, ones, and twos)
disp('Normalize data into zeros, ones, twos')
for i = 1:length(raw_data)
% modified from < to <= to take care of edge cases
if raw_data(i) <= edges(1)
normalized_data(i) = 0;
end
% similar modification
if (raw_data(i) > edges(1)) && (raw_data(i) <= edges(2))
normalized_data(i) = 1;
end
if raw_data(i) > edges(2)
normalized_data(i) = 2;
end
end
disp(normalized_data)
end
  1 Comment
Reuben
Reuben on 19 Oct 2013
Thank you very much, the code works excellent! I am going to take the time and look deeper to why the code works. =)

Sign in to comment.

More Answers (1)

Image Analyst
Image Analyst on 14 Oct 2013
Try imquantize() in the Image Processing Toolbox - it's meant for this purpose.

Community Treasure Hunt

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

Start Hunting!