Re: [Matplotlib-users] semilogy question

2007-10-25 Thread Bernhard Voigt
A simple solution would be:

numbers, text = yticks()
mytext = ['%.2f' % n for n in numbers]
yticks(numbers, mytext)

If you need fancier formatting look at Ticker and Formatter API
http://matplotlib.sourceforge.net/matplotlib.ticker.html
For sure there's something about this in the examples as well.

Best! Bernhard

On 10/23/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
> Hi guys.
> I'm just a newbie at matplotlib. I couldn't find the answer on my
> quistion in project's docs.
> I've wrote the following code:
> from pylab import *
> semilogy([1, 5, 2, 3, 1, 6], basey=2)
> show()
>
>
> It works OK but I'd like to see usual decimal numbers instead of 2^0,
> 2^1, 2^2 ... on y axis.
> How can I do that?
> Thnx.
>
> -
> This SF.net email is sponsored by: Splunk Inc.
> Still grepping through log files to find problems?  Stop.
> Now Search log events and configuration files using AJAX and a browser.
> Download your FREE copy of Splunk now >> http://get.splunk.com/
> ___
> Matplotlib-users mailing list
> Matplotlib-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
-
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] Grid Shifting in PS backend

2007-10-25 Thread David D Clark
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Hello folks,

I have a Gaussian peak centered on zero.  When the plot is drawn on
screen with the GTKAgg backend, the peak is shown in the correct place.
 When I either click on the disk icon and save the plot as eps or use
savefig, the peak is shifted to the left of zero by several x axis units.

I am using Python 2.5 with matplotlib 0.90.1 and numpy 1.0.3. and scipy
0.5.1 in my script.  These are running on my Fedora 7 box. I compiled
and installed mpl 0.90.1 this morning because I noticed this behavior
with python-matplotlib-0.90.0 that I had installed with yum.  I also see
this behavior if I run my script from the command line and from ipython
0.8.1.

When I save using PNG, the peak is in the correct place.  My Mac also
saves both EPS and PNG correctly.

Any thoughts?
Dave

- --
David D. Clark
Electrical Engineer
P-23, Neutron Science and Technology
e-mail mailto:[EMAIL PROTECTED]
GPG Public key 0x018D6523 available at http://pgp.mit.edu
http://www.gnupg.org has information about public key cryptography

-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.7 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org

iD8DBQFHIOunNu7GcwGNZSMRAlKnAJ46KFuJVNN0rC6EHgredtUHYZyvdQCgqQNG
OiwS8VN/qZ1ula37vDP7Q88=
=/1De
-END PGP SIGNATURE-

-
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] bug or problem in my configuration

2007-10-25 Thread Michael Droettboom
Darren Dale wrote:
> Hi Mike,
> 
> On Tuesday 23 October 2007 09:05:56 am Michael Droettboom wrote:
>> Unfortunately, I can't reproduce this on my machine even with the latest
>> stable version of freetype-2.5.3 (which is the same version in Ubuntu
>> Gutsy).
> 
> I think you mean freetype-2.3.5. I also have that version installed, although 
> the mpl setup script is reporting 9.16.3.

Yes.  freetype-2.3.5.  There are arcane historical reasons I don't fully 
comprehend why the pkgconfig version doesn't match the release version 
(and why freetype2 is called freetype6 on Debian and derivatives)... 
but my numbers do match yours.

>> The Ubuntu/Debian package of freetype has a lot of patches 
>> applied, and I don't know if they are causing this (but from the looks
>> of them, I doubt it).
>>
>> Can you set debug.verbose to "annoying" and send me the output of your
>> matplotlib run?  I want to rule out any font-loading problems.
> 
> It's attached. I'm running 64bit gentoo, everything compiled with gcc-4.2.2, 
> in case its relevent.

Always good to have more details, but I'm sort of at a loss on this one, 
especially since I can't reproduce it.

Maybe we need to take a poll on this list of who is working and who 
isn't to see what the source of the breakage may be...

Cheers,
Mike

>> Michael Droettboom wrote:
>>> I can't reproduce this bug on my own machine with SVN head.  I suspect
>>> this is freetype2 related -- that's the library that actually performs
>>> the rendering of the characters for the Agg backend.  The fact the
>>> humufr saw this after upgrading to Gutsy suggests there might have been
>>>   change to freetype that is now revealing possibly an incorrect usage
>>> in matplotlib.  Can you please send the version of freetype you are
>>> using?  (pkg-config --modversion freetype2)
>>>
>>> My machine has the (fairly old) 2.1.9.
>>>
>>> I'm going to try installing the latest freetype and see if I can
>>> reproduce this bug.
>>>
>>> [I believe this is an instance of the same bug that Darren sent me
>>> off-list.]
>>>
>>> Cheers,
>>> Mike
>>>
>>> [EMAIL PROTECTED] wrote:
 Sorry I didn't know the difference...

 N.

 Le Friday 19 October 2007 10:52:25 Darren Dale, vous avez écrit :
