Why does my matlab code cannot detect the number of periods in a specific time range

4 次查看(过去 30 天)
I have developed a matlab code which imports pNRF Files that contain a measurement signal of light distance of a wheel surface in order to detect the number of cracks on that surface. There are in the file 3 signals, 2 rotary encoder signals and one light distance signal.
The Code does mostly what I want it to do:
  1. It can import the Data accurately and successfully.
  2. It can plot all the 3 signals
  3. It can detect the cracks automatically using a threshold
One thing thats important and that the code is doing wrong, is that it detects the wrong number of the periods in the time range where a crack is being detected. (See the following picture, the back rectangles are the Cracks detected).
Now what I would like to do is to calculate the number of the Periods on the Signal Ch B1 (increment Encoder A) in the time where a crack is being detected. In this example the number of the periods is about 5,2 Periods of the first Crack and about nearly 1 Period of the second crack.
This is a substract of the 200line Code that i have to determine how many cracks I have:
% Zusammenfassung der Risse anzeigen
disp('Anzahl der detektierten Risse:');
disp(numCracks);
disp('Breite der detektierten Risse in Inkrementen und Mikrometern:');
for i = 1:numCracks
rissIndizes = risseGruppen.PixelIdxList{i};
Crackstart = min(rissIndizes);
Crackend = max(rissIndizes);
Periods_Yellow_Signal = locs_gelb(locs_gelb >= Crackstart & locs_gelb <= Crackend);
CracksthicknessinPeriods = length(Periods_Yellow_Signal);
rissBreiteMicrometer = CracksthicknessinPeriods * INC_TO_MICROMETER;
fprintf('Crack %d: Thickness = %d Periods, %.2f Micrometer (Signal: Ch B1_A)\n', i, rissBreiteInkrement, rissBreiteMicrometer);
fprintf('Number of Periods: %d\n', rissBreiteInkrement);
end
What am I doing wrong here?
I would so thankful for any help! Thanks a lot in advance.
  2 个评论
Ramo
Ramo 2024-6-9
Hi @Voss, I just sent you the complete Code as a message, but feel free to answer here. The only necessary data that I upload into the Code is the .pNRF File which contains the measured signals, but I unfortunately cannot upload it here due to its data typ..

请先登录,再进行评论。

回答(1 个)

Image Analyst
Image Analyst 2024-6-10
Is locs_gelb the yellow signal? It looks like you've already determined how many cracks you have and your loop simply inspects each crack one at a time and gets the number of elements in the crack. The CracksthicknessinPeriods should be indexed by (i) otherwise you're just overwriting each crack length.
CracksthicknessinPeriods(i) = numel(Periods_Yellow_Signal);
Then after the loop you can do
totalCrackLength = sum(CracksthicknessinPeriods)
However you can also get that without doing the loop at all (if you're not interested in individual crack lengths) just by summing your threshold criteria
totalCrackLength = sum(locs_gelb > yourThreshold)
If you have any more questions, then attach your data and code to read it in with the paperclip icon after you read this:

类别

Help CenterFile Exchange 中查找有关 Get Started with MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by