Some parts are commented in Polish. Sorry for that :) If you need a similar solution for an AC drive please see http://ufnalski.edu.pl/dissertation/ -- also in Polish :) You might be also interested in http://www.mathworks.com/matlabcentral/fileexchange/57351-extended-kalman-filter-for-speed-sensorless-ac-motor-drive .
Bartlomiej Ufnalski (2020). Kalman filter for speed-sensorless DC motor drive (https://www.mathworks.com/matlabcentral/fileexchange/57319-kalman-filter-for-speed-sensorless-dc-motor-drive), MATLAB Central File Exchange. Retrieved .
Modeling of the system (=process) noise corrected. A huge thanks goes to my colleague Arkadiusz Kaszewski for pointing this out.
Info on EKF added.