> On Friday 19 October 2007 10:38:36 am [EMAIL PROTECTED] wrote:
>> Le Friday 19 October 2007 08:37:00 Darren Dale, vous avez écrit :
>>> On Thursday 18 October 2007 11:49:50 am [EMAIL PROTECTED] wrote:
Hi,

 I have a small problem with label.


 plot([0,1],[0,1])
 xlabel(r'$ABCDEF$',fontsize=35)

 (but the size doesn't change anything) I obtain the result visible
 on the figure join. I think there are a problem when using latex and
 how the first character is handle.
>>> I don't think its a problem with matplotlib; I can't reproduce the
>>> problem on my machine. Maybe its an issue with your dvipng? I'm using
>>> version 1.9.
>> Oups I found the problem, I don't know why because it was working fine
>> before the upgrade to gutsy but I have to change matplotlib
>> configuration and everything is working fine if I put in the file:
>>
>> rc('text', usetex=True)
> In your first email you said you were using latex, but you were
> actually using mathtext. I can confirm the problem when I disable
> usetex and instead use mathtext. Mike, is this something easy to fix?
>
> Darren
 
 - This SF.net email is sponsored by: Splunk Inc.
 Still grepping through log files to find problems?  Stop.
 Now Search log events and configuration files using AJAX and a browser.
 Download your FREE copy of Splunk now >> http://get.splunk.com/
 ___
 Matplotlib-users mailing list
 Matplotlib-users@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/matplotlib-users
> 
> 
> 

-- 
Michael Droettboom
Science Software Branch
Operations and Engineering Division
Space Telescope Science Institute
Operated by AURA for NASA

-
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] bug or problem in my configuration

2007-10-25 Thread humufr
Yep that can be a good idea. I don't know anything on how mathtext is working 
but I'm not completely sure that the problem is with freetype because 
sometime that can work. In reality every character I tested worked but you 
have to put in a certain order. To understand a little bit more what I try to 
say (very badly) see the script join and the figure. 
 
I hope that can help a little bit to try to find the reason of this behaviour.

N

Le Thursday 25 October 2007 15:41:40 Michael Droettboom, vous avez écrit :
> Darren Dale wrote:
> > Hi Mike,
> >
> > On Tuesday 23 October 2007 09:05:56 am Michael Droettboom wrote:
> >> Unfortunately, I can't reproduce this on my machine even with the latest
> >> stable version of freetype-2.5.3 (which is the same version in Ubuntu
> >> Gutsy).
> >
> > I think you mean freetype-2.3.5. I also have that version installed,
> > although the mpl setup script is reporting 9.16.3.
>
> Yes.  freetype-2.3.5.  There are arcane historical reasons I don't fully
> comprehend why the pkgconfig version doesn't match the release version
> (and why freetype2 is called freetype6 on Debian and derivatives)...
> but my numbers do match yours.
>
> >> The Ubuntu/Debian package of freetype has a lot of patches
> >> applied, and I don't know if they are causing this (but from the looks
> >> of them, I doubt it).
> >>
> >> Can you set debug.verbose to "annoying" and send me the output of your
> >> matplotlib run?  I want to rule out any font-loading problems.
> >
> > It's attached. I'm running 64bit gentoo, everything compiled with
> > gcc-4.2.2, in case its relevent.
>
> Always good to have more details, but I'm sort of at a loss on this one,
> especially since I can't reproduce it.
>
> Maybe we need to take a poll on this list of who is working and who
> isn't to see what the source of the breakage may be...
>
> Cheers,
> Mike
<>

test_mathtext.py
Description: application/python
-
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] PSD amplitudes

2007-10-25 Thread Joseph Park




Please try the attached script.
The answer should be ~0 dB for each of the frequencies.
Most likely a simple scaling issue/parameter of which i'm ignorant.

-- 



##
## Name: psd_scale.py
## 
## Purpose:  Test Power Spectral Density of 1Vrms data
##   Depends on Python SciPy and NumPy
## 
## Author:   J Park
##
## Created:  10/17/07
##
## Modified: 
##

try:
from numpy import *  # www.numpy.org numpy.scipy.org
except ImportError: 
print "Failed to import numpy."

try:
import pylab as mp  # matplotlib.sourceforge.net
from matplotlib.font_manager import fontManager, FontProperties 
except ImportError: 
print "Failed to import pylab."


# Default Parameters
nFFT  = 1024 
overlap   = 512  
freqSample= 100. 
PlotAll   = False
WriteOutput   = False

##
## Main module
def main():

deltaF = freqSample/nFFT # Frequency resolution in Hz
deltaT = 1./freqSample   # Sample interval
print 'Sample interval %e (s)'   % (deltaT)
print 'Frequency resolution %e (Hz)' % (deltaF)

# Setup Plots
# --
mp.figure(1)
mp.title ( "PSD" )
mp.ylabel( "(dB)" )
mp.xlabel( "Frequency (Hz)" )
legendFont = FontProperties(size='small')

ymin = 0
ymax = 30
xmin = 0
xmax = 50
xticks = 5
yticks = 5

if PlotAll:
mp.figure(2)
mp.title ( "Input Timeseries" )
mp.ylabel( "Amplitude" )
mp.xlabel( "time (s)" )

# Create some synthetic data with unity RMS amplitude = 0 dB
# --
t = mp.arange(0., 60., deltaT) # 60 seconds at deltaT interval
A = 1.414

y0 = A * sin( 2. * math.pi * 5  * t )
y1 = A * sin( 2. * math.pi * 10 * t )
y2 = A * sin( 2. * math.pi * 20 * t )
y3 = A * sin( 2. * math.pi * 30 * t )
y4 = A * sin( 2. * math.pi * 40 * t )
y5 = A * sin( 2. * math.pi * 45 * t )

dataList = [ y0, y1, y2, y3, y4, y5 ]

for data in dataList:
inputDataLen = len( data )
numAverages  = math.floor( inputDataLen / (overlap) ) - 1
normalizedRandomError = 1./math.sqrt( numAverages )
print "%d points" % ( inputDataLen ),
print "%d averages" % (numAverages),
print "normalized random error %.3f" % ( normalizedRandomError )

