Thread Subject: FFT -- sum( v(t)) /= sum (v(t))

Subject: FFT -- sum( v(t)) /= sum (v(t))

From: Travis Bland

Date: 2 Nov, 2009 23:39:02

Message: 1 of 10

Hi,
 I'm taking a course using Matlab, and i'm also doing data analysis for a job. Since i started using Matlab, i thought it might be easier to use than my program written in C++, and i was hoping to check the numbers against eachother.
I have a file data.dat with two columns, time and voltage. The sum v(t)^2 should equal the sum of v(f)^2, correct? I should have the same total power in the frequency domain as the time domain?
Well i can't get this to prove true. Here's what i tried

volt_t = data(:,2)

sum ( v(f)^2 ) --------->
>> sum( (fft(volt_t)) .* (fft(volt_t)) )
ans = 7.6598

sum( ( v(f)/ N )^2) ,where N = length volt_t-------->
>> sum( abs( (fft(volt_t) / N) .* (fft(volt_t) / N) ))
ans = 8.6741e-08

sum ( (v(t))^2)----------->
>> sum(volt_t .* volt_t)
ans = 0.0035




I notice when i read in the file to volt_t, the precision isn't very high. My values are #*e-06 , and matlab gives 0.0001 or 0.0000. Could this be my issue; if so, how do i fix it? If not, any suggestions on what to do?


 Thanks,
 Travis

Subject: FFT -- sum( v(t)) /= sum (v(t))

From: dpb

Date: 2 Nov, 2009 23:56:20

Message: 2 of 10

Travis Bland wrote:
> Hi,
...
> I notice when i read in the file to volt_t, the precision isn't very
> high. My values are #*e-06 , and matlab gives 0.0001 or 0.0000.
> Could this be my issue; if so, how do i fix it? If not, any
> suggestions on what to do?
>
ML uses default double for internal representation irrespective of what
the command window display format is.

Try

format long

or

format long e

to see full internal precision.

doc format % for more info

As for the fft normalization, w/ correct normalization you should find
all the energy, yes.

--

Subject: FFT -- sum( v(t)) /

From: TideMan

Date: 3 Nov, 2009 00:13:54

Message: 3 of 10

On Nov 3, 12:39 pm, "Travis Bland" <travisblan...@yahoo.com> wrote:
> Hi,
>  I'm taking a course using Matlab, and i'm also doing data analysis for a job. Since i started using Matlab, i thought it might be easier to use than my program written in C++, and i was hoping to check the numbers against eachother.
> I have a file data.dat with two columns, time and voltage. The sum  v(t)^2  should equal the sum of v(f)^2, correct? I should have the same total power in the frequency domain as the time domain?
> Well i can't get this to prove true. Here's what i tried
>
> volt_t = data(:,2)
>
> sum ( v(f)^2 )  --------->>> sum(   (fft(volt_t))  .* (fft(volt_t))   )
>
> ans = 7.6598
>
> sum(  ( v(f)/ N )^2) ,where N = length volt_t-------->>> sum(  abs( (fft(volt_t) / N)  .* (fft(volt_t) / N) ))
>
> ans = 8.6741e-08
>
> sum ( (v(t))^2)----------->>> sum(volt_t .* volt_t)
>
> ans = 0.0035
>
> I notice when i read in the file to volt_t, the precision isn't very high. My values are #*e-06 , and matlab gives   0.0001 or 0.0000. Could this be my issue; if so, how do i fix it? If not, any suggestions on what to do?
>
>  Thanks,
>  Travis

Try this:
N=10000;
y=randn(y,1);
[var(y) sum(abs(fft(y)/N).^2)]

Subject: FFT -- sum( v(t)) /

From: Travis Bland

Date: 3 Nov, 2009 03:35:04

Message: 4 of 10

TideMan <mulgor@gmail.com> wrote in message <18ca1852-949a-41c5-b2dd-0564cad82341@z4g2000prh.googlegroups.com>...
> On Nov 3, 12:39?pm, "Travis Bland" <travisblan...@yahoo.com> wrote:
> > Hi,
> > ?I'm taking a course using Matlab, and i'm also doing data analysis for a job. Since i started using Matlab, i thought it might be easier to use than my program written in C++, and i was hoping to check the numbers against eachother.
> > I have a file data.dat with two columns, time and voltage. The sum ?v(t)^2 ?should equal the sum of v(f)^2, correct? I should have the same total power in the frequency domain as the time domain?
> > Well i can't get this to prove true. Here's what i tried
> >
> > volt_t = data(:,2)
> >
> > sum ( v(f)^2 ) ?--------->>> sum( ? (fft(volt_t)) ?.* (fft(volt_t)) ? )
> >
> > ans = 7.6598
> >
> > sum( ?( v(f)/ N )^2) ,where N = length volt_t-------->>> sum( ?abs( (fft(volt_t) / N) ?.* (fft(volt_t) / N) ))
> >
> > ans = 8.6741e-08
> >
> > sum ( (v(t))^2)----------->>> sum(volt_t .* volt_t)
> >
> > ans = 0.0035
> >
> > I notice when i read in the file to volt_t, the precision isn't very high. My values are #*e-06 , and matlab gives ? 0.0001 or 0.0000. Could this be my issue; if so, how do i fix it? If not, any suggestions on what to do?
> >
> > ?Thanks,
> > ?Travis
>
> Try this:
> N=10000;
> y=randn(y,1);
> [var(y) sum(abs(fft(y)/N).^2)]
>





