(new bee) How can I verify my 'C' algorithm using Matlab. Plz give directions
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Walter Roberson
am 24 Jan. 2012
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.
Antworten (2)
Walter Roberson
am 25 Jan. 2012
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()
Siehe auch
Kategorien
Mehr zu Function Creation finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!