Error message when using findpeaks for example code

2 views (last 30 days)
I am using findpeaks to detect peaks on accelerometer data. I need the x value (time) of the peak to work out latency. I can't get this to work though.
I get the following error:
??? Error using ==> uddpvparse at 119
Invalid Parameter/Value pairs.
Error in ==> findpeaks>parse_inputs at 69
hopts = uddpvparse('dspopts.findpeaks',varargin{:});
Error in ==> findpeaks at 43
[X,Ph,Pd,Th,Np,Str,infIdx] = parse_inputs(X,varargin{:});
I have tried this with the code given as an example in (<http://www.mathworks.com/matlabcentral/answers/158309-how-to-find-the-peaks-both-x-and-y-location) this> thread and I get this error also.
I am loading a csv file of data and trying to find peaks and time to compare two data sets.
I am using r2011a student
Thanks,
Joe
  4 Comments
joannnne
joannnne on 31 Mar 2015
Edited: joannnne on 31 Mar 2015
Hey sorry, been offline. I don't seem to be getting notifications for replies. Will format properly in future! Not sure what happened with csv, here it is.
Thank for your quick responses and sorry to not have seen them sooner.
Star Strider
Star Strider on 31 Mar 2015
What units are time (column #1) in?
I’ll assume seconds for now.

Sign in to comment.

Accepted Answer

Star Strider
Star Strider on 31 Mar 2015
This proved to be something of an adventure. I suspect findpeaks choked because there are NaN values in your data, so the first thing I did was to delete them and then do a linear interpolation to replace those values. Since ‘real world’ data are usually noisy, I filtered your data to remove some of the noise. (It isn’t necessary for you to include the fft part of the code in the code you use, since I only used it to design the filter.) I tested findpeaks and it now works with your data.
The code:
[d,s,r] = xlsread('lra_test.csv');
d = d(:,1:4);
t = d(:,1);
[dnanr,~] = find(isnan(d(:,2:4)));
d(dnanr,:) = []; % Delete NaN Rows
di = interp1(d(:,1), d(:,2:4), t); % Interpolate Missing Values
ftd = fft(di)/size(di,1); % Use ‘fft’ To Design Filter
ftd(1,:) = 0;
ftda = abs(ftd);
Ts = mean(diff(t));
Fs = 1/Ts;
Fn = Fs/2;
Fv = linspace(0, 1, size(d,1)/2+1)*Fn;
Ix = 1:length(Fv);
Wp = [0.005 0.015]/Fn; % Design Filter
Ws = [0.001 0.018]/Fn;
Rp = 1;
Rs = 10;
[n,Wn] = buttord(Wp, Ws, Rp, Rs);
[b,a] = butter(n,Wn);
[sos,g] = tf2sos(b,a);
df = filtfilt(sos, g, di); % Filter Data
[pka1,pki1] = findpeaks(df(:,1), 'MinPeakDistance',100);
[pka2,pki2] = findpeaks(df(:,2), 'MinPeakDistance',100);
[pka3,pki3] = findpeaks(df(:,3), 'MinPeakDistance',100);
figure(1) % Plot Filtered Data & Peaks
subplot(3,1,1)
plot(t, df(:,1))
hold on
plot(t(pki1),df(pki1,1),'r^')
hold off
grid
subplot(3,1,2)
plot(t, df(:,2))
hold on
plot(t(pki2),df(pki2,2),'r^')
hold off
grid
subplot(3,1,3)
plot(t, df(:,3))
hold on
plot(t(pki3),df(pki3,3),'r^')
hold off
grid
figure(2) % Plot FFT
plot(Fv, ftda(Ix,:))
grid
set(gca, 'XLim',[0.0 0.05]);
  3 Comments
Star Strider
Star Strider on 8 Apr 2015
My pleasure!
The code is fairly straightforward, but if you would like a more detailed explanation, I will provide it.
If my Answer solved your problem, please Accept it.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!