hello can some one help. I am to find peaks of accelrometer axis, for that am using the previously suggested code in this form,
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
if true
% code
I am trying the same code with my data and data file is attached.and getting errror in interp1. can somone help me to solve. Error using griddedInterpolant
The grid vectors must contain unique points.
Error in interp1 (line 158) F = griddedInterpolant(Xext,V,method);
endif true
% code
[d,s,r] = xlsread('New Microsoft Excel Worksheet.xlsx')
d(d==0)=NaN
d = d(:,1:4)
t = d(:,1)
t=datetime(time,'ConvertFrom', 'posixtime')
t=second(t)
[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]);
end
3 comentarios
Image Analyst
el 26 de Nov. de 2017
Why does the error not make sense to you? It's saying that you have duplicated points in your vectors.
This is the one way to solve your problem : http://blogs.mathworks.com/videos/2012/07/03/debugging-in-matlab/ since you've chosen not to upload your workbook. Even if you do upload your workbook, it's still the best path to solving this.
Respuestas (1)
Star Strider
el 26 de Nov. de 2017
You can create unique independent variable values from duplicated values by multiplying the duplicated-values vector by an increasing vector of very small values.
This works:
fudgefactor = cumsum(ones(size(d(:,1)))) * 1E-12;
di = interp1(d(:,1).*fudgefactor, d(:,2:4), t); % Interpolate Missing Values
I leave you to determine if it produces the result you want. (I only ran your code to the first interp1 call, since that threw the error.)
0 comentarios
Ver también
Categorías
Más información sobre Parametric Spectral Estimation en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!