필터 지우기
필터 지우기

how can i calculate the rms of a vector ?

조회 수: 11 (최근 30일)
Mallouli Marwa
Mallouli Marwa 2016년 5월 3일
댓글: Camille Dingam 2020년 3월 10일
my problem consist to calculate the rms of v using for loop. But this for loop display vrms as zeros
for i=1:2500
vs=sum((v(i,1))^2)
end
vrms=sqrt((1/2501)*vs);

채택된 답변

Guillaume
Guillaume 2016년 5월 3일
You get 0 because the last value in v is 0 and your vs is just the last value of v squared. Notice that sum(v(i)) is just v(i). You probably meant:
vs = vs + v(i)^2;
Your loop is badly constructed by the way. For a start you shouldn't hardcode the length of the vector, you can get it with numel. You also shouldn't use subscript indexing when linear indexing suffices. That way, it would work with row or column vectors:
vs = 0;
for i = 1:numel(v)
vs = vs + v(i)^2;
end
vrms = sqrt(vs / (numel(v)+1));
In any case, the loop is completely unnecessary:
vs = sum(v.^2);
vrms = sqrt(vs / (numel(v)+1));
  댓글 수: 2
Mallouli Marwa
Mallouli Marwa 2016년 5월 3일
thank's a lot
Tahariet Sharon
Tahariet Sharon 2017년 11월 25일
편집: Tahariet Sharon 2017년 11월 25일
why do you divide by plus 1?

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Star Strider
Star Strider 2016년 5월 3일
The root-mean-square calculation is a one-line calculation:
v = sin([1:0.1:20]*2*pi); % Create Data
rms = sqrt(mean(v.^2));
  댓글 수: 3
Star Strider
Star Strider 2016년 5월 4일
My pleasure.
Camille Dingam
Camille Dingam 2020년 3월 10일
I have done the work with normal people and dysarthria(sick person) audio datasets. I have extracted the rms(root mean squared) energies of their vowels, and i found that dysarthria rms energies of the vowels are mostly high than normal person, please i try to make a conclusion of it. If anyone have some ideas of rms energy, can you tell me why the vowels rms energies are high in dysarthria? Thank you for your reply

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by