mp.figure(1)
(Pxx, freqs) = mp.psd( data,
   NFFT = nFFT,
   Fs   = freqSample,
   noverlap = overlap,
   lw   = 2,
   label= '' )

Pxx_dB = 10.*log10(Pxx)

if PlotAll:
mp.figure(2)
mp.plot(t, data, label='' )

# Write Output data
# --
if WriteOutput:
PxxLen = len(Pxx)
OutputFile = "PSD.dat"
fdOutFile = open( OutputFile, 'a' )
fdOutFile.write( "Freq\t\tPower(dB)\n" )
for i in range(PxxLen):
fdOutFile.write( "%.4e\t%.3f\n" % ( freqs[i], Pxx_dB[i] ) )
fdOutFile.close()
print "Wrote ", PxxLen, " points to ", OutputFile


# Show the Plot
# --
mp.figure(1)
mp.axis([xmin, xmax, ymin, ymax])
mp.xticks( arange(xmin, xmax+1, xticks) )
mp.yticks( arange(ymin, ymax  , yticks) )
mp.title('')
mp.xlabel('Frequency (Hz)')
mp.ylabel(r'$\tt{dB re V^2/Hz}$')
#mp.legend( loc='upper right', prop=legendFont )
if WriteOutput:
plotFileName = "PSD.png"
mp.savefig( plotFileName )
print "Wrote png image to ", plotFileName
if PlotAll:
mp.figure(2)
#mp.legend( loc='lower left', prop=legendFont )
mp.show()

print "Normal Exit"
## Main module
##

##
## Provide for cmd line invocation
if __name__ == "__main__":
main()

-
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/m

[Matplotlib-users] Fw: PSD amplitudes

2007-10-25 Thread brett . mcsweeney
Are you sure that the answer should be zero?  Shouldn't the PSD for a 
simple sine wave tend to infinity (depending on the resolution)?





Joseph Park <[EMAIL PROTECTED]> 
Sent by: [EMAIL PROTECTED]
26/10/2007 06:50 AM

To
matplotlib-users@lists.sourceforge.net
cc

Subject
[Matplotlib-users] PSD amplitudes






Please try the attached script.
The answer should be ~0 dB for each of the frequencies.
Most likely a simple scaling issue/parameter of which i'm ignorant.

-- 


__
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
__
##
## Name: psd_scale.py
## 
## Purpose:  Test Power Spectral Density of 1Vrms data
##   Depends on Python SciPy and NumPy
## 
## Author:   J Park
##
## Created:  10/17/07
##
## Modified: 
##

try:
from numpy import *  # www.numpy.org numpy.scipy.org
except ImportError: 
print "Failed to import numpy."
 
try:
import pylab as mp  # matplotlib.sourceforge.net
from matplotlib.font_manager import fontManager, FontProperties 
except ImportError: 
print "Failed to import pylab."
 

# Default Parameters
nFFT  = 1024 
overlap   = 512 
freqSample= 100. 
PlotAll   = False
WriteOutput   = False

##
## Main module
def main():

deltaF = freqSample/nFFT # Frequency resolution in Hz
deltaT = 1./freqSample   # Sample interval
print 'Sample interval %e (s)'   % (deltaT)
print 'Frequency resolution %e (Hz)' % (deltaF)

# Setup Plots
# 
--
mp.figure(1)
mp.title ( "PSD" )
mp.ylabel( "(dB)" )
mp.xlabel( "Frequency (Hz)" )
legendFont = FontProperties(size='small')

ymin = 0
ymax = 30
xmin = 0
xmax = 50
xticks = 5
yticks = 5

if PlotAll:
mp.figure(2)
mp.title ( "Input Timeseries" )
mp.ylabel( "Amplitude" )
mp.xlabel( "time (s)" )

# Create some synthetic data with unity RMS amplitude = 0 dB
# 
--
t = mp.arange(0., 60., deltaT) # 60 seconds at deltaT interval
A = 1.414
 
y0 = A * sin( 2. * math.pi * 5  * t )
y1 = A * sin( 2. * math.pi * 10 * t )
y2 = A * sin( 2. * math.pi * 20 * t )
y3 = A * sin( 2. * math.pi * 30 * t )
y4 = A * sin( 2. * math.pi * 40 * t )
y5 = A * sin( 2. * math.pi * 45 * t )

dataList = [ y0, y1, y2, y3, y4, y5 ]
 
for data in dataList:
inputDataLen = len( data )
numAverages  = math.floor( inputDataLen / (overlap) ) - 1
normalizedRandomError = 1./math.sqrt( numAverages )
print "%d points" % ( inputDataLen ),
print "%d averages" % (numAverages),
print "normalized random error %.3f" % ( normalizedRandomError )

mp.figure(1)
(Pxx, freqs) = mp.psd( data,
   NFFT = nFFT,
   Fs   = freqSample,
   noverlap = overlap,
   lw   = 2,
   label= '' )

Pxx_dB = 10.*log10(Pxx)
 
if PlotAll:
mp.figure(2)
mp.plot(t, data, label='' )

# Write Output data
# 
--
if WriteOutput:
PxxLen = len(Pxx)
OutputFile = "PSD.dat"
fdOutFile = open( OutputFile, 'a' )
fdOutFile.write( "Freq\t\tPower(dB)\n" )
for i in range(PxxLen):
fdOutFile.write( "%.4e\t%.3f\n" % ( freqs[i], Pxx_dB[i] ) 
)
fdOutFile.close()
print "Wrote ", PxxLen, " points to ", OutputFile
 