Wow, i didn't know you guys would respond so quick!!
Thanks dpb, that outputs the full length.
TideMan
how can i use y to declare y (y=randn(y,1)? It gives an error. I would normally just figure out what you meant to say... but since i'm new to matlab i can't quite figure out what that code is trying to do.
Also, my data.dat file is 40,004 long. I tried N = 40004 instead of length(volt) but it didn't help any.

Thanks for the quick reply!

Subject: FFT -- sum( v(t)) /

From: TideMan

Date: 3 Nov, 2009 06:21:32

Message: 5 of 10

On Nov 3, 4:35 pm, "Travis Bland" <travisblan...@yahoo.com> wrote:
> TideMan <mul...@gmail.com> wrote in message <18ca1852-949a-41c5-b2dd-0564cad82...@z4g2000prh.googlegroups.com>...
> > On Nov 3, 12:39?pm, "Travis Bland" <travisblan...@yahoo.com> wrote:
> > > Hi,
> > > ?I'm taking a course using Matlab, and i'm also doing data analysis for a job. Since i started using Matlab, i thought it might be easier to use than my program written in C++, and i was hoping to check the numbers against eachother.
> > > I have a file data.dat with two columns, time and voltage. The sum ?v(t)^2 ?should equal the sum of v(f)^2, correct? I should have the same total power in the frequency domain as the time domain?
> > > Well i can't get this to prove true. Here's what i tried
>
> > > volt_t = data(:,2)
>
> > > sum ( v(f)^2 ) ?--------->>> sum( ? (fft(volt_t)) ?.* (fft(volt_t)) ? )
>
> > > ans = 7.6598
>
> > > sum( ?( v(f)/ N )^2) ,where N = length volt_t-------->>> sum( ?abs( (fft(volt_t) / N) ?.* (fft(volt_t) / N) ))
>
> > > ans = 8.6741e-08
>
> > > sum ( (v(t))^2)----------->>> sum(volt_t .* volt_t)
>
> > > ans = 0.0035
>
> > > I notice when i read in the file to volt_t, the precision isn't very high. My values are #*e-06 , and matlab gives ? 0.0001 or 0.0000. Could this be my issue; if so, how do i fix it? If not, any suggestions on what to do?
>
> > > ?Thanks,
> > > ?Travis
>
> > Try this:
> > N=10000;
> > y=randn(y,1);
> > [var(y) sum(abs(fft(y)/N).^2)]
>
> Wow, i didn't know you guys would respond so quick!!
> Thanks dpb, that outputs the full length.
> TideMan
> how can i use y to declare y (y=randn(y,1)? It gives an error.  I would normally just figure out what you meant to say... but since i'm new to matlab i can't quite figure out what that code is trying to do.
> Also, my data.dat file is 40,004 long. I tried N = 40004 instead of length(volt) but it didn't help any.
>
> Thanks for the quick reply!

OOps
Typo. It should have read:
y=randn(N,1);

Subject: FFT -- sum( v(t)) /

From: Travis Bland

Date: 4 Nov, 2009 16:24:03

Message: 6 of 10

TideMan <mulgor@gmail.com> wrote in message <ab1631de-4e0f-4f32-88ef-7afb8935a075@f1g2000prf.googlegroups.com>...
> On Nov 3, 4:35?pm, "Travis Bland" <travisblan...@yahoo.com> wrote:
> > TideMan <mul...@gmail.com> wrote in message <18ca1852-949a-41c5-b2dd-0564cad82...@z4g2000prh.googlegroups.com>...
> > > On Nov 3, 12:39?pm, "Travis Bland" <travisblan...@yahoo.com> wrote:
> > > > Hi,
> > > > ?I'm taking a course using Matlab, and i'm also doing data analysis for a job. Since i started using Matlab, i thought it might be easier to use than my program written in C++, and i was hoping to check the numbers against eachother.
> > > > I have a file data.dat with two columns, time and voltage. The sum ?v(t)^2 ?should equal the sum of v(f)^2, correct? I should have the same total power in the frequency domain as the time domain?
> > > > Well i can't get this to prove true. Here's what i tried
> >
> > > > volt_t = data(:,2)
> >
> > > > sum ( v(f)^2 ) ?--------->>> sum( ? (fft(volt_t)) ?.* (fft(volt_t)) ? )
> >
> > > > ans = 7.6598
> >
> > > > sum( ?( v(f)/ N )^2) ,where N = length volt_t-------->>> sum( ?abs( (fft(volt_t) / N) ?.* (fft(volt_t) / N) ))
> >
> > > > ans = 8.6741e-08
> >
> > > > sum ( (v(t))^2)----------->>> sum(volt_t .* volt_t)
> >
> > > > ans = 0.0035
> >
> > > > I notice when i read in the file to volt_t, the precision isn't very high. My values are #*e-06 , and matlab gives ? 0.0001 or 0.0000. Could this be my issue; if so, how do i fix it? If not, any suggestions on what to do?
> >
> > > > ?Thanks,
> > > > ?Travis
> >
> > > Try this:
> > > N=10000;
> > > y=randn(y,1);
> > > [var(y) sum(abs(fft(y)/N).^2)]
> >
> > Wow, i didn't know you guys would respond so quick!!
> > Thanks dpb, that outputs the full length.
> > TideMan
> > how can i use y to declare y (y=randn(y,1)? It gives an error. ?I would normally just figure out what you meant to say... but since i'm new to matlab i can't quite figure out what that code is trying to do.
> > Also, my data.dat file is 40,004 long. I tried N = 40004 instead of length(volt) but it didn't help any.
> >
> > Thanks for the quick reply!
>
> OOps
> Typo. It should have read:
> y=randn(N,1);


alright, so that gives me the same value each time. But I'm not quite sure what it's doing. I fed my data into y
N= 40004;
y=data(:,2);
[var(y) sum(abs(fft(y)/N).^2)]

but that doesn't give me the same values.

ans =
  1.0e-007 *
    0.3966 0.4485

What did i do wrong?

Subject: FFT -- sum( v(t)) /

From: TideMan

Date: 4 Nov, 2009 18:51:31

Message: 7 of 10

On Nov 5, 5:24 am, "Travis Bland" <travisblan...@yahoo.com> wrote:
> TideMan <mul...@gmail.com> wrote in message <ab1631de-4e0f-4f32-88ef-7afb8935a...@f1g2000prf.googlegroups.com>...
> > On Nov 3, 4:35?pm, "Travis Bland" <travisblan...@yahoo.com> wrote:
> > > TideMan <mul...@gmail.com> wrote in message <18ca1852-949a-41c5-b2dd-0564cad82...@z4g2000prh.googlegroups.com>...
> > > > On Nov 3, 12:39?pm, "Travis Bland" <travisblan...@yahoo.com> wrote:
> > > > > Hi,
> > > > > ?I'm taking a course using Matlab, and i'm also doing data analysis for a job. Since i started using Matlab, i thought it might be easier to use than my program written in C++, and i was hoping to check the numbers against eachother.
> > > > > I have a file data.dat with two columns, time and voltage. The sum ?v(t)^2 ?should equal the sum of v(f)^2, correct? I should have the same total power in the frequency domain as the time domain?
> > > > > Well i can't get this to prove true. Here's what i tried
>
> > > > > volt_t = data(:,2)
>
> > > > > sum ( v(f)^2 ) ?--------->>> sum( ? (fft(volt_t)) ?.* (fft(volt_t)) ? )
>
> > > > > ans = 7.6598
>
> > > > > sum( ?( v(f)/ N )^2) ,where N = length volt_t-------->>> sum( ?abs( (fft(volt_t) / N) ?.* (fft(volt_t) / N) ))
>
> > > > > ans = 8.6741e-08
>
> > > > > sum ( (v(t))^2)----------->>> sum(volt_t .* volt_t)
>
> > > > > ans = 0.0035
>
> > > > > I notice when i read in the file to volt_t, the precision isn't very high. My values are #*e-06 , and matlab gives ? 0.0001 or 0.0000. Could this be my issue; if so, how do i fix it? If not, any suggestions on what to do?
>
> > > > > ?Thanks,
> > > > > ?Travis
>
> > > > Try this:
> > > > N=10000;
> > > > y=randn(y,1);
> > > > [var(y) sum(abs(fft(y)/N).^2)]
>
> > > Wow, i didn't know you guys would respond so quick!!
> > > Thanks dpb, that outputs the full length.
> > > TideMan
> > > how can i use y to declare y (y=randn(y,1)? It gives an error. ?I would normally just figure out what you meant to say... but since i'm new to matlab i can't quite figure out what that code is trying to do.
> > > Also, my data.dat file is 40,004 long. I tried N = 40004 instead of length(volt) but it didn't help any.
>
> > > Thanks for the quick reply!
>
> > OOps
> > Typo.  It should have read:
> > y=randn(N,1);
>
> alright, so that gives me the same value each time. But I'm not quite sure what it's doing. I fed my data into y
> N= 40004;
> y=data(:,2);
> [var(y) sum(abs(fft(y)/N).^2)]
>
> but that doesn't give me the same values.
>
> ans =
>   1.0e-007 *
>     0.3966                              0.4485
>
> What did i do wrong?

It assumes the mean is zero.
Do this first:
y=detrend(y,0);

Subject: FFT -- sum( v(t)) /= sum (v(t))

From: Matt

Date: 4 Nov, 2009 19:14:03

Message: 8 of 10

"Travis Bland" <travisbland88@yahoo.com> wrote in message <hcnqim$l20$1@fred.mathworks.com>...
> Hi,
> I'm taking a course using Matlab, and i'm also doing data analysis for a job. Since i started using Matlab, i thought it might be easier to use than my program written in C++, and i was hoping to check the numbers against eachother.
> I have a file data.dat with two columns, time and voltage. The sum v(t)^2 should equal the sum of v(f)^2, correct? I should have the same total power in the frequency domain as the time domain?
> Well i can't get this to prove true. Here's what i tried
>
> volt_t = data(:,2)
>
> sum ( v(f)^2 ) --------->
> >> sum( (fft(volt_t)) .* (fft(volt_t)) )
> ans = 7.6598
>
> sum( ( v(f)/ N )^2) ,where N = length volt_t-------->
> >> sum( abs( (fft(volt_t) / N) .* (fft(volt_t) / N) ))
> ans = 8.6741e-08

No. To properly normalize the fft to obtain equivalent energies, you must divide by
sqrt(N), not by N. Try the following for any N:


N=100;
a=rand(1,N);

norm(a),
norm(fft(a)/sqrt(N)),

Subject: FFT -- sum( v(t)) /

From: Greg Heath

Date: 5 Nov, 2009 01:12:09

Message: 9 of 10

On Nov 2, 6:39 pm, "Travis Bland" <travisblan...@yahoo.com> wrote:
> Hi,
>  I'm taking a course using Matlab, and i'm also doing data analysis for a job. Since i started using Matlab, i thought it might be easier to use than my program written in C++, and i was hoping to check the numbers against eachother.
> I have a file data.dat with two columns, time and voltage. The sum  v(t)^2  should equal the sum of v(f)^2, correct? I should have the same total power in the frequency domain as the time domain?
> Well i can't get this to prove true. Here's what i tried
>
> volt_t = data(:,2)
>
> sum ( v(f)^2 )  --------->>> sum(   (fft(volt_t))  .* (fft(volt_t))   )
>
> ans = 7.6598
>
> sum(  ( v(f)/ N )^2) ,where N = length volt_t-------->>> sum(  abs( (fft(volt_t) / N)  .* (fft(volt_t) / N) ))
>
> ans = 8.6741e-08
>
> sum ( (v(t))^2)----------->>> sum(volt_t .* volt_t)
>
> ans = 0.0035
>
> I notice when i read in the file to volt_t, the precision isn't very high. My values are #*e-06 , and matlab gives   0.0001 or 0.0000. Could this be my issue; if so, how do i fix it? If not, any suggestions on what to do?
>
>  Thanks,
>  Travis

Take a look at

http://groups.google.com/group/comp.soft-sys.matlab/msg/2222327db2ea7f51?hl=en

Hope this helps.

Greg

Subject: FFT -- sum( v(t)) /= sum (v(t))

From: Travis Bland

Date: 5 Nov, 2009 03:05:19

Message: 10 of 10




Matt " <xys@whatever.com> wrote in message
> No. To properly normalize the fft to obtain equivalent energies, you must divide by
> sqrt(N), not by N. Try the following for any N:
>
>
> N=100;
> a=rand(1,N);
>
> norm(a),
> norm(fft(a)/sqrt(N)),



THANKYOU MATT!! This is what i was looking for. I wondered if it just wasn't normalized correctly.
I had no clue what was going on in the other methods, i don't understand the need for all of the functions... i thought this was a simple thing... sum v(t) = sum v(f)


But interestingly enough, i wrote my own function to sum the two arrays, and when i used this code... i got the two values to be the same... and i normalized using N. There must be something going on internally somewhere that i don't understand.


load std000.txt
volt = std000(:,2);
v_s = 0;
for n = 1:40004
   v_s = (volt(n).* volt(n)) + v_s ; %sum of v(t)
end

v_f = (fft(volt));
v_f_s = 0;

for b = 1:40004

   v_f_s = v_f_s + (abs((v_f(b) .* v_f(b))/ 40004));
end
v_s %sum of v(t)
v_f_s % sum of v(f)




but thanks to everyone

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
orthonormalizin... Matt 5 Nov, 2009 01:52:45
rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com