(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 で Debugging and Analysis についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!