Jimmy87 said:
When you pluck a guitar string it resonates at its fundamental frequency plus some of the overtones. My question is, what exactly determines the note (i.e. A,C, E etc) for, say, a guitar? For example, if note A is 440Hz then what is it that is at 440Hz because some instruments have lots of overtones when you play them and some don't so for the ones that do have lots of overtones does it mean that the 440Hz is the sum of all the overtones and the fundamental or is it just the fundamental that dictates the frequency of a particular note? Also, why do you get a bad sound when you don't quite hit the right note because even if you don't hit the note surely whatever you do hit still has resonant frequencies with harmonics?
I actually did a summer project on this a while back, so I'm going to give a very long (but hopefully useful) answer.
The physical properties of the string/instrument are basically what determine the note. For an ideal string, it's just tension and mass per unit length (IIRC). For a real string, other things come into play (more on this later). Also, the instrument surrounding a string will impact the sound quite a bit.
For an ideal string, there's a fundamental frequency (e.g. 440 Hz) and harmonics above it (880 Hz, 1320 Hz, etc.). The fundamental frequency is what determines the note. If the fundamental frequency is 440 Hz, then the note is an A, regardless of whether the harmonics are audible or not.
The harmonics are important, though, because they are a key part of what makes an A on a piano sound different from an A on a guitar. For example, a whistle is going to be pretty much a pure 440 Hz wave; the 880 and 1320 Hz harmonics are going to be very small. On a different instrument, like a piano, the harmonics will be much stronger, which is why a piano sounds so much "richer" than a whistle. On a guitar the harmonics will have different strengths than the piano, making the guitar sound different. The relative strengths of the harmonics and fundamental frequency depend on the whole musical instrument, including the string and the body that the string is attached to (not to mention how the string is made to vibrate: e.g. hammer, pick, or bow). That's why guitars and pianos sound different, even though the strings are reasonably similar.
To sum up, for an ideal string/instrument there's a fundamental frequency f
0, which determines the "note" you're playing. Then there are harmonics at exactly 2*f
0, 3*f
0, etc. Changing the relative strength of these harmonics can make the same note sound quite different.
The ideal string model is a good starting place, and but to understand real instruments, we need to add some things to our model. The first, perhaps obvious, thing is that real strings don't vibrate forever. They lose energy and the note decays over time. Different harmonics decay at different rates, which can affect how a note sounds. (For "sharper" notes, the second and third harmonics can actually be louder than the fundamental frequency at first, but they die away very quickly, leaving the fundamental frequency to linger in your ear).
The second non-ideal effect comes from something called the stiffness of the string. What this does is it shifts the harmonics a bit. For example, rather than having 440, 880, 1320, etc., you might have 440, 886, 1334, etc. (it affects the higher harmonics more than the lower ones). This effect is noticeable for the lowest keys on the piano: it helps give them that really rich, full sound. However, while a little bit of offset can be nice, shifting the harmonics by too much will sound awful. This is one way that a "bad" note can appear: if a string is too stiff (so it's not a very good string), it won't produce a good sound. This doesn't really answer your question, though, which has to do with a string that normally sounds good, but sounds bad if you hit it wrong.
So finally, what happens when you hit a string "wrong?" For example, let's say you pull a guitar string up as far as you can without breaking it and then let it snap back. It will make an ugly sound and then mellow out into a "purer" note. What's happening here is you've pushed the string into what's called a non-linear regime. Basically, the physics describing the string become a lot more complicated if you stretch it too far or make it vibrate loosely against a fret or something like that. In "extreme" (non-linear) cases like these, the idea of fundamental frequency and harmonics is no longer a good way to describe the string. Mathematically you can still do it, but you'll basically have a huge mess of seemingly-random harmonics which probably won't look anything like the ideal case (it's quite different from stiffness where you still have harmonics, you've just shifted them around). So to answer your question, the note sounds "bad" because if you push the string into "non-linear mode" the whole notion of fundamental frequencies and harmonics goes out the window. You just get a seemingly-random vibration which may or may not sound "nice."
Summary:
In the ideal case, you get fundamental frequencies and harmonics. In the more-realistic-but-still-musical case, the note decays and the harmonics get shifted around a bit (they won't quite be multiples of the fundamental). You still have harmonics, but if you push them around too much, they'll clash and things will sound bad. If you play your instrument in a way it's not meant to be played, your instrument might start to behave in a non-linear way. In that case, harmonics go out the window and you essentially get a big seemingly-random mess of frequencies which may or may not sound good.
Note 1: This answer mostly focused on strings, but the same goes for other instruments, like the vocal chords or a pipe organ. The underlying reasons may be different, but the effects are similar.
Note 2: For the more mathematically literate, "ideal" instruments are modeled using the wave equation. "Non-ideal" instruments are modeled using the wave equation with additional 3rd and 4th order partial derivative terms added. "Non-linear" instruments are modeled using non-linear partial differential equations.