One thing you can do is to use the Hilbert transform to form the analytic signal corresponding to your signal, then use the modulus (absolute value) of the analytic signal to detect changes in the mean.
For a purely sinuisodal signal obviously the modulus of the analytic signal is a constant. Given numerical precision concerns and the fact that the measurement will contain random noise, the modulus in a given block will not be a constant, but from your example above, it will be close.
n = 0:399;
x = zeros(400,1);
x(1:159) = cos(pi/4*n(1:159));
x(200:end) = 1/5*cos(pi/2*n(200:end));
Now, use hilbert() to obtain the analytic signal
y = hilbert(x);
Notice how the modulus of the analytic signal captures changes in the mean.
If you do something like:
changepoints = abs(diff(abs(y)));
You can see where the mean levels are changing. You will have to ignore the very beginning and end of the interval.
Of course there are a number of change point detection algorithms out there better than the technique I've given (detecting a change based on the first difference of the absolute value of the analytic signal), so feel free to use another technique, but hopefully that gets you started.