How to find a surface area for any plotted wave

Hi all, I am doing a project which involves plotting peaks values in a waveform and finding the surface area. I m done with plotting, can anyone give me the idea of how to find a surface area for any waveform.

 Réponse acceptée

Paulo Silva
Paulo Silva le 10 Mar 2011
doc trapz
doc cumtrapz

22 commentaires

santosh
santosh le 10 Mar 2011
Thanks for ur help,
I have tried with different wave forms but i m getting the same result. Can u pls help me
Paulo Silva
Paulo Silva le 10 Mar 2011
You have the sampling frequency (Fs) of the wav, time values (X) and amplitude of the wav (Y), you just need to calculate:
trapz(X,Y)/Fs
santosh
santosh le 10 Mar 2011
thanks for ur prompt reply paulo,
I dont have sampling frequency for each wave, I just have time and amplitude. Is it possible to get without the frequency or if no, then pls help me out to find the sampling frequency for each wave I choose.
Paulo Silva
Paulo Silva le 10 Mar 2011
Fs=1/(t(ind+1)-t(ind))
santosh
santosh le 10 Mar 2011
thnx paulo
I used the above function but it is showing me the error as
??? Error using ==> mrdivide
Matrix dimensions must agree.
Error in ==> trialdiff45matrix at 216
Z = cumtrapz(t(record2),1)/Fs;
Here is the figure code which i m using to plot and i trying to find the surface area of that wave, I used the matrices to plot this wave may be this is causing me the error. Pls have a look on this code
figure(7);
plot(t,Z2,t(record2),Z2(record2),'r*');
title('Averaged desired points found through Absolute Difference matrix');
Fs=1/(t(record2+1)-t(record2))
Z = trapz(t(record2),Z2(record2))/Fs
Paulo Silva
Paulo Silva le 11 Mar 2011
insert a . before / so the operations can be done element by element, I'm not sure about what your are doing. Fs should be a single value not a vector but with luck it could work.
Paulo Silva
Paulo Silva le 11 Mar 2011
Just in case you got different Fs values in a time vector (t) and you want to know the values do this:
unique(1./diff(t))
santosh
santosh le 11 Mar 2011
pls have a look on ur mail paulo I sent u the code and input file as well
Paulo Silva
Paulo Silva le 11 Mar 2011
I'm very sorry but I just can't help everyone that sends me emails, everyday someone sends their homework to my email but I have my own important things to do and the time spent here is already too much, it's better for you to put your questions and doubts here for all to see!
santosh
santosh le 11 Mar 2011
hello,
sorry for the mail.
I have large number of input files which consists of data in CSV format. Each data file has about 600 rows and 2 columns. So i want to find the surface area under the curve for each file after plotting. can u plz help me out.
Paulo Silva
Paulo Silva le 11 Mar 2011
The way I told you to calculate Fs, does it return one value of Fs for a given file data?
santosh
santosh le 11 Mar 2011
No, actually it is returning more values.
Paulo Silva
Paulo Silva le 11 Mar 2011
are the values very similar, if so average them and use that value for Fs
santosh
santosh le 11 Mar 2011
I tried taking average and i got one value. but getting same value for different data files
Paulo Silva
Paulo Silva le 11 Mar 2011
that means that all measurements used the same Fs don't you agree?
santosh
santosh le 11 Mar 2011
No all the measurments have variations even the surface area calculation:
Fs=1/(t(record2+1)-t(record2));
Q= mean(Fs);
Z = trapz(t(record2),Z2(record2))/Q;
for above variables the values are same for different measurments.
Paulo Silva
Paulo Silva le 11 Mar 2011
what's record2?
santosh
santosh le 11 Mar 2011
record2 is an index which contains time and voltage values
Paulo Silva
Paulo Silva le 11 Mar 2011
Try with cumtrapz
Fs=1/(t(record2+1)-t(record2));
Q= mean(Fs);
Z = cumtrapz(t(record2),Z2(record2))/Q;
santosh
santosh le 11 Mar 2011
I m getting the following output as
Z =
1.0e-010 *
0
-0.0102
-0.3311
-0.3460
-0.3568
-0.3329
0.0241
0.0460
>> Fs
Fs =
1.0e+006 *
0 0 0 0 0 0 0 5.0000
the above result is same for all the data files.
Paulo Silva
Paulo Silva le 11 Mar 2011
there's something wrong with your code, please check it, it's too late here, must go sleep a bit, good luck finding the error, bye
santosh
santosh le 11 Mar 2011
thnx alot for ur answers i will work out and catch u tomorrow gud nt.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by