How does an AM radio filter out only the desired frequency?
It uses something called a filter. You can build filters out of all sorts of different things.
RC filters made out of resistors and capacitors are probably the simplest to understand. Basically, the capacitor acts as a resistor, but with a different resistance at different frequencies. When you add a resistor, you can build a voltage divider that is frequency dependent. This is called an RC filter. You can make high pass and low pass filters with one resistor and one capacitor. A low pass filter is designed to pass low frequencies and block high frequencies, while a high pass filter does the opposite. A low pass in series with a high pass forms a bandpass, which passes frequencies within some range and blocks other frequencies. Note that the operation of an RC filter (and most filters, for that matter) will depend on the source and load impedance. This is especially important when cascading simple filter stages to construct larger filters as the operation of each stage will be affected by the impedance of the adjacent stages.
simulate this circuit – Schematic created using CircuitLab
Filters can also be made with other components, such as inductors. Inductors also act like resistors, but they change in the opposite direction as capacitors. At low frequencies, an inductor looks like a short while a capacitor looks like an open. At high frequencies, an inductor looks like an open while a capacitor looks like a short. LC filters are a type of filter built with inductors and capacitors. It is possible to make a rather sharp LC filter that cuts off quickly and is easy to tune with a variable capacitor. This is what is normally done for simple radios like crystal radios.
simulate this circuit
You can make bandpass filters out of anything that has a resonant frequency. A capacitor and an inductor in series or in parallel form a resonant tank circuit that can be used as a bandpass or bandstop filter, depending on precisely how you hook it up. An antenna is also a bandpass filter - it will only receive frequencies well that have wavelengths around the size of the antenna. Too large or too small and it won't work. Cavities can also be used as filters - a sealed metal box has various standing wave modes, and these can be exploited to use as filters. Electronic waves can also be converted to other waves, such as acoustic waves, and filtered. SAW (surface acoustic wave) filters and crystal filters both work by mechanical resonance and use the piezoelectric effect to interface with the circuit. It is also possible to build filters out of transmission lines by exploiting their inherent inductance and capacitance as well as by exploiting constructive and destructive interference that results from reflections. I have seen a number of microwave band filters that are made out of a crazily shaped piece of copper printed on a PCB. These are called distributed element filters. Incidentally, most of these other filters can all be modeled as LC or RLC circuits.
Now, a software defined radio is a different animal altogether. Since you are working with digital data, you can't just throw some resistors and capacitors at the problem. Instead, you can use some standard filter topologies like FIR or IIR. These are built out of a cascade of multipliers and adders. The basic idea is to create a time-domain representation of the filter you need, and then convolve this filter with the data. The result is filtered data. It is possible to build low pass and bandpass FIR filters.
Filtering goes hand in hand with frequency conversion. There is a parameter that you will see all over the place called Q. This is the quality factor. For bandpass filters, it is related to the bandwidth and center frequency. If you want to make a 100 Hz wide filter at 1 GHz, you would need a filter with an astronomically high Q. Which is infeasible to build. So instead, what you do is filter with a low Q (wide) filter, downconvert to a lower frequency, and then filter with another low Q filter. However, if you convert 1 GHz to, say, 10 MHz, a 100 Hz filter has a much more reasonable Q. This is often done in radios, and possibly with more than one frequency conversion. Additionally, this method makes it very easy to tune the receiver as you can just change the frequency of the oscillator used for the frequency translation to tune the radio instead of changing the filters.
In the case of digital filters, the longer the filter, the higher the Q and the more selective the filter becomes. Here is an example of an FIR bandpass filter:
The top curve is the frequency response of the filter and the bottom curve is a plot of the filter coefficients. You can think of this type of filter as a way of searching for matching shapes. The filter coefficients contain specific frequency components. As you can see, the response oscillates a bit. The idea is that this oscillation will match up with the input waveform. Frequency components that match closely will appear in the output and frequency components that do not will get cancelled out. A signal is filtered by sliding the filter coefficients along the input signal one sample at a time, and at each offset the corresponding signal samples and filter coefficients are multiplied and summed. This ends up basically averaging out signal components that do not match the filter.
Frequency conversion is also performed both in software and in hardware. In hardware, this is required to get the band you're interested in inside of the ADC IF bandwidth. Say, if you want to look at a signal at 100 MHz but your ADC can only receive 5 MHz of bandwidth, you will have to downconvert it by around 95 MHz. Frequency conversion is performed with a mixer and a reference frequency, generally called the local oscillator (LO). Mixing exploits a trig identity, $$\cos(A)\cos(B) = \frac{1}{2}(\cos(A+B)+\cos(A-B))$$. Mixing requires a component that multiplies the amplitudes of the two input signals together, and the result are frequency components at the sum and difference of the input frequencies. After mixing, you'll need to use a filter to select the mixer output that you want.
This is done using a Heterodyne tuning system. For example, let's say you want to tune in a station at 1200kHZ. You set your tuning dial to "1200", which sets a local oscillator to generate a frequency of 745kHz. When you mix them, one of the resulting frequencies is the difference (the freq. you want to tune - 745kHz).
The next stage is a narrow band amplifier tuned to 455kHz. What is now at 455kHZ was 455+745 or 1200kHZ incoming, the station you wanted to receive. This (455kHz) gets amplified and detected, resulting in the audio for that station being heard.
Other frequencies still are received, of course. But their resulting frequency will be different than 455kHz, so they will not be amplified.
Using 455kHZ intermediate frequency (in the US) was decided because it was below the standard AM band (535kHZ to 1610kHz) so there would be no interference with any station you were trying to receive.
This is for analog radio signal reception. For additional details, you might check Heterodyne, Why the conversion to Intermediate Frequency? and Intermediate frequency.
A radio's antenna will receive many signals equally. what we want is to filter out the other stations, and only permit the signal of the station we are tuned to. the way this was initially done was to use both an inductor and a variable capacitor. At some frequency, the inductive reactance will equal the capacitive reactance, Xl=Xc, giving the least amount of impedance to that signal. that signal is then sent on to be amplified by the remaining circuitry in the radio, while the other frequencies are suppressed because they are not at that resonant frequency. As long as the Q of the filter is high enough, you can eliminate the other stations from being amplified. Also of interest, this inductive / capacitive circuit oscillates, in the true sense of oscillators... meaning it has a gain of above 1 and is driven by a current.