This paper utilizes the Fast Fourier Transform (FFT) technique to extract the apparent power of DC microgrids for fault detection. The proposed method separates the real and imaginary components of power and compares the imaginary part with a predetermined threshold. To determine the relay threshold, PP and PG faults are simulated at various distances along each line connected to each bus. The Inverse Fast Fourier Transform (IFFT) is then calculated for each fault at each line and location. The relay threshold is selected based on the lowest significant value among the highest IFFT values calculated for all microgrid lines. This study proposes a novel relay threshold calculation approach, enabling precise fault detection and localization in DC microgrids. The relay threshold value is calculated at the control center and then sent to the microgrid relays. Fault detection is achieved by comparing the IFFT values obtained within the microgrid with the relay threshold value. Once the relay threshold is surpassed, the microgrid detects the fault and promptly sends a trip signal to the circuit breaker. This fault detection strategy accurately identifies the fault location by measuring the current and voltage between the terminals of the faulty section. The proposed method swiftly detects all PP and PG faults (including HIF up to 50 ohms) in grid-connected and islanded modes within 2-3 milliseconds. It accurately locates faults with minimal deviation across various positions. Rigorous simulations using MATLAB and EMTP-RV programs confirm the effectiveness of the protection scheme, emphasizing its reliable performance.