# Show the Plot
# 
--
mp.figure(1)
mp.axis([xmin, xmax, ymin, ymax])
mp.xticks( arange(xmin, xmax+1, xticks) )
mp.yticks( arange(ymin, ymax  , yticks) )
mp.title('')
mp.xlabel('Frequency (Hz)')
mp.ylabel(r'$\tt{dB re V^2/Hz}$')
#mp.legend( loc='upper right', prop=legendFont )
if WriteOutput:
plotFileName = "PSD.png"
mp.savefig( plotFileName )
print "Wrote png image to ", plotFileName
if PlotAll:
mp.figure(2)
#mp.legend( loc='lower left', prop=legendFont )
mp.show()

print "Normal Exit"
## Main module
##

##
## Provide for

Re: [Matplotlib-users] PSD amplitudes

2007-10-25 Thread Joseph Park




Shouldn't the PSD for a simple sine
wave tend to infinity

the spectral resolution
will impact the amplitude, if you
are not dealing with a density. by definition a spectral density
has applied the bandwidth resolution correction. the PSD amplitude
should correspond to the RMS amplitude of the sine wave. in the
example a 1VRMS amplitude sine wave (time domain) should have a
PSD power of 20*log(1V) = 0dB. The windowing function will impact
this ideal number a bit, but certainly not by 25dB.

[EMAIL PROTECTED] wrote:

  Are you sure that the answer should
be zero?  Shouldn't the PSD for a simple sine wave tend to infinity
(depending on the resolution)?
  
  
  
  
  
  

  
Joseph Park
<[EMAIL PROTECTED]>

Sent by:
[EMAIL PROTECTED]
26/10/2007 06:50 AM




  

  
  To
  
  matplotlib-users@lists.sourceforge.net
  


  
  cc
  
  
  


  
  Subject
  
  [Matplotlib-users]
PSD amplitudes

  



  

  
  
  
  
  

  



  

  
  
  
  
  Please try the attached script.
The answer should be ~0 dB for each of the frequencies.
Most likely a simple scaling issue/parameter of which i'm ignorant.
  
  
  -- 
  
  
  
__
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
__##
## Name:     psd_scale.py
##             
## Purpose:  Test Power Spectral Density of 1Vrms data
##           Depends on Python SciPy and NumPy
##             
## Author:       J Park
##
## Created:      10/17/07
##
## Modified:     
##
  
try:
   from numpy import *  # www.numpy.org numpy.scipy.org
except ImportError: 
   print "Failed to import numpy."
   
try:
   import pylab as mp  # matplotlib.sourceforge.net
   from matplotlib.font_manager import fontManager, FontProperties
  
except ImportError: 
   print "Failed to import pylab."
   
  
# Default Parameters
nFFT          = 1024 
overlap       = 512  
freqSample    = 100. 
PlotAll       = False
WriteOutput   = False
  
##
## Main module
def main():
  
   deltaF = freqSample/nFFT # Frequency resolution in Hz
   deltaT = 1./freqSample   # Sample interval
   print 'Sample interval %e (s)'       % (deltaT)
   print 'Frequency resolution %e (Hz)' % (deltaF)
  
   # Setup Plots
   #
--
   mp.figure(1)
   mp.title ( "PSD" )
   mp.ylabel( "(dB)" )
   mp.xlabel( "Frequency (Hz)" )
   legendFont = FontProperties(size='small')
  
   ymin = 0
   ymax = 30
   xmin = 0
   xmax = 50
   xticks = 5
   yticks = 5
  
   if PlotAll:
       mp.figure(2)
       mp.title ( "Input Timeseries" )
       mp.ylabel( "Amplitude" )
       mp.xlabel( "time (s)" )
  
   # Create some synthetic data with unity RMS amplitude = 0
dB
   #
--
   t = mp.arange(0., 60., deltaT) # 60 seconds at deltaT interval
   A = 1.414
   
   y0 = A * sin( 2. * math.pi * 5  * t )
   y1 = A * sin( 2. * math.pi * 10 * t )
   y2 = A * sin( 2. * math.pi * 20 * t )
   y3 = A * sin( 2. * math.pi * 30 * t )
   y4 = A * sin( 2. * math.pi * 40 * t )
   y5 = A * sin( 2. * math.pi * 45 * t )
  
   dataList = [ y0, y1, y2, y3, y4, y5 ]
   
   for data in dataList:
       inputDataLen = len( data )
       numAverages  = math.floor( inputDataLen
/ (overlap) ) - 1
       normalizedRandomError = 1./math.sqrt( numAverages
)
       print "%d points" % ( inputDataLen
),
       print "%d averages" % (numAverages),
       print "normalized random error %.3f"
% ( normalizedRandomError )
  
       mp.figure(1)
       (Pxx, freqs) = mp.psd( data,
                   
          NFFT     = nFFT,
                   
          Fs       = freqSample,
                   
          noverlap = overlap,
                   
          lw       = 2,
                   
          label    = '' )
  
       Pxx_dB = 10.*log10(Pxx)
       
       if PlotAll:
           mp.figure(2)
           mp.plot(t, data, label='' )
  
       # Write Output data
       #
--
       if WriteOutput:
           PxxLen = len(Pxx)
           OutputFile = "PSD.dat"
           fdO

Re: [Matplotlib-users] PSD amplitudes

2007-10-25 Thread brett . mcsweeney
If you lower the resolution (ie increase nFFT) in your program you will 
see that the PSD does indeed increase.  I think it may be on the way to 
infinity.





Joseph Park <[EMAIL PROTECTED]> 
Sent by: [EMAIL PROTECTED]
26/10/2007 10:05 AM

To
matplotlib-users@lists.sourceforge.net
cc

