View
9
Download
0
Category
Preview:
Citation preview
PROJECT REPORT
(Project Semester May – August 2012)
ENHANCING RESULTS ON KALMAN FILTER
Submitted by
Vijit Dubey
Department of Electrical Engineering
Punjab Engineering College, Chandigarh
India
Under the Guidance of
Dr. Jeffrey Burl
Associate Professor, Electrical and Computer Engineering
Michigan Technological University
Houghton, Michigan
USA
ACKNOWLEDGEMENT
It has been an enriching experience for me to undertake a Project at Michigan Technological
University, Houghton. At the outset I would like to express my gratitude to my mentor Dr. Jeffrey
B. Burl, who assigned me this project after assessing my aptitude in this particular field and spent
his valuable time in giving inputs related to the project and clearing my doubts on the same.
There are some people without whom the completion of this Project was not possible. I would like
to express my deep regards to Dr. Dennis for wise inputs and the time he spared for discussions. I
would also like to thank the entire faculty of Electrical Engineering Department for giving their
valuable time to my Project.
Introduction
Some basic topics were covered during the internship project. Initially weeks we had a run though
of basic concepts of MATLAB. Plotting basic functions was learnt. Many other examples were
covered to get a basic idea of functionality of topics to be covered in the reviewing of the thesis.
Some of the examples covered are discussed below.
Plotting a sine wave
Plotting a cosine wave with amplitude at specific points
Plotting a composite wave
Plotting a Magnitude vs Frequency graph
MATLAB code:
clear % Equation for filter: y(k) =.65*sin(k)+.65*sin(k-1)+.65*sin(k-
2)+..+.65*sin(k-15) s=16; kt=zeros(s); fr=60; T=1/s/fr; % step is of 0.01 so T=1 would be fine y=zeros(1,s); tt=0:1/s/fr:(s-1)/s/fr; kt(1)=1; for k=1:s,
for n=1:s, p(n) = cos(2*pi*fr*(s+1-k)*kt(s+1-n)/(fr*s))+j*sin(2*pi*fr*(s+1-
k)*kt(s+1-n)/(fr*s)); y(k)=p(n); end
end % finding implulse at 16 points in a period figure(1) clf stem(tt,y); % finding frequency response % H(z) = .65+.65*z^(-1)+.65*z^(-2)+...+.65*z^(-15) f=0:0.1:300; z=exp(-j*2*pi*f*T); F=0; for v=1:s Hofz= y(s+1-v)*z.^(v-1); F=F+Hofz; end figure(2) clf subplot(311) plot(F); subplot(312) plot(f,abs(F)); subplot(313) plot(f,angle(F));
Plotting the results on graph
Work on KALMAN Gain
The results of thesis written by an alumni of MTU were quite unexpected. The model was working
perfectly if sampling was done at 10. However, if sampling was done at any other rate. The results were
coming out to be much unexpected.
The old MATLAB code and results are discussed below.
OLD MATLAB Code:
% 11 state clear sample_count=10; cycles=6; f=60; t=0:1/sample_count/60:cycles/60; % not using 15/16/60 to get a full wave
till 2*pi y=sin(2*f*pi*t); points=sample_count; dt=1/600; w=2*pi*60; lambda=0.5; P=[cos(w*dt) -sin(w*dt) 0 0 0 0 0 0 0 0 0; sin(w*dt) cos(w*dt) 0 0 0 0 0 0 0 0 0; 0 0 cos(2*w*dt) -sin(2*w*dt) 0 0 0 0 0 0 0; 0 0 sin(2*w*dt) cos(2*w*dt) 0 0 0 0 0 0 0; 0 0 0 0 cos(3*w*dt) -sin(3*w*dt) 0 0 0 0 0; 0 0 0 0 sin(3*w*dt) cos(3*w*dt) 0 0 0 0 0; % 11*11 0 0 0 0 0 0 cos(4*w*dt) -sin(4*w*dt) 0 0 0; 0 0 0 0 0 0 sin(4*w*dt) cos(4*w*dt) 0 0 0; 0 0 0 0 0 0 0 0 cos(5*w*dt) -sin(5*w*dt) 0; 0 0 0 0 0 0 0 0 sin(5*w*dt) cos(5*w*dt) 0; 0 0 0 0 0 0 0 0 0 0 exp(-dt/lambda)]; Q=P; C=[1 0 1 0 1 0 1 0 1 0 1]; U=1*diag([0.005^2 0.005^2 0.005^2 0.005^2 0.005^2 0.005^2 0.005^2 0.005^2
0.005^2 0.005^2 0.005^2]); % 11*11 B=0.01^2; M=1*diag([(100)/6 (100)/6 (5^2)/6 (5^2)/6 (1^2)/6 (1^2)/6 (1^2)/6 (1^2)/6
(2^2)/6 (2^2)/6 (10^2)/12]); % 11*11 vhat0=[0;0;0;0;0;0;0;0;0;0;0]; % 11*1 err=zeros(1,length(y)); for n=1:points K(:,n)=M*C'/(C*M*C'+B); % 11*1 Z=(eye(11)-K(:,n)*C)*M; % 11*11 M=P*Z*P'+Q*U*Q'; % 11*11 end
flag=0;
for n=1:length(y)
if n<=points if n==1 vhat(:,n)=P*vhat0+K(:,n)*(y(n)-C*P*vhat0); else vhat(:,n)=P*vhat(:,n-1)+K(:,n)*(y(n)-C*P*vhat(:,n-1)); end elseif flag==1 && k<=length(K(1,:)) vhat(:,n)=P*vhat(:,n-1)+K(:,k)*(y(n)-C*P*vhat(:,n-1)); k=k+1; if k==length(k(1,:)) flag=0; end else vhat(:,n)=P*vhat(:,n-1)+K(:,end)*(y(n)-C*P*vhat(:,n-1)); bla(:,n)=P*vhat(:,n-1); err(n)=abs(y(n)-y(n-points)); if err(n)>0.1 flag=1; k=1; end end
end
est=abs(vhat(1,:)-1i*vhat(2,:)); % fundamental est2=abs(vhat(3,:)-1i*vhat(4,:)); % 2 harmonic est3=abs(vhat(5,:)-1i*vhat(6,:)); % 3 harmonic est4=abs(vhat(7,:)-1i*vhat(8,:)); % 4 harmonic est5=abs(vhat(9,:)-1i*vhat(10,:)); % 5 harmonic est_dc=abs(vhat(11,:)); % dc offset
figure(1) plot(60.*t,y,'k',60.*t,est,'b:h',60.*t,est2,'g:+',60.*t,est3,'r-
s',60.*t,est4,'b:x',60.*t,est5,'b:o',60.*t,est_dc,'k-->') % figure(2) % plot(60.*t,est,'b') % figure(3) % plot(60.*t,est2,'g') grid on xlabel('number of 60hz cycles') ylabel('currrent A') Title('11 state model') legend('signal input','fundamental wave','2nd harmonic','3rd harmonic','4th
harmonic','5th harmonic','DC offset');
Results
for sample count = 10, cycles=6, frequency=60:
for sample count = 16, cycles=6, frequency=60:
for sample count = 16, cycles=6, frequency=60:
New MATLAB code after correction:
% 11 state clear sample_count=16; cycles=6; f=60; t=0:1/sample_count/60:cycles/60; % not using 15/16/60 to get a full wave
till 2*pi y=sin(2*f*pi*t); points=sample_count; fs=points*60; dt=1/fs; w=2*pi*60; lambda=0.5; P=[cos(w*dt) -sin(w*dt) 0 0 0 0 0 0 0 0 0; sin(w*dt) cos(w*dt) 0 0 0 0 0 0 0 0 0; 0 0 cos(2*w*dt) -sin(2*w*dt) 0 0 0 0 0 0 0; 0 0 sin(2*w*dt) cos(2*w*dt) 0 0 0 0 0 0 0; 0 0 0 0 cos(3*w*dt) -sin(3*w*dt) 0 0 0 0 0; 0 0 0 0 sin(3*w*dt) cos(3*w*dt) 0 0 0 0 0; % 11*11 0 0 0 0 0 0 cos(4*w*dt) -sin(4*w*dt) 0 0 0; 0 0 0 0 0 0 sin(4*w*dt) cos(4*w*dt) 0 0 0; 0 0 0 0 0 0 0 0 cos(5*w*dt) -sin(5*w*dt) 0; 0 0 0 0 0 0 0 0 sin(5*w*dt) cos(5*w*dt) 0; 0 0 0 0 0 0 0 0 0 0 exp(-dt/lambda)]; Q=P; C=[1 0 1 0 1 0 1 0 1 0 1]; U=1*diag([0.005^2 0.005^2 0.005^2 0.005^2 0.005^2 0.005^2 0.005^2 0.005^2
0.005^2 0.005^2 0.005^2]); % 11*11 B=0.01^2; M=1*diag([(100)/6 (100)/6 (5^2)/6 (5^2)/6 (1^2)/6 (1^2)/6 (1^2)/6 (1^2)/6
(2^2)/6 (2^2)/6 (10^2)/12]); % 11*11 vhat0=[0;0;0;0;0;0;0;0;0;0;0]; % 11*1 err=zeros(1,length(y)); for n=1:points K(:,n)=M*C'/(C*M*C'+B); % 11*1 Z=(eye(11)-K(:,n)*C)*M; % 11*11 M=P*Z*P'+Q*U*Q'; % 11*11 end
flag=0;
for n=1:length(y) if n<=points if n==1 vhat(:,n)=P*vhat0+K(:,n)*(y(n)-C*P*vhat0); else vhat(:,n)=P*vhat(:,n-1)+K(:,n)*(y(n)-C*P*vhat(:,n-1)); end elseif flag==1 && k<=length(K(1,:)) vhat(:,n)=P*vhat(:,n-1)+K(:,k)*(y(n)-C*P*vhat(:,n-1)); k=k+1; if k==length(k(1,:))
flag=0; end else vhat(:,n)=P*vhat(:,n-1)+K(:,end)*(y(n)-C*P*vhat(:,n-1)); bla(:,n)=P*vhat(:,n-1); err(n)=abs(y(n)-y(n-points)); if err(n)>0.1 flag=1; k=1; end end
end
est=abs(vhat(1,:)-1i*vhat(2,:)); % fundamental est2=abs(vhat(3,:)-1i*vhat(4,:)); % 2 harmonic est3=abs(vhat(5,:)-1i*vhat(6,:)); % 3 harmonic est4=abs(vhat(7,:)-1i*vhat(8,:)); % 4 harmonic est5=abs(vhat(9,:)-1i*vhat(10,:)); % 5 harmonic est_dc=abs(vhat(11,:)); % dc offset
figure(1) plot(60.*t,y,'k',60.*t,est,'b:h',60.*t,est2,'g:+',60.*t,est3,'r-
s',60.*t,est4,'b:x',60.*t,est5,'b:o',60.*t,est_dc,'k-->') % figure(2) % plot(60.*t,est,'b') % figure(3) % plot(60.*t,est2,'g') grid on xlabel('number of 60hz cycles') ylabel('currrent A') Title('11 state model') legend('signal input','fundamental wave','2nd harmonic','3rd harmonic','4th
harmonic','5th harmonic','DC offset');
Results
for sample count = 10, cycles=6, frequency=60:
for sample count = 16, cycles=6, frequency=60:
for sample count = 32, cycles=6, frequency=60:
Conclusion
The results received were due to a minor mistake in the MATLAB code. The changes were
rectified and accurate results were received.
Recommended