码迷,mamicode.com
首页 > 其他好文 > 详细

信号的有效值(RMS)估计

时间:2019-12-22 14:27:21      阅读:262      评论:0      收藏:0      [点我收藏+]

标签:family   soft   rms   bsp   sqrt   length   sig   function   div   

% 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 - sig_sum)/N);
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;

 

信号的有效值(RMS)估计

标签:family   soft   rms   bsp   sqrt   length   sig   function   div   

原文地址:https://www.cnblogs.com/lyuyangly/p/12079606.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!