3. Given constants $a>0, b>0$. Then the range of the function
$$
f(x)=a|\sin x|+b|\cos x|
$$

is ( ).
(A) $\left[-\sqrt{a^{2}+b^{2}}, \sqrt{a^{2}+b^{2}}\right]$
(B) $\left[a, \sqrt{a^{2}+b^{2}}\right]$
(C) $\left[b, \sqrt{a^{2}+b^{2}}\right]$
(D) $\left[a, \sqrt{a^{2}+b^{2}}\right]$ or $\left[b, \sqrt{a^{2}+b^{2}}\right]$
3. D.

Since $f(x)$ is an even function, and when $a \neq b$, $T=$ $\pi$, when $a=b$, $T=\frac{\pi}{2}$, so, without loss of generality, let $x \in[0$, $\left.\frac{\pi}{2}\right]$.
Then $f(x)=a \sin x+b \cos x$
$$
=\sqrt{a^{2}+b^{2}} \sin (x+\varphi),
$$

where $\sin \varphi=\frac{b}{\sqrt{a^{2}+b^{2}}}, \cos \varphi=\frac{a}{\sqrt{a^{2}+b^{2}}}, \varphi$ is an acute angle.

Since $x+\varphi \in\left[\varphi, \varphi+\frac{\pi}{2}\right]$, $\sin x$ is monotonically increasing in $\left[\varphi, \frac{\pi}{2}\right]$ and monotonically decreasing in $\left[\frac{\pi}{2}, \varphi+\frac{\pi}{2}\right]$, so when $a \geqslant b$, the range of the function $f(x)$ is $\left[b, \sqrt{a^{2}+b^{2}}\right]$; when $a<b$, the range of the function $f(x)$ is $\left[a, \sqrt{a^{2}+b^{2}}\right]$.