4. (7th "Hope Cup" Senior High School Competition) If the function $y=\left|\sin \left(\omega x+\frac{\pi}{3}\right)-1\right|$ has the smallest positive period of $\frac{\pi}{2}$, then the value of the positive number $\omega$ is
A. 8
B. 4
C. 2
D. 1
4. B Because $-1 \leqslant \sin \left(\omega \pi+\frac{\pi}{3}\right) \leqslant 1$.

So $\left|\sin \left(\omega x+\frac{\pi}{3}\right)-1\right|=1-\sin \left(\omega x+\frac{\pi}{3}\right)$.
Since $T=\frac{2 \pi}{\omega}$ and $T=\frac{\pi}{2}$, then $\omega=4$. Choose $\mathrm{B}$.
Another solution: From the graph, the curve $\sin \left(\omega x+\frac{\pi}{3}\right)-1$ is always below the x-axis and tangent to it. Therefore, the curve $\left|\sin \left(\omega x+\frac{\pi}{3}\right)-1\right|$ is always above the x-axis and tangent to it, so the smallest positive period of the function $y$ is $T=\frac{2 \pi}{\omega}$. Since the given $T=\frac{\pi}{2}$. Therefore, $\omega=4$, choose B.

Note: Generally, for the function $y=|\sin (\omega x+\varphi)+c|(\omega>0)$, when $c=0$, the smallest positive period is $\frac{\pi}{\omega}$, and when $c \neq 0$, the smallest positive period is always $\frac{2 \pi}{\omega}$. Readers who are interested can prove it themselves.