Automatically normalize a range of data into specific values.
2 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
采纳的回答
Vivek Selvam
2013-10-14
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 个)
Image Analyst
2013-10-14
Try imquantize() in the Image Processing Toolbox - it's meant for this purpose.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Clocks and Timers 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!