Hello all,
I have the sequence v of length K-by-1. I want to do integration of v over nn*nsamp to (nn+1)*nsamp for nn=0, ..., N-1 and K=nsamp*N. I did this in MATLAB as following:
y=zeros(N,1);
for nn=0:N-1
y(nn)=sum(v(nn*nsamp:(n+1)*nsamp))
end
Is this right?

댓글 수: 2

Unlike some other programming languages, the index for the first element in a matrix/vector is 1 in MATLAB. So for example, if A=[5 6 7], then A(1) gives 5. While A(0) gives an error. So in your case, you want to define nn from 1 to N-1:
for nn=0:N-1
You might also want to look into the trapz built-in function to integrate. What is the range of x-values you're integrating over?
S. David
S. David 2014년 6월 4일
편집: S. David 2014년 6월 4일
Yes you are right, I should have written
...
y(nn+1)=sum(v(nn*nsamp+1:(n+1)*nsamp))
...
Actually, v corresponds to the continuous time signal v(t) where
t=0:Ta:(K-1)*Ta
I want to do the integration:
yn=int_{n*Ts}^{(nn+1)*Ts} v(t) dt % n=0,...,N-1
where Ta=Ts/nsamp.

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

답변 (0개)

카테고리

도움말 센터 및 File Exchange에서 Numerical Integration and Differentiation에 대해 자세히 알아보기

태그

질문:

2014년 6월 4일

편집:

2014년 6월 4일

Community Treasure Hunt

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

Start Hunting!

Translated by