Subject
Re: [Matplotlib-users] PSD amplitudes






Shouldn't the PSD for a simple sine wave tend to infinity

the spectral resolution will impact the amplitude, if you
are not dealing with a density. by definition a spectral density
has applied the bandwidth resolution correction. the PSD amplitude
should correspond to the RMS amplitude of the sine wave. in the
example a 1VRMS amplitude sine wave (time domain) should have a
PSD power of 20*log(1V) = 0dB. The windowing function will impact
this ideal number a bit, but certainly not by 25dB.

[EMAIL PROTECTED] wrote: 

Are you sure that the answer should be zero?  Shouldn't the PSD for a 
simple sine wave tend to infinity (depending on the resolution)? 




Joseph Park <[EMAIL PROTECTED]> 
Sent by: [EMAIL PROTECTED] 
26/10/2007 06:50 AM 


To
matplotlib-users@lists.sourceforge.net 
cc

Subject
[Matplotlib-users] PSD amplitudes








Please try the attached script.
The answer should be ~0 dB for each of the frequencies.
Most likely a simple scaling issue/parameter of which i'm ignorant.

-- 


__
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
__
##
## Name: psd_scale.py
## 
## Purpose:  Test Power Spectral Density of 1Vrms data
##   Depends on Python SciPy and NumPy
## 
## Author:   J Park
##
## Created:  10/17/07
##
## Modified: 
##

try:
   from numpy import *  # www.numpy.org numpy.scipy.org
except ImportError: 
   print "Failed to import numpy."
 
try:
   import pylab as mp  # matplotlib.sourceforge.net
   from matplotlib.font_manager import fontManager, FontProperties 
except ImportError: 
   print "Failed to import pylab."
 

# Default Parameters
nFFT  = 1024 
overlap   = 512 
freqSample= 100. 
PlotAll   = False
WriteOutput   = False

##
## Main module
def main():

   deltaF = freqSample/nFFT # Frequency resolution in Hz
   deltaT = 1./freqSample   # Sample interval
   print 'Sample interval %e (s)'   % (deltaT)
   print 'Frequency resolution %e (Hz)' % (deltaF)

   # Setup Plots
   # 
--
   mp.figure(1)
   mp.title ( "PSD" )
   mp.ylabel( "(dB)" )
   mp.xlabel( "Frequency (Hz)" )
   legendFont = FontProperties(size='small')

   ymin = 0
   ymax = 30
   xmin = 0
   xmax = 50
   xticks = 5
   yticks = 5

   if PlotAll:
   mp.figure(2)
   mp.title ( "Input Timeseries" )
   mp.ylabel( "Amplitude" )
   mp.xlabel( "time (s)" )

   # Create some synthetic data with unity RMS amplitude = 0 dB
   # 
--
   t = mp.arange(0., 60., deltaT) # 60 seconds at deltaT interval
   A = 1.414
 
   y0 = A * sin( 2. * math.pi * 5  * t )
   y1 = A * sin( 2. * math.pi * 10 * t )
   y2 = A * sin( 2. * math.pi * 20 * t )
   y3 = A * sin( 2. * math.pi * 30 * t )
   y4 = A * sin( 2. * math.pi * 40 * t )
   y5 = A * sin( 2. * math.pi * 45 * t )

   dataList = [ y0, y1, y2, y3, y4, y5 ]
 
   for data in dataList:
   inputDataLen = len( data )
   numAverages  = math.floor( inputDataLen / (overlap) ) - 1
   normalizedRandomError = 1./math.sqrt( numAverages )
   print "%d points" % ( inputDataLen ),
   print "%d averages" % (numAverages),
   print "normalized random error %.3f" % ( normalizedRandomError )

   mp.figure(1)
   (Pxx, freqs) = mp.psd( data,
  NFFT = nFFT,
  Fs   = freqSample,
  noverlap = overlap,
  lw   = 2,
  label= '' )

   Pxx_dB = 10.*log10(Pxx)
 
   if PlotAll:
   mp.figure(2)
   mp.plot(t, data, label='' )

   # Write Output data
   # 
--
   if WriteOutput:
   PxxLen = len(Pxx)
   OutputFile = "PSD.dat"
   fdOutFile = open( OutputFile, 'a' )
   fdOutFile.write( "Freq\t\tPower(dB)\n" )
   for i in range(PxxLen):
   fdOutFile.write( "%.4e\t%.3f\n" % ( freqs[i], Pxx_dB[i] ) )
   fdOutFile.close()
   print "Wrote ", PxxLen, " points to ", OutputFile
 

   # Show the Plot
   # 
-

Re: [Matplotlib-users] PSD amplitudes

2007-10-25 Thread Joseph Park




is the suggestion that the matplotlib
algorithm is correct in computing PSD amplitudes?

btw, increasing nFFT increases the number of points used in the FFT,
which 
increases the spectral frequency resolution (smaller binwidth)
but for a limited data set
of N points, as is the case in the example, decreases the number of
data averages 
thereby decreasing the spectral amplitude resolution
(accuracy). keep in mind that
just changing nFFT without making a corresponding change in overlap
will oversample
the data, thereby skewing the amplitudes. 

in any case, the amplitude change is not approaching infinity, even if
you set nFFT to
6000, which is the length of the timeseries, the amplitudes are ~35dB,
adjust variable ymax
to see this. 

to review issues of spectral/amplitude resolution, windowing/overlap,
etc, a good
reference is Random Data by Bendat  &Piersol:
http://www.amazon.com/Random-Data-Analysis-Measurement-Procedures/dp/0471317330

