I hope you're not planning to couple the speaker directly to your DAC
No, I am not. What I meant to say if this offset is going to produce any problems because I can't generate an AC-voltage (in terms of a voltage < 0 during one half sine wave) with a DAC (I assume?) if there is no negative supply voltage. So there has to be an offset - right?
I don't have enough knowledge about electronics to tell whether an operational amplifier would be sufficient or if I need something with more output power.
…
Well, how would this work if I truly create an AC voltage?
…
I don't really want to play with an AC power supply or whatnot. Is it possible to stick to a 5V DC supply?
Here's a basic idea of what your setup could look like. The DAC on the left is generating the signal with a DC offset so that the output stays within the power supply rails.
The opamp could be just an opamp, or a driver IC like LM386, or a power amp IC. Start with an opamp and see how you get on. They don't have a lot of output drive for speakers but AFAIK, speaker parameters don't change a lot between 1 milliwatt and 1 watt (unless you have a very low-power speaker).
I added two resistors R1 and R2 as current sense resistors. You can choose either one and measure the voltage across it. 10 ohms is just a placeholder value that would work, but you may want to decrease the value to near-zero so you can assume that the voltage across the speaker is equal to the amplifier output voltage.
The capacitor (1 microfarad is probably a bit small, you would lose bass response) is an AC-coupling capacitor. You can see this kind of capacitor in many audio circuits. They are used to change a signal's DC value without changing its AC value.
On the topic of AC: you seem to be confusing mains AC power with the definition of AC. AC = alternating current, but usually when engineers talk about AC, they mean a voltage that is rapidly changing (hence "AC voltage"). So yes, mains power is AC but the presence of AC in your circuit (inevitable) is not related to mains power.
How can the whole signal be in the range of the ADC if the signal is AC and the ADC can only measure half of the cycle (because DC)?
In reference to the image above, if you measure the voltage after R1, the whole signal will be within your power supply and the ADC can read it. Or you could accept the clipping and measure directly from R2. Or you could use an AC-coupling capacitor to add DC back to the voltage at R2 and then the ADC can read the whole signal.
It doesn't matter.
So what you are saying is that I don't need to sample a complete sine wave from the ADC because I just need the peaks (which will of course also occur during the positiv wave) to calculate impedance?
That's right. For a perfect sine wave, the amplitude, peak to peak voltage, and RMS voltage are all linearly related. What that means for you is that you don't need to know anything except for the peak voltage to calculate the RMS voltage. From that and the resistor value, you know the current through the resistor by I = V / R.
For a sine wave signal, any of these values at any moment will work in the equation. The speaker impedance Z = V / I is an instantaneous value, but it will be constant at any point in the sine wave as long as the frequency stays the same.
I wrote: then there must be a resistor with precisely known value in series to the second connector of the speaker
...
I don't think we are speaking about the same thing. How do I get I without an resistor?
Aha, we are talking about different things. I was talking about a resistor to calibrate the system where you place a known load on the speaker terminals.
You're talking about the current sense resistor, which is necessary.
Earlier, I said "but you may want to decrease the value to near-zero so you can assume that the voltage across the speaker is equal to the amplifier output voltage."
To expand on that:
Your output signal Vout will go to the speaker and the sense resistor. Vout = Vspk + Vsense (therefore Vspk = Vout - Vsense)
The current through the sense resistor is related to the voltage across it Isense = Vsense / Rsense
The current through the sense resistor is equal to the current through the speaker. Ispk = Isense
From this you can know two of the Ohm's law parameters for the speaker: Vspk and Ispk
So you can calculate its impedance Z = Vspk / Ispk = (Vout - Vsense) / (Vsense / Rsense)
If you use a small Rsense like 0.1 then you can probably ignore Vsense in the first equation and assume Vout = Vspk. Not really any point though so whatever.
If you use a big Rsense like 10 ohms then there will be more voltage across it so you'll get more resolution in your ADC and therefore a higher quality result.
Thanks Prehistoricman, that's a very valuable post for me.
...
Sorry to ask so many beginners questions
More questions = more good. You're clearly thinking about the problem and you're willing to work on a solution which is great.
I hope I haven't given you too many words, or too many options