I want to calculate THD. SO how do I isolate the fundamental frequency from a signal with harmonics? I have a signal V which is a sum of V1, V2 and V3. V1=A1sin(w1t+phi1), V2=A2sin(w2t+phi2) and V3=A3sin(w3t+phi3). I want to find out the magnitude/amplitude of a known frequency w1 in the signal. How do I proceed? Should I use the FFT library? If yes then how?
What exactly are you trying to do? If you want to measure THD from an external signal, an Arduino is probably not the best choice. It only has 10-bit ADCs and they are DC-coupled. You can build a simple circuit (https://www.daqarta.com/dw_rrll.htm) to shift an AC-coupled input to DC for the Arduino, but you will still have only 10-bit resolution. I haven't looked deep enough into the library that chrisl mentions to see how big an FFT it can perform in the limited RAM of an Arduino, but I suspect the spectral resolution would be so poor as to be unhelpful for real-world THD measurements.
The way you describe the signal makes me think that this is an academic exercise, not a real-world problem. If so, you don't need an Arduino or any other hardware, just run the FFT on your main computer. If you do need to make real-world measurements, an ordinary sound card on your computer is a better way to go. See https://www.daqarta.com/dw_0d0t.htm for an example. The sound card approach has the added advantage that it can generate a low-distortion test signal to drive the device whose distortion you are trying to measure. That allows a "trick" (called "Spectral Line Lock" in the example) to get even better resolution, by making the test signal synchronous with the sample rate so you don't need window functions.
If you really want to measure THD with an Arduino, consider an approach used in what used to be called a "wave analyzer". The block diagram is shown here: https://www.daqarta.com/dw_0h0p.htm. This is essentially a one-spectral-line analyzer, which actually can be more selective than an FFT. You basically multiply the input signal by the sine and cosine of the reference frequency (the fundamental) and then rectify and filter the results, and combine RMS-wise. That gives you the fundamental value (or any individual harmonic you tune the reference to), so to get THD you divide by the RMS of the overall input signal.