i remain unconvinced that the PSD amplitudes are reasonable, which only
leaves Matlab
as an alternative... that's a hard pill to swallow... matplotlib is
clearly preferable.


[EMAIL PROTECTED] wrote:

  If you lower the resolution (ie
increase
nFFT) in your program you will see that the PSD does indeed increase.
 I
think it may be on the way to infinity.
  
  
  
  
  
  

  
Joseph Park
<[EMAIL PROTECTED]>

Sent by:
[EMAIL PROTECTED]
26/10/2007 10:05 AM




  

  
  To
  
  matplotlib-users@lists.sourceforge.net
  


  
  cc
  
  
  


  
  Subject
  
  Re:
[Matplotlib-users] PSD amplitudes

  



  

  
  
  
  
  

  



  

  
  
  
  
  Shouldn't the PSD
for
a simple sine wave tend to infinity
  
the spectral resolution will impact the amplitude, if you
are not dealing with a density. by definition a spectral density
has applied the bandwidth resolution correction. the PSD amplitude
should correspond to the RMS amplitude of the sine wave. in the
example a 1VRMS amplitude sine wave (time domain) should have a
PSD power of 20*log(1V) = 0dB. The windowing function will impact
this ideal number a bit, but certainly not by 25dB.
  
  [EMAIL PROTECTED]
wrote: 
  
  
Are you sure that the answer should be zero?  Shouldn't the PSD for
a simple sine wave tend to infinity (depending on the resolution)?
  
  
  
  
  
  

  
Joseph
Park
<[EMAIL PROTECTED]>

Sent by: [EMAIL PROTECTED]

26/10/2007
06:50 AM




  

  
  To
  
  matplotlib-users@lists.sourceforge.net
  


  
  cc
  
  
  


  
  Subject
  
  [Matplotlib-users]
PSD
amplitudes

  




  

  
  
  
  
  

  



  

  
  
  
  
  
Please try the attached script.
The answer should be ~0 dB for each of the frequencies.
Most likely a simple scaling issue/parameter of which i'm ignorant.
  
-- 
  
  
__
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email
  
__##
## Name:     psd_scale.py
##             
## Purpose:  Test Power Spectral Density of 1Vrms data
##           Depends on Python SciPy and NumPy
##             
## Author:       J Park
##
## Created:      10/17/07
##
## Modified:     
##
  
try:
  from numpy import *  # www.numpy.org
numpy.scipy.org
except ImportError: 
  print "Failed to import numpy."
  
try:
  import pylab as mp  # matplotlib.sourceforge.net
  from matplotlib.font_manager import fontManager, FontProperties
  
except ImportError: 
  print "Failed to import pylab."
  
  
# Default Parameters
nFFT          = 1024 
overlap       = 512  
freqSample    = 100. 
PlotAll       = False
WriteOutput   = False
  
##
## Main module
def main():
  
  deltaF = freqSample/nFFT # Frequency resolution in Hz

Re: [Matplotlib-users] PSD amplitudes

2007-10-25 Thread brett . mcsweeney
There is certainly differences (usually of a factor of PI) in the various 
definitions used for PSDs, but a simple sign wave has an infinite power 
density at the sine wave frequency.  Are we agreed on that?

Use of windowing will modify this comment somewhat (so it probably won't 
really go to infinity) but the basic fact remains.  The units of a PSD are 
amp^2/Hz.  The MS of a signal between two frequencies should equal the 
area under the PSD between those frequencies (with allowance for different 
definitions/factors of PI).  As I said, for a sign wave the frequency band 
can be made arbitrarily small about the sine wave frequency, but the power 
between these bands remains constant.  Therefore the PSD goes to infinity. 
 Otherwise it isn't a density.





Joseph Park <[EMAIL PROTECTED]> 
Sent by: [EMAIL PROTECTED]
26/10/2007 10:49 AM

To

cc
matplotlib-users@lists.sourceforge.net
Subject
Re: [Matplotlib-users] PSD amplitudes






is the suggestion that the matplotlib algorithm is correct in computing 
PSD amplitudes?

btw, increasing nFFT increases the number of points used in the FFT, which 

increases the spectral frequency resolution (smaller binwidth) but for a 
limited data set
of N points, as is the case in the example, decreases the number of data 
averages 
thereby decreasing the spectral amplitude resolution (accuracy). keep in 
mind that
just changing nFFT without making a corresponding change in overlap will 
oversample
the data, thereby skewing the amplitudes. 

in any case, the amplitude change is not approaching infinity, even if you 
set nFFT to
6000, which is the length of the timeseries, the amplitudes are ~35dB, 
adjust variable ymax
to see this. 

to review issues of spectral/amplitude resolution, windowing/overlap, etc, 
a good
reference is Random Data by Bendat  &Piersol:
http://www.amazon.com/Random-Data-Analysis-Measurement-Procedures/dp/0471317330


i remain unconvinced that the PSD amplitudes are reasonable, which only 
leaves Matlab
as an alternative... that's a hard pill to swallow... matplotlib is 
clearly preferable.


[EMAIL PROTECTED] wrote: 

If you lower the resolution (ie increase nFFT) in your program you will 
see that the PSD does indeed increase.  I think it may be on the way to 
infinity. 




Joseph Park <[EMAIL PROTECTED]> 
Sent by: [EMAIL PROTECTED] 
26/10/2007 10:05 AM 


To
matplotlib-users@lists.sourceforge.net 
cc

Subject
Re: [Matplotlib-users] PSD amplitudes








Shouldn't the PSD for a simple sine wave tend to infinity

