The recursive discrete Fourier transformation (RDFT) method can be used for grid voltage phase-locking and harmonic current detection in a shunt active power filter (SAPF). However, in weak power grids such as microgrids, significant errors might occur in the amplitude and phase detection due to grid frequency deviation. In this study, to resolve this problem, a directly modified RDFT (DMRDFT) method is proposed for SAPF weak grid application. Through theoretical analysis, the errors of phase and amplitude detection were found to consist of fixed error and fluctuating error. The fixed error is only determined by frequency deviation, whereas the fluctuating error is also related to the recursive pointer and the initial phase. The DMRDFT algorithm can obtain the real grid frequency through the calculation of the phase angle difference for two consecutive periods. Then it can employ the grid frequency deviation and the recursive pointer value to directly correct the detection results gathered by the conventional RDFT algorithm. As a result, DMRDFT can yield accurate amplitude and phase information of the grid voltage or current with a simple calculation. Simulation results verify the high precision of the proposed DMRDFT method in both steady and dynamic situations. Experimental results show that the DMRDFT method can significantly increase the SAPF compensation performance when grid frequency shifts.