Automatically normalize a range of data into specific values.
조회 수: 1 (최근 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에서 Spreadsheets에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!