the spectral resolution will impact the amplitude, if you
are not dealing with a density. by definition a spectral density
has applied the bandwidth resolution correction. the PSD amplitude
should correspond to the RMS amplitude of the sine wave. in the
example a 1VRMS amplitude sine wave (time domain) should have a
PSD power of 20*log(1V) = 0dB. The windowing function will impact
this ideal number a bit, but certainly not by 25dB.

[EMAIL PROTECTED] wrote: 

Are you sure that the answer should be zero?  Shouldn't the PSD for a 
simple sine wave tend to infinity (depending on the resolution)? 



Joseph Park <[EMAIL PROTECTED]> 
Sent by: [EMAIL PROTECTED] 
26/10/2007 06:50 AM 


To
matplotlib-users@lists.sourceforge.net 
cc

Subject
[Matplotlib-users] PSD amplitudes










Please try the attached script.
The answer should be ~0 dB for each of the frequencies.
Most likely a simple scaling issue/parameter of which i'm ignorant.

-- 


__
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
__
##
## Name: psd_scale.py
## 
## Purpose:  Test Power Spectral Density of 1Vrms data
##   Depends on Python SciPy and NumPy
## 
## Author:   J Park
##
## Created:  10/17/07
##
## Modified: 
##

try:
  from numpy import *  # www.numpy.org numpy.scipy.org
except ImportError: 
  print "Failed to import numpy."
 
try:
  import pylab as mp  # matplotlib.sourceforge.net
  from matplotlib.font_manager import fontManager, FontProperties 
except ImportError: 
  print "Failed to import pylab."
 

# Default Parameters
nFFT  = 1024 
overlap   = 512 
freqSample= 100. 
PlotAll   = False
WriteOutput   = False

