How count pulse with matlab?

8 次查看(过去 30 天)
Jamal
Jamal 2016-4-7
I have the signal outputs from the rotary encoder. I'd like to count pulses using Matlab software. How can I count pulses? I attach the signal outputs. Would you please find the attachment files. Any codes? Any Solutions?

回答(1 个)

Image Analyst
Image Analyst 2016-4-7
Find the bottom envelope by using imerode() (in the Image Processing Toolbox). Then subtract the envelope from the signal. Then threshold and call bwlabel to count the pulses. Or you can use diff but it's more complicated.
bottomEnvelope = imerode(signal, true(1, windowWidth));
flattenedSignal = signal - bottomEnvelope;
hold on;
plot(flattenedSignal, 'r-');
binarySignal = flattenedSignal > 50;
plot(binarySignal, 'r-');
[~, numberOfPulses] = bwlabel(binarySignal);
  18 个评论
SHANTANU KSHIRSAGAR
the findchangepts is not working due to absence of signal processing toolox. Is there any way similarly robust.
Image Analyst
Image Analyst 2020-5-31
Find the first place where the signal exceeds 2.5 and then fall down the left side until it turns around.
% Initialization steps. Brute force cleanup of everything currently existing to start with a clean slate.
clc; % Clear the command window.
fprintf('Beginning to run %s.m ...\n', mfilename);
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
s = load('req4.mat')
x = s.x1;
y = s.z1;
subplot(2, 1, 1);
plot(x, y, 'b-', 'LineWidth', 2);
index = find(y > 2.5, 1, 'first');
hold on;
plot(x(index), y(index), 'r*', 'LineWidth', 2, 'MarkerSize', 15);
grid on;
% This finds a point on the upward slope. Fall down the slope until it starts to turn around again.
while y(index) > y(index - 1) && index >= 2
index = index - 1;
end
xline(x(index), 'Color', 'r', 'LineWidth', 2);
caption = sprintf('Original Signal with %d elements. Start crop at index = %d, x = %f', length(x), index, x(index));
fontSize = 20;
title(caption, 'FontSize', fontSize);
xlabel('x1', 'FontSize', fontSize);
ylabel('z1', 'FontSize', fontSize);
% Extract just the part to the right of the index (red line).
x2 = x(index : end);
y2 = y(index : end);
subplot(2, 1, 2);
plot(x2, y2, 'b-', 'LineWidth', 2);
grid on;
xlim([min(x2), max(x2)]);
xlabel('x1', 'FontSize', fontSize);
ylabel('z1', 'FontSize', fontSize);
g = gcf;
g.WindowState = 'maximized';
caption = sprintf('Cropped Signal with %d elements.', length(x2));
title(caption, 'FontSize', fontSize);

请先登录,再进行评论。

Community Treasure Hunt

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

Start Hunting!

Translated by