So my problem is to find the rms value of each frequency component. I know the magnitude of each frequency component from this graph, but how can I convert this magnitude to rms value?
Remember the Fourier expansion. It gives you all sinewave components that form the original signal. So the magnitudes you see on your FOURIER ANALYSIS graph are the magnitudes of each sinewave component. To get the RMS, just divide the magnitude by the square root of two, 1.414.
If I want to calculate an approximate THD value, how many harmonics should I calculate up to?
I'm calculating it manually, but does Proteus have a practical feature for this? Or is there a specific application for THD calculation?
This answers your last two questions: You don't need to use a number of sinewaves' peaks. You can, but there's no standard way to choose the number of harmonics for THD calculation. Of course, after a certain index of harmonic the THD measurement will not change much, but that depends on the frequency content or the original signal itself, and also your accuracy requirement. So it's up to you i.e. you can start with up to 10th harmonic and calculate the THD, then up to 11th to see if it changes much, etc.
Instead,
- Run the original signal through a very high-Q band-stop filter. (I believe ISIS/Proteus has a block to do the job). This will remove the fundamental component. Therefore the remaining (filter's output) will be the sum of all of the harmonics. So the RMS will give you the numerator of the THD formula. The scope or the voltmeter should able to show the RMS for you, so it shouldn't be a problem.
- Calculating the V1, RMS of the fundamental, should not be a problem either because you can calculate it by hand. The peak is \$V_{1pk}=(4/\pi) \ V_p\$ and its RMS is \$V_1=(2\sqrt2/\pi) \ V_p\$, where \$V_p\$ is the peak of your original square wave signal.
- Put the numbers into the formula.