필터 지우기
필터 지우기

How count pulse with matlab?

조회 수: 11 (최근 30일)
Jamal
Jamal 2016년 4월 7일
댓글: Image Analyst 2020년 5월 31일
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?
  댓글 수: 3
Jamal
Jamal 2016년 4월 7일
The sampling interval is 3.90625E-05 seconds.

댓글을 달려면 로그인하십시오.

답변 (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
SHANTANU KSHIRSAGAR 2020년 5월 31일
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);

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Smoothing and Denoising에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by