Azzera filtri
Azzera filtri

(new bee) How can I verify my 'C' algorithm using Matlab. Plz give directions

1 visualizzazione (ultimi 30 giorni)
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 Commenti
Walter Roberson
Walter Roberson il 24 Gen 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.
NDKA
NDKA il 25 Gen 2012
Yes, thanks for correcting me. My "iC" expression was something wrong. It should be something like " iC += ((Cn+Cn-1)2)*t ". My intent was to know how can I integrate my input text file data into Matlab variable(s) and do check the output of "iC" on different input conditions. Thanks for your help Walter.

Accedi per commentare.

Risposte (2)

Walter Roberson
Walter Roberson il 25 Gen 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()
  1 Commento
NDKA
NDKA il 25 Gen 2012
Thank you, my data in the input file looks something like below.
The below mentioned "Speed, WheelSpeed, Torque, Torque_BPF" are the different variables in my input file. Data samples are stored for each of these variables in columns as shown. After importing the text file to matlab, I want to extract only one or two variables from it and relate that to MATLAB variable.
TIME Speed WheelSpeed Torque Torque_BPF etc
0.000 10.0000 3000.0000 10.0000 6.0000 .....
0.006 10.0000 3002.0000 10.0000 6.0000 .....
0.017 13.0000 3009.0000 08.0000 4.5000 .....
0.044 16.0000 3014.0000 13.0000 7.3000 .....

Accedi per commentare.


NDKA
NDKA il 26 Gen 2012
Walter, I think I got some solution. I used the following commands to load my *.txt file in to MATLAB.
1. load my_textfile.txt; 2. variable1 = my_textfile(:,1); % copy the 1st column from text file% 3. variable2 = my_textfile(:,2); % copy the 1st column from text file%
and it seems to work very file. And since I'm using the 'load' command. I had to remove all the header information present in the text file.
Thanks alot for your help.

Categorie

Scopri di più su Debugging and Analysis in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by