How do we find the exact temperature of a star?

This is a very basic question, but I am a little confused. As far as I know, the temperature of a star is analyzed based on the color of the light it emits. So, if a star is moving away from us, then the light emitted by it will be redshifted(or if it is stationary with respect to us and the light undergoes gravitational redshift), then how do we know the exact temperature of that star or any other object because it is possible that we observe red light but actually the star might be emitting yellow light.

-
I think you are answering yourself. Given that we understand photon redshift then it is just a matter of considering those effects in the calculation for the real colour and eventually arrive to the temperature. – harogaston May 7 '14 at 9:58
@harogaston But for removing the error due to red shift, you first have to know that you are seeing red shifted light. – Yashbhatt May 7 '14 at 12:19
Every light wave coming from a galaxy not belonging to our cluster will be redshifted. So you know that what you are getting is redshifted light. Then you can calculate the distance to the galaxy/star you are observing and from there its relative velocity and so you can have an estimate of the redshift effect in your signal. Then apply the corrections to get its real temperature. – harogaston May 7 '14 at 20:24

This question is very broad - there are very many techniques for estimating temperatures, so I will stick to a few principles and examples. When we talk about measuring the temperature of a star, the only stars we can actually resolve and measure are in the local universe; they do not have appreciable redshifts and so this is rarely of any concern. Stars do of course have line of sight velocities which give their spectrum a redshift (or blueshift). It is a reasonably simple procedure to correct for the line of sight velocity of a star, because the redshift (or blueshift) applies to all wavelengths equally and we can simply shift the wavelength axis to account for this. i.e. We put the star back into the rest-frame before analysing its spectrum.

Gerald has talked about the blackbody spectrum - indeed the wavelength of the peak of a blackbody spectrum is inversely dependent of temperature through Wien's law. This method could be used to estimate the temperatures of objects that have spectra which closely approximate blackbodies and for which flux-calibrated spectra are available that properly sample the peak. Both of these conditions are hard to satisfy in practice: stars are in general not blackbodies, though their effective temperatures - which is usually what is quoted, are defined as the temperature of a blackbody with the same radius and luminosity of the star.

The effective temperature of a star is most accurately measured by (i) estimating the total flux of light from the star; (ii) getting an accurate distance from a parallax; (iii) combining these to give the luminosity; (iv) measuring the radius of the star using interferometry; (v) this gives the effective temperature from Stefan's law: $$L = 4\pi R^2 \sigma T_{eff}^4,$$ where $\sigma$ is the Stefan-Boltzmann constant. Unfortunately the limiting factor here is that it is difficult to measure the radii of all but the largest or nearest stars. So measurements exist for a few giants and a few dozen nearby main sequence stars; but these are the fundamental calibrators against which other techniques are compared and calibrated.

A second major secondary technique is a detailed analysis of the spectrum of a star. To understand how this works we need to realise that (i) atoms/ions have different energy levels; (ii) the way that these levels are populated depends on temperature (higher levels are occupied at higher temperatures); (iii) transitions between levels can result in the emission or absorption of light at a particular wavelength that depends on the energy difference between the levels.

To use these properties we construct a model of the atmosphere of a star. In general a star is hotter on the inside and cooler on the outside. The radiation coming out from the centre of the star is absorbed by the cooler, overlying layers, but this happens preferentially at the wavelengths corresponding to energy level differences in the atoms that are absorbing the radiation. This produces absorption lines in the spectrum. A spectrum analysis consists of measuring the strengths of these absorption lines for many different chemical elements and different wavelengths. The strength of an absorption line depends primarily on (i) the temperature of the star and (ii) the amount of a particular chemical element, but also on several other parameters (gravity, turbulence, atmospheric structure). By measuring lots of lines you isolate these dependencies and emerge with a solution for the temperature of the star - often with a precision as good as +/-50 Kelvin.

Where you don't have a good spectrum, the next best solution is to use the colour of the star to estimate its temperature. This works because hot stars are blue and cool stars are red. The colour-temperature relationship is calibrated using the measured colours of the fundamental calibrator stars. Typical accuracies of this method are +/- 100-200 K (poorer for cooler stars).

-

Spectral lines occur at defined wavelengths. By their redshift you can calculate the radial velocity (or gravitational redshift) of the star, or the absorbing medium, and hence the amount you've to shift the black body radiation to obtain the surface temperature (and the radial velocity of a possibly absorbing medium between the star and Earth).

Schematic example: Assume, you measure the following two stellar spectra, and you're able to identify the typical H-alpha spectral emission line. This line should be at 565.3 nm:

In the second spectrum, H-alpha is at the correct position: no redshift. In the first spectrum, it's redshifted (towards longer wavelength).

Although the measured intensity may be the same elsewhere in the spectrum, you'll know, that the first spectrum is of a hotter star, since the maximum intensity (besides the H-alpha line) is left (towards blue) of the H-alpha wavelength, whereas the maximum intensity in the second spetrum is right (towards red) of the H-alpha line.

Both stars would look reddish, but the first one is the hotter one, and it's redshifted, either due to Doppler shift, due to gravity, or due to cosmic expansion.

-
I read that article on spectral lines but still din't get it. Let us suppose that I note down the spectrum of a star. Normally, there should be a peak at blue but now the star starts moving away at a constant speed and as a result there's a peak at yellow. So, won't there be an error in calculating the temperature? – Yashbhatt May 6 '14 at 14:02
See the third answer here. Is that what you are trying to say? – Yashbhatt May 6 '14 at 14:04
@Yashbhatt I've added a link to black body radiation. Stars roughly emit black body radiation. From the intensity maxium you can conclude the temperature. The spectral lines tell you, how much you have to shift the measured curve to get the emitted curve. Details may be more complicated, but that's the principle. – Gerald May 6 '14 at 22:49
@ Gerald I understood that this method is used for finding out the temperature of stars but what about galaxies? They are not made up of a single element. So how do we know how much the spectra is shifted? Do we do something like averaging the temperatures of all the stars in the galaxy or something like that? – Yashbhatt Jun 15 '14 at 15:02
I understood how we use it to calculate temperatures of stars. But what about galaxies/ They are mixture of so many elements. How do we know how much the spectra is shifted? Do we do something like averaging th temperatures of all the stars in the galaxy? – Yashbhatt Jun 15 '14 at 15:21