How does PWM generate an analog signal?
I'll answer, qualitatively, that a low pass filter (i.e. an RC filter or something more sophisticated), acts to smooth out variations over time (more or less aggressively based on its designed time constant). A step function (i.e. a theoretically pure square wave is a composition of these) will be transformed into a more gradual "ramp" (not being precise here on purpose) by a low pass filter. If instead of a step function, you imagine a PWM signal that changes more rapidly than the time it takes that "ramp" to reach it's final value in the case of a step response, it's plain to see that the output of the low pass filter will be somewhere between the high and low value of the square wave. Where exactly that voltage settles is an direct function of the duty cycle, and you can prove that to yourself mathematically or through simulation. There's also obviously some distorting relationship between the rise-time of the filter's step response and the period of the PWM signal, but that's a second-ordery consideration. I might get myself into trouble here, I'm a bit rusty, but I think an important point here is that practical low pass filter are not memoryless.