Error message when using findpeaks for example code

조회 수: 4 (최근 30일)
joannnne
joannnne 2015년 3월 30일
댓글: amr atyia 2015년 11월 11일
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.
amr atyia
amr atyia 2015년 11월 11일
thanks alot star strider

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Descriptive Statistics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by