% Root Mean Square Value
function [retval] = rms1(sig)
N = 20;
for k = 1 : length(sig)/N - 1
sig_sum = sum(sig((k-1)*N+1 : k*N));
squ_sum = sum(sig((k-1)*N+1 : k*N).^2);
retval(k) = sqrt(squ_sum/N);
end
endfunction
% Root Mean Square Value of AC
function [retval] = rms2(sig)
N = 20;
for k = 1 : length(sig)/N - 1
sig_sum = sum(sig((k-1)*N+1 : k*N));
squ_sum = sum((sig((k-1)*N+1 : k*N) .- sig_sum/N).^2);
retval(k) = sqrt(squ_sum/N);
end
endfunction
% Root Mean Square Value of AC
function [retval] = rms3(sig)
N = 20;
for k = 1 : length(sig)/N - 1
sig_sum = sum(sig((k-1)*N+1 : k*N));
squ_sum = sum(sig((k-1)*N+1 : k*N).^2);
retval(k) = sqrt(squ_sum/N - (sig_sum/N)^2);
end
endfunction
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Fs = 1e5;
N = 1000;
t = [0 : 1/Fs : (N-1)/Fs];
x = 2 * 1.414 * cos(2*pi*25e3*t) .+ 2 * 1.414 * cos(2*pi*10e3*t) + 1.0;
figure;
subplot(2,2,1)
plot(x(1:50));
grid on;
subplot(2,2,2);
plot(rms1(x));
grid on;
subplot(2,2,3);
plot(rms2(x));
grid on;
subplot(2,2,4);
plot(rms3(x));
grid on;