Electrical engineering education textbooks usually restrict the linking between theory and practical work in power quality problems, such as voltage sag/swell. This paper presents a mathematic model of the power signal and digital signal processing tools, such as Kalman filter and wavelet transform, for analysis and detection of voltage sag/swell. Aiming at education and teaching in electrical power quality courses, M files for Kalman filter and wavelet transform in the Matlab program are introduced to record and track the waveform distortion with harmonics, voltage sag or a pulse, which allow students to simulate the effect of voltage sag and to see immediately the advantages and limitations of these two techniques for power quality problems.