## Peak Detection in ICP signal

1. The problem statement, all variables and given/known data

I have the task of finding the first peak (percussion peak) per each period of a ICP signal. I was told to filter the signal to get rid of some noise and a dc offset, find the percussion peak indicies and then plot those back onto the original signal. I am unable to only plot the first peak, my code plots both peaks. I am not sure why my code is not differentiating between the indicies of relavence. Any help with the code below would help,

2. Relevant equations

3. The attempt at a solution
clc; close all;

x = icpcomposite;
k = 1:length(x);

%% filtering

b = fir1(200,30/(fs/2));
y1 = filtfilt(b,1,x);

%% Detrending

b = fir1(300,0.5/(fs/2),'high');
y2 = filtfilt(b,1,y1);

figure;
plot(y2);

%% Peak Detection

L = 1:length(y2);
[ymax,imax] = extrema(y2);
figure;
plot(L,y2,L(imax),ymax,'r.');

%% Error Correction

imd = diff(imax);
imdm = median(imd);

mdt = 0.5*imdm;
mdind = find(imdm<mdt);

mdind = mdind+1;
imax(mdind) = 0;
imax = unique(imax);

figure;
plot(k,x,imax,x(imax),'r.');
Attached Files
 extrema.m (3.6 KB, 3 views)
 PhysOrg.com science news on PhysOrg.com >> King Richard III found in 'untidy lozenge-shaped grave'>> Google Drive sports new view and scan enhancements>> Researcher admits mistakes in stem cell study