##
## Main module
def main():

  deltaF = freqSample/nFFT # Frequency resolution in Hz
  deltaT = 1./freqSample   # Sample interval
  print 'Sample interval %e (s)'   % (deltaT)
  print 'Frequency resolution %e (Hz)' % (deltaF)

  # Setup Plots
  # --
  mp.figure(1)
  mp.title ( "PSD" )
  mp.ylabel( "(dB

Re: [Matplotlib-users] PSD amplitudes

2007-10-25 Thread Joseph Park




spectral density is by convention a 1Hz
binwidth, not an arbitrary one, units of A^2/Hz.

perhaps if you manually compute the spectral density of a sine wave,
you will easily see
that they don't have infinite power, R is the autocorrelation of the
Asin(wt):


Back to the original question:

Is there evidence that the matplotlib PSD spectral amplitudes are
accurate?
say by comparison with Matlab results, or a synthetic signal as in the
example, or 
from considerations of basic DSP as in the references?


[EMAIL PROTECTED] wrote:

  There is certainly differences
(usually
of a factor of PI) in the various definitions used for PSDs, but a
simple
sign wave has an infinite power density at the sine wave frequency.
 Are
we agreed on that?
  
  
  Use of windowing will modify this
comment
somewhat (so it probably won't really go to infinity) but the basic
fact
remains.  The units of a PSD are amp^2/Hz.  The MS of a signal
between two frequencies should equal the area under the PSD between
those
frequencies (with allowance for different definitions/factors of PI).
 As
I said, for a sign wave the frequency band can be made arbitrarily
small
about the sine wave frequency, but the power between these bands
remains
constant.  Therefore the PSD goes to infinity.  Otherwise it
isn't a density.
  
  
  
  
  
  

  
Joseph Park
<[EMAIL PROTECTED]>

Sent by:
[EMAIL PROTECTED]
26/10/2007 10:49 AM




  

  
  To
  
  
  


  
  cc
  
  matplotlib-users@lists.sourceforge.net
  


  
  Subject
  
  Re:
[Matplotlib-users] PSD amplitudes

  



  

  
  
  
  
  

  



  

  
  
  
  
  is the
suggestion
that the matplotlib algorithm is correct in computing PSD amplitudes?
  
btw, increasing nFFT increases the number of points used in the FFT,
which
  
increases the spectral frequency resolution (smaller binwidth)
but
for a limited data set
of N points, as is the case in the example, decreases the number of
data
averages 
thereby decreasing the spectral amplitude resolution
(accuracy).
keep in mind that
just changing nFFT without making a corresponding change in overlap
will
oversample
the data, thereby skewing the amplitudes. 
  
in any case, the amplitude change is not approaching infinity, even if
you set nFFT to
6000, which is the length of the timeseries, the amplitudes are ~35dB,
adjust variable ymax
to see this. 
  
to review issues of spectral/amplitude resolution, windowing/overlap,
etc,
a good
reference is Random Data by Bendat  &Piersol:
  http://www.amazon.com/Random-Data-Analysis-Measurement-Procedures/dp/0471317330
  
i remain unconvinced that the PSD amplitudes are reasonable, which only
leaves Matlab
as an alternative... that's a hard pill to swallow... matplotlib is
clearly
preferable.
  
  
  [EMAIL PROTECTED]
wrote: 
  
  
If you lower the resolution (ie increase nFFT) in your program you will
see that the PSD does indeed increase.  I think it may be on the way
to infinity. 
  
  
  
  
  

  
Joseph
Park
<[EMAIL PROTECTED]>

Sent by: [EMAIL PROTECTED]

26/10/2007
10:05 AM




  

  
  To
  
  matplotlib-users@lists.sourceforge.net
  


  
  cc
  
  
  


  
  Subject
  
  Re:
[Matplotlib-users]
PSD amplitudes

  




  

  
  
  
  
  

  



  

  
  
  
  
  
Shouldn't the PSD for a simple sine wave tend to infinity
  
the spectral resolution will impact the amplitude, if you
are not dealing with a density. by definition a spectral density
has applied the bandwidth resolution correction. the PSD amplitude
should correspond to the RMS amplitude of the sine wave. in the
example a 1VRMS amplitude sine wave (time domain) should have a
PSD power of 20*log(1V) = 0dB. The windowing function will impact
this ideal number a bit, but certainly not by 25dB.
  
  [EMAIL PROTECTED]
wrote: 
  
Are you sure that the answer should be zero?  Shouldn't the PSD for
a simple sine wave tend to infinity (depending on the resolution)?
  
  
  
  
  

  
Joseph
Park
<[EMAIL PROTECTED]>

Sent by: [EMAIL PROTECTED]

 

Re: [Matplotlib-users] PSD amplitudes

2007-10-25 Thread brett . mcsweeney
I didn't say infinite power, but infinite power density at the sine wave 
frequemcy. 

Being per Hz doesn't mean that one computes the PSD using a 1 Hz band!  It 
means that one divides the power in the band by the width of the band, 
which can be anything one chooses.

The formula for S(f) of a sine wave is a delta function!





Joseph Park <[EMAIL PROTECTED]> 
Sent by: [EMAIL PROTECTED]
26/10/2007 11:50 AM

To

cc
matplotlib-users@lists.sourceforge.net
Subject
Re: [Matplotlib-users] PSD amplitudes






spectral density is by convention a 1Hz binwidth, not an arbitrary one, 
units of A^2/Hz.

perhaps if you manually compute the spectral density of a sine wave, you 
will easily see
that they don't have infinite power, R is the autocorrelation of the 
Asin(wt):


Back to the original question:

Is there evidence that the matplotlib PSD spectral amplitudes are 
accurate?
say by comparison with Matlab results, or a synthetic signal as in the 
example, or 
from considerations of basic DSP as in the references?


[EMAIL PROTECTED] wrote: 

There is certainly differences (usually of a factor of PI) in the various 
definitions used for PSDs, but a simple sign wave has an infinite power 
density at the sine wave frequency.  Are we agreed on that? 

Use of windowing will modify this comment somewhat (so it probably won't 
really go to infinity) but the basic fact remains.  The units of a PSD are 
amp^2/Hz.  The MS of a signal between two frequencies should equal the 
area under the PSD between those frequencies (with allowance for different 
definitions/factors of PI).  As I said, for a sign wave the frequency band 
can be made arbitrarily small about the sine wave frequency, but the power 
between these bands remains constant.  Therefore the PSD goes to infinity. 
 Otherwise it isn't a density. 




Joseph Park <[EMAIL PROTECTED]> 
Sent by: [EMAIL PROTECTED] 
26/10/2007 10:49 AM 


To

cc
matplotlib-users@lists.sourceforge.net 
Subject
Re: [Matplotlib-users] PSD amplitudes








is the suggestion that the matplotlib algorithm is correct in computing 
PSD amplitudes?

btw, increasing nFFT increases the number of points used in the FFT, which 

increases the spectral frequency resolution (smaller binwidth) but for a 
limited data set
of N points, as is the case in the example, decreases the number of data 
averages 
thereby decreasing the spectral amplitude resolution (accuracy). keep in 
mind that
just changing nFFT without making a corresponding change in overlap will 
oversample
the data, thereby skewing the amplitudes. 

in any case, the amplitude change is not approaching infinity, even if you 
set nFFT to
6000, which is the length of the timeseries, the amplitudes are ~35dB, 
adjust variable ymax
to see this. 

to review issues of spectral/amplitude resolution, windowing/overlap, etc, 
a good
reference is Random Data by Bendat  &Piersol:
http://www.amazon.com/Random-Data-Analysis-Measurement-Procedures/dp/0471317330


i remain unconvinced that the PSD amplitudes are reasonable, which only 
leaves Matlab
as an alternative... that's a hard pill to swallow... matplotlib is 
clearly preferable.


[EMAIL PROTECTED] wrote: 

If you lower the resolution (ie increase nFFT) in your program you will 
see that the PSD does indeed increase.  I think it may be on the way to 
infinity. 



Joseph Park <[EMAIL PROTECTED]> 
Sent by: [EMAIL PROTECTED] 
26/10/2007 10:05 AM 


To
matplotlib-users@lists.sourceforge.net 
cc

Subject
Re: [Matplotlib-users] PSD amplitudes










Shouldn't the PSD for a simple sine wave tend to infinity

the spectral resolution will impact the amplitude, if you
are not dealing with a density. by definition a spectral density
has applied the bandwidth resolution correction. the PSD amplitude
should correspond to the RMS amplitude of the sine wave. in the
example a 1VRMS amplitude sine wave (time domain) should have a
PSD power of 20*log(1V) = 0dB. The windowing function will impact
this ideal number a bit, but certainly not by 25dB.

[EMAIL PROTECTED] wrote: 

Are you sure that the answer should be zero?  Shouldn't the PSD for a 
simple sine wave tend to infinity (depending on the resolution)? 


Joseph Park <[EMAIL PROTECTED]> 
Sent by: [EMAIL PROTECTED] 
26/10/2007 06:50 AM 


To
matplotlib-users@lists.sourceforge.net 
cc

Subject
[Matplotlib-users] PSD amplitudes












Please try the attached script.
The answer should be ~0 dB for each of the frequencies.
Most likely a simple scaling issue/parameter of which i'm ignorant.

-- 


__
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
__
##
## Name: psd_scale.py
## 
## Purpose:  Test Power Spectral Density of 1Vrms data
##   Depends