(new bee) How can I verify my 'C' algorithm using Matlab. Plz give directions
1 次查看(过去 30 天)
显示 更早的评论
Hello everyone, I'm Kasu.I have seen other's using MATLAB and know very little about it, but this time, I actually have to use it to check my 'C' code. My task is to verify my 'C' function and the function is very simple. 1. The function has two input sine waves(lets say 'A', 'B'). 2. Inside the function, I just multiply both the inputs (i.e. 'C = A*B') 3. Now, I take the integral of this product (integral of 'C' i.e. iC = (Cn+Cn-1)/2t.. where Cn is current sample, Cn-1 previous sample and 't' is the time between the two samples).Now, I need to verify this integral output using MATLAB.
So, I wanna do something like this.I know the data for two input sine waves to my c-function. I have this data in *.txt file. Now, I want to import this *.txt file into matlab and copy my integral statement from C-function into MATLAB and plot the output of integral.
I have been hearing about many ways that I can do this using MATLAB. But I'm all confused. Some one please give me directions.. or at least provide me some hints of steps about which topics I need to study for this.
Thanks alot. Kasu (<mailto:nandu@mando.com nandu@mando.com>)
2 个评论
Walter Roberson
2012-1-24
The iC expression you give is not really "the integral" of those values: it is the numeric integral over those two points using the trapezoidal rule -- and even then only if the "t" part is a multiplication of the entire product, as in t*(C(n)+C(n-1))/2 . Reference: http://en.wikipedia.org/wiki/Trapezoidal_rule
If you had intended the "2t" to mean (2*t) in the denominator then your iC would appear to be incorrect.
回答(2 个)
Walter Roberson
2012-1-25
The instructions on loading the data are going to depend upon how the data is stored in the file. Please give a few sample lines.
For the calculation:
All at once:
C = A .* B;
sum( t * (C(2:end) + C(1:end-1)) / 2 )
Or use trapz() or cumtrapz()
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Function Creation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!