Get the number of pulses from data set

1 visualizzazione (ultimi 30 giorni)
Lalmi Ahmed
Lalmi Ahmed il 3 Apr 2021
Risposto: Image Analyst il 27 Mag 2022
i have a set of data in xlsx file
it containes about 500 row and 3 column i want to get the number of pulses for each vector (column).
here is my draft, i was trying to count the number of values colser to the center(100)
clc
D = xlsread('newData.xlsx');
size(D)
T = D(:,1);
V = D(:,2);
I = D(:,3);
plot(T,V,T,I);
p= 0;
r = 100;
first = false;
for j = 1:length(V)-1 % loop through the vector V
if abs(V(j)-100) < 10 % if the difference between the value and 100 (horizonal center) is less than 10
if first == false
t = j; % t is the first time when we got point close to the center
p = 1;
first = true;
endif
if first == true
if j-t > 0.2 % if we find another point it sould be a bit far from the previous one
t = j;
p = p +1;
endif
endif
endif
endfor
disp('the number of pulses is ')
disp(p);
i think this is not a good way to do it so if you have any suggestion please help.
  1 Commento
dpb
dpb il 4 Apr 2021
Have you tried findpeaks with a discrimination level and, possibly, a distance requirement?

Accedi per commentare.

Risposte (1)

Image Analyst
Image Analyst il 27 Mag 2022
Try this:
%============================================================================================================================================
% Demo by Image Analyst to count pulses
% Initialization Steps.
clc; % Clear the command window.
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;
data = readmatrix('newData.xlsx');
x = data(:, 1); % X is the first column.
data = data(:, 2:end); % Y are the other columns.
[rows, columns] = size(data)
for col = 1 : columns
% Get this signal.
thisColumn = data(:, col);
% Plot it.
subplot(columns, 1, col);
plot(thisColumn, 'b-');
grid on;
% Get a threshold.
threshold = mean(thisColumn);
yline(threshold, 'Color','r', 'LineWidth', 2)
% Count pulses
binarySignal = thisColumn > threshold;
[~, numPulses] = bwlabel(binarySignal);
caption = sprintf('%d Pulses', numPulses);
title(caption, 'FontSize',fontSize)
end

Categorie

Scopri di più su Scope Variables and Generate Names in Help Center e File Exchange

Prodotti


Release

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by