Error message when using findpeaks for example code

4 次查看(过去 30 天)
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 个评论
joannnne
joannnne 2015-3-31
编辑:joannnne 2015-3-31
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 2015-3-31
What units are time (column #1) in?
I’ll assume seconds for now.

请先登录,再进行评论。

采纳的回答

Star Strider
Star Strider 2015-3-31
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 个评论
Star Strider
Star Strider 2015-4-8
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.

请先登录,再进行评论。

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by