Sensors & signal processing _261111_134518.pdf
https://www.youtube.com/watch?v=blnnAEmVXp0
https://www.youtube.com/watch?v=CGpG_Ctfagk&t=9s
https://www.youtube.com/watch?v=-hOsdEH6YZw
https://www.youtube.com/watch?v=wn1UCt9Z6NQ
https://www.youtube.com/watch?v=zzHcsJDV3_o
https://www.youtube.com/watch?v=yOmYCh_i_JI
https://www.youtube.com/watch?v=eqZgxR6eRjo
clear all
close all
clc
%System parameter
M= 1e-6; C=3e-6; K=6e-5;
A = [0 1;-K/M -C/M];
B = [0;-1];
%Initialization
X=[0;0];
%Numerical Simulation parameter
dt=0.001;
t=0:dt:10;
X_k=zeros(2,length(t));
y_k=zeros(1,length(t));
z_k=zeros(1,length(t));
X_k(:,1)=X; y_k(1)=X(1);z_k(1)=0;
a_fk=zeros(1,length(t));
a_bk=zeros(1,length(t));
a_bk(1)=1;
for k=1:length(t)-1
y = X(1); % output update
a_b = a_bk(k);
X=X+(A*X+B*a_b)*dt;
X_k(:,k+1) = X;
y_k(k+1) = X(1) + 0.01*randn(1);
%% LPF
alpha=0.1;
z_k(k+1)=(1-alpha)*z_k(k)+alpha*y_k(k+1);
a_fk(k+1)=-K/M*z_k(k+1);
a_bk(k+1) = 4*cos(0.2*pi*t(k+1));
end
figure
plot(t,-K/M*y_k,'g--','LineWidth',2);hold on
plot(t,a_fk,'m:','LineWidth',2);hold on
plot(t,a_bk,'r-','LineWidth',2);
ylabel('acceleration $[m/s^2]$','Interpreter','latex');
xlabel('time $[s]$','Interpreter','latex');
legend('Unfiltered', 'Filtered', 'True', 'Location', 'northeast','Orientation','horizontal');
set(gca,'fontsize',14,'fontname','Times')
grid on
grid minor