shg
hold on
grid on
plot(u)
shg
legend({'output y','input u'},'location',#best')
legend({'output y','input u'},'location',#best')
{Error: The input character is not valid in MATLAB statements or expressions.
}
legend({'output y','input u'},'location','best')
shg
xlabel('sample number')
ylabel('distance mm')
shg
title('response of xp10d10')
shg
dord2
ans =
0 0.0308 0.0211
help dord2
[num,den]=dord2(wn,z,T) - see assignment
Generate second order system sampled at T and with natural
frequency Wn and damping factor Z.
[A,B,C,D] = dord2(Wn, Z) returns the A,B,C,D representation of the
sampled second order system.
For a demo run dord without return arguments.
[num,den]=dord2
num =
0 0.0408 0.0384
den =
1.0000 -1.4089 0.8375
help filter
filter One-dimensional digital filter.
Y = filter(B,A,X) filters the data in vector X with the
filter described by vectors A and B to create the filtered
data Y. The filter is a "Direct Form II Transposed"
implementation of the standard difference equation:
a(1)*y(n) = b(1)*x(n) + b(2)*x(n-1) + ... + b(nb+1)*x(n-nb)
- a(2)*y(n-1) - ... - a(na+1)*y(n-na)
If a(1) is not equal to 1, filter normalizes the filter
coefficients by a(1).
filter always operates along the first non-singleton dimension,
namely dimension 1 for column vectors and non-trivial matrices,
and dimension 2 for row vectors.
[Y,Zf] = filter(B,A,X,Zi) gives access to initial and final
conditions, Zi and Zf, of the delays. Zi is a vector of length
MAX(LENGTH(A),LENGTH(B))-1, or an array with the leading dimension
of size MAX(LENGTH(A),LENGTH(B))-1 and with remaining dimensions
matching those of X.
filter(B,A,X,[],DIM) or filter(B,A,X,Zi,DIM) operates along the
dimension DIM.
Tip: If you have the Signal Processing Toolbox, you can design a
filter, D, using DESIGNFILT. Then you can use Y = filter(D,X) to
filter your data.
See also filter2, filtfilt, filtic, designfilt.
Note: FILTFILT, FILTIC and DESIGNFILT are in the Signal Processing
Toolbox.
Reference page for filter
Other functions named filter
u=rand(50,1)-.5;
hold off
plot(u);shg
y=filter(num,den,u);
hold on
plot(y)
shg
us=ones(50,1);
plot(fliter(num,den,us));shg
{Undefined function or variable 'fliter'.
}
plot(filter(num,den,us));shg
num
num =
0 0.0408 0.0384
den
den =
1.0000 -1.4089 0.8375
phi=[ -[0;y(1:end-1)] ];
y(1:4)
ans =
0
0.0054
-0.0037
-0.0343
phi(1:4)
ans =
0
0
-0.0054
0.0037
phi=[ -[0;y(1:end-1)] -[0;0;y];
phi=[ -[0;y(1:end-1)] -[0;0;y]];
{Error using horzcat
Dimensions of matrices being concatenated are not consistent.
}
phi=[ -[0;y(1:end-1)] -[0;0;y(1:end-2)]];
phi=[ -[0;y(1:end-1)] -[0;0;y(1:end-2)] [0;u(1:end-1)] [0;0;u(1:end-2)]];
whos
Name Size Bytes Class Attributes
ans 4x1 32 double
den 1x3 24 double
fname 1x7 14 char
num 1x3 24 double
phi 50x4 1600 double
ry 624x2 9984 double
u 50x1 400 double
us 50x1 400 double
xhurl 1x76 152 char
xp10d01 624x2 9984 double
y 50x1 400 double
num
num =
0 0.0408 0.0384
den
den =
1.0000 -1.4089 0.8375
(phi'*phi)\phi'*y
ans =
-1.4089
0.8375
0.0408
0.0384
phi=[ -[0;y(1:end-1)] [0;u(1:end-1)] [0;0;u(1:end-2)]];
theta=(phi'*phi)\phi'*y
theta =
-0.7280
0.0324
0.0628
num
num =
0 0.0408 0.0384
den
den =
1.0000 -1.4089 0.8375
stem(y)
shg
hold off
stem(y)
shg
yfit=filter([0 theta(2) theta(3),[1 theta(1),u);
yfit=filter([0 theta(2) theta(3),[1 theta(1),u);
{Error: Unbalanced or unexpected parenthesis or bracket.
}
yfit=filter([0 theta(2) theta(3),[1 theta(1)],u);
yfit=filter([0 theta(2) theta(3),[1 theta(1)],u);
{Error: Unbalanced or unexpected parenthesis or bracket.
}
yfit=filter([0 theta(2) theta(3)],[1 theta(1)],u]);
yfit=filter([0 theta(2) theta(3)],[1 theta(1)],u]);
{Error: Unbalanced or unexpected parenthesis or bracket.
}
yfit=filter([0 theta(2) theta(3)],[1 theta(1)],u);
hold on
stem(yfit)
shg
hold off
plot(y);hold on;plot(yfit);
shg
phi=[ -[0;y(1:end-1)] -[0;0;y(1:end-2)] [0;u(1:end-1)] [0;0;u(1:end-2)]];
phi=[ -[0;y(1:end-1)] -[0;0;y(1:end-2)] -[0;0;0;y(1:end-3)[0;u(1:end-1)] [0;0;u(1:end-2)]];
phi=[ -[0;y(1:end-1)] -[0;0;y(1:end-2)] -[0;0;0;y(1:end-3)[0;u(1:end-1)] [0;0;u(1:end-2)]];
{Error: Unbalanced or unexpected parenthesis or bracket.
}
phi=[ -[0;y(1:end-1)] -[0;0;y(1:end-2)] -[0;0;0;y(1:end-3)][0;u(1:end-1)] [0;0;u(1:end-2)]];
phi=[ -[0;y(1:end-1)] -[0;0;y(1:end-2)] -[0;0;0;y(1:end-3)][0;u(1:end-1)] [0;0;u(1:end-2)]];
{Error: Unbalanced or unexpected parenthesis or bracket.
}
phi=[ -[0;y(1:end-1)] -[0;0;y(1:end-2)] -[0;0;0;y(1:end-3)] [0;u(1:end-1)] [0;0;u(1:end-2)]];
theta=(phi'*phi)\phi'*y
theta =
-1.4089
0.8375
-0.0000
0.0408
0.0384
num
num =
0 0.0408 0.0384
den
den =
1.0000 -1.4089 0.8375
ynoise=y+randn(size(y));
hold off
plot(y);hold on;plot(ynoise)
shg
ynoise=y+0.1*randn(size(y));
hold off
plot(y);hold on;plot(ynoise)
shg
phi=[ -[0;ynoise(1:end-1)] -[0;0;ynoise(1:end-2)] [0;u(1:end-1)] [0;0;u(1:end-2)]];
theta=(phi'*phi)\phi'*ynoise
theta =
-0.2048
-0.0875
0.0641
0.0474
num
num =
0 0.0408 0.0384
den
den =
1.0000 -1.4089 0.8375
hold off
yfit=filter([0 theta(2) theta(3)],[1 theta(1) theta(2)],u);
plot(y);hold on;plot(yfit);shg
ynoise=y+0.01*randn(size(y));
phi=[ -[0;ynoise(1:end-1)] -[0;0;ynoise(1:end-2)] [0;u(1:end-1)] [0;0;u(1:end-2)]];
theta=(phi'*phi)\phi'*ynoise
theta =
-1.2832
0.7280
0.0294
0.0502
plot(yfit);shg
num
num =
0 0.0408 0.0384
den
den =
1.0000 -1.4089 0.8375
yfit=filter([0 theta(2) theta(3)],[1 theta(1) theta(2)],u);
plot(yfit);shg
e
{Undefined function or variable 'e'.
}
num
num =
0 0.0408 0.0384
den
den =
1.0000 -1.4089 0.8375
theta
theta =
-1.2832
0.7280
0.0294
0.0502
yfit=filter([0 theta(3) theta(4)],[1 theta(1) theta(2)],u);
hold off
plot(y)
hold on
plot(yfit)
shg
diary off