How to use filter correctly for vector data?
17 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello, I would like to ask to this: I have data from txt file and I want to plot them, do the first and second derivatives. Because it's vector data so I used filter, but it isn't solve my problem. For example: One part of data(original plot) has a quadratic function characteristic and after the first and second derivatives it isnt true (1. linear and 2. constant), there is again, the non-smooth curve.

It's possible that I use filter wrong or on the wrong place?
dt = 0.000039;
windowSize = 100;
pocatecni_t = 22.672;
koncove_t = 22.736;
fileID = fopen('blabla.txt','r');
s = textscan(fileID,'%f %f','HeaderLines','2');
fclose(fileID); %scan
y1 = s{1}*10 %1. laser
y2 = s{2}*10 %2. laser
t = transpose(0:dt:dt*(length(s{1})-1));
rozsah = (t > pocatecni_t & t < koncove_t);
%filter
velikost_okna = 10
b = (1/velikost_okna)*ones(1,velikost_okna);
a = 1;
yy1 = filter(b,a,y1);
yy2 = filter(b,a,y2);
%derivatives
dy1 = diff(yy1);
dy2 = diff(yy2);
t1 = t(2:end) %x
d11 = dy1/(1e3) %y1
d12 = dy2/(1e3) %y2
ddy1 = diff(dy1);
ddy2 = diff(dy2);
t2 = t(3:end) %x
d21 = ddy1/(1e3) %y1
d22 = ddy2/(1e3) %y2
%PLOTS
graf = figure;
%graf_posuvů_po_celé_délce
subplot(4,1,1);
plot(t,y1);
title('Hodnoty rychlosti a zrychleni z namerenych posuvu lasery')
xlabel('cas [t]')
ylabel('posuv [mm]')
subplot(4,1,2);
plot(t(rozsah),yy1(rozsah));
xlabel('cas [t]')
ylabel('posuv [mm]')
subplot(4,1,3);
plot(t1(rozsah), d11(rozsah),'r');
xlabel('cas [t]')
ylabel('rychlost [m/s]')
subplot(4,1,4);
plot(t2(rozsah), d21(rozsah),'g');
xlabel('cas [t]')
ylabel('zrychleni [m/s^2]')
0 Kommentare
Antworten (0)
Siehe auch
Kategorien
Mehr zu Interpolation finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!