⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 273-278.html

📁 dshfghfhhgsfgfghfhfghgfhfghfgh fg hfg hh ghghf hgf hghg gh fg hg hfg hfh f hg hgfh gkjh kjkh g yj f
💻 HTML
字号:
<HTML>
<HEAD>
<META name=vsisbn content="1558515682"><META name=vstitle content="Java Digital Signal Processing"><META name=vsauthor content="Douglas A. Lyon"><META name=vsimprint content="M&T Books"><META name=vspublisher content="IDG Books Worldwide, Inc."><META name=vspubdate content="11/01/97"><META name=vscategory content="Web and Software Development: Programming, Scripting, and Markup Languages: Java"><TITLE>Java Digital Signal Processing:Digital Audio Transform Recipes</TITLE>
<!-- HEADER --><STYLE type="text/css">  <!-- A:hover  { 	color : Red; } --></STYLE><META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
<!--ISBN=1558515682//-->
<!--TITLE=Java Digital Signal Processing//-->
<!--AUTHOR=Douglas A. Lyon//-->
<!--PUBLISHER=IDG Books Worldwide, Inc.//-->
<!--IMPRINT=M & T Books//-->
<!--CHAPTER=6//-->
<!--PAGES=273-278//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->

<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="266-273.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="278-282.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<H3><A NAME="Heading11"></A><FONT COLOR="#000077">The FFT Class</FONT></H3>
<P>The <I>FFT</I> class is a public class that resides in the <I>lyon.audio</I> package. It depends on the <I>grapher.Graph</I> package for performing graph functions, as well as the <I>futils.bench.Timer</I> class for benchmarking. If these packages are not needed, they can be removed along with their invocations. Such a situation might arise if this code were used in another program.</P>
<P>The <I>grapher</I> package provides a simple interface to make an automatically scaled graph. Usually, only a single method is invoked.</P>
<!-- CODE SNIP //-->
<PRE>
public void makeHann() &#123;
double window[];
     window = makeHann(256);
     Graph.graph(window,
                 &#147;The Hann window&#148;,&#148;f&#148;);
&#125;
</PRE>
<!-- END CODE SNIP //-->
<P>The &#147;The Hann window&#148; string appears along the x-axis, and &#147;f&#148; appears on the y-axis. <I>Graph.graph</I> can be invoked directly, because the <I>graph</I> method is static. It graphs an array of type <I>double</I>.</P>
<H4 ALIGN="LEFT"><A NAME="Heading12"></A><FONT COLOR="#000077">Class Summary</FONT></H4>
<!-- CODE //-->
<PRE>
package lyon.audio;
import java.io.*;
import java.awt.*;
import grapher.Graph;
import futils.bench.Timer;
public class FFT extends Frame &#123;
  public FFT(int N)
  public FFT()
  public void graphs()
  public void graphs(String t)
  public void setTitle(String t)
  public static double getMaxValue(double in[])
  public static int log2(int n)
  public static double[] arrayCopy( double [] in)
  public double [] computePSD ()
  public double[] dft(double v[])
  public double[] idft()
  public double [] getReal()
  public double [] getImaginary()
  public void forwardFFT(double in_r[], double in_i[])
  public void reverseFFT(double in_r[], double in_i[])
  public void printArray(double[] v,String title)
  public void printArrays(String title)
  public void printReal(String title)
  public static void main(String args[])
  public static void timeFFT()
  public static void testFFT()
  public static void testDFT()
&#125;
</PRE>
<!-- END CODE //-->
<H4 ALIGN="LEFT"><A NAME="Heading13"></A><FONT COLOR="#000077">Class Usage</FONT></H4>
<P>The <I>FFT</I> class maintains internal data arrays that are stored as doubles. These arrays are private and are used to assist computation. Furthermore, the in-place Cooley-Tukey algorithm employed for the fast transform is destructive of the original data. The <I>FFT</I> class in the <I>lyon.audio</I> package uses doubles for all computations. This class is for 1-D (audio) transforms.</P>
<P>Suppose the following variables are predefined:</P>
<!-- CODE SNIP //-->
<PRE>
FFT f;
int N = 8;
double inputArray[];
String title = &#147;My data title&#148;;
double aDoubleArray[];
double in_r[];
double in_i[];
</PRE>
<!-- END CODE SNIP //-->
<P>To make a new instance of the <I>FFT</I> class and allocate two internal arrays of double, each of length <I>N</I>, use:</P>
<!-- CODE SNIP //-->
<PRE>
f = new FFT(N);
</PRE>
<!-- END CODE SNIP //-->
<P>To make a new instance of the <I>FFT</I> class with no memory allocation:</P>
<!-- CODE SNIP //-->
<PRE>
f = new FFT();
</PRE>
<!-- END CODE SNIP //-->
<P>To graph the real and imaginary data arrays:
</P>
<!-- CODE SNIP //-->
<PRE>
f.graphs();
</PRE>
<!-- END CODE SNIP //-->
<P>To graph the real and imaginary data arrays with a title:
</P>
<!-- CODE SNIP //-->
<PRE>
f.graphs(title);
</PRE>
<!-- END CODE SNIP //-->
<P>To set the title for the graphs:
</P>
<!-- CODE SNIP //-->
<PRE>
f.setTitle(title);
</PRE>
<!-- END CODE SNIP //-->
<P>To get the maximum value of an <I>inputArray</I>:</P>
<!-- CODE SNIP //-->
<PRE>
FFT.getMaxValue(inputArray);
</PRE>
<!-- END CODE SNIP //-->
<P>To compute the floor of the log of an <I>int</I> to base 2:</P>
<!-- CODE SNIP //-->
<PRE>
int numberOfBits = FFT.log2(N);
</PRE>
<!-- END CODE SNIP //-->
<P>To copy an array of double:
</P>
<!-- CODE SNIP //-->
<PRE>
aDoubleArray = FFT.arrayCopy(inputArray);
</PRE>
<!-- END CODE SNIP //-->
<P>To compute the PSD (power spectral density) of the previous DFT or FFT:
</P>
<!-- CODE SNIP //-->
<PRE>
aDoubleArray = f.computePSD();
</PRE>
<!-- END CODE SNIP //-->
<P>To nondestructively compute the DFT of an input array and return the PSD:
</P>
<!-- CODE SNIP //-->
<PRE>
aDoubleArray = f.dft(inputArray);
</PRE>
<!-- END CODE SNIP //-->
<BLOCKQUOTE>
<P><FONT SIZE="-1"><HR><B>NOTE:&nbsp;&nbsp;</B>DFT, IDFT, FFT, and IFFT alter the internal data structures in an instance of the <I>FFT</I> class.<HR></FONT>
</BLOCKQUOTE>
<P>To get the real part of the last transform:
</P>
<!-- CODE SNIP //-->
<PRE>
aDoubleArray = f.getReal();
</PRE>
<!-- END CODE SNIP //-->
<P>To get the imaginary part of the last transform:
</P>
<!-- CODE SNIP //-->
<PRE>
aDoubleArray = f.getImaginary();
</PRE>
<!-- END CODE SNIP //-->
<P>To take the IDFT of the internal data and return the real part:
</P>
<!-- CODE SNIP //-->
<PRE>
aDoubleArray = f.idft();
</PRE>
<!-- END CODE SNIP //-->
<P>To take the forward FFT on two input arrays, (destructively):
</P>
<!-- CODE SNIP //-->
<PRE>
f.forwardFFT(in_r, in_i);
</PRE>
<!-- END CODE SNIP //-->
<P>To take the inverse FFT on two input arrays, (destructively):
</P>
<!-- CODE SNIP //-->
<PRE>
f.reverseFFT(in_r, in_i);
</PRE>
<!-- END CODE SNIP //-->
<P>To print an array of double, with a title:
</P>
<!-- CODE SNIP //-->
<PRE>
f.printArray(aDoubleArray, title);
</PRE>
<!-- END CODE SNIP //-->
<P>To print the internal real and imaginary arrays, with a title:
</P>
<!-- CODE SNIP //-->
<PRE>
f.printArrays(title);
</PRE>
<!-- END CODE SNIP //-->
<P>To print the internal real array, with a title:
</P>
<!-- CODE SNIP //-->
<PRE>
f.printReal(title);
</PRE>
<!-- END CODE SNIP //-->
<P>To test the DFT, IDFT, FFT, and IFFT:
</P>
<!-- CODE SNIP //-->
<PRE>
FFT.main();
</PRE>
<!-- END CODE SNIP //-->
<P>To time the FFT:
</P>
<!-- CODE SNIP //-->
<PRE>
FFT.timeFFT();
</PRE>
<!-- END CODE SNIP //-->
<P>To test the FFT:
</P>
<!-- CODE SNIP //-->
<PRE>
FFT.testFFT();
</PRE>
<!-- END CODE SNIP //-->
<P>To test the DFT:
</P>
<!-- CODE SNIP //-->
<PRE>
FFT.testDFT();
</PRE>
<!-- END CODE SNIP //-->
<H4 ALIGN="LEFT"><A NAME="Heading14"></A><FONT COLOR="#000077">Testing the FFT and IFFT</FONT></H4>
<P>The <I>FFT</I> class has a static method that permits the testing of the DFT, IDFT, FFT, and IFFT. It also performs timing for a transform of 2,048 doubles. To run this test, you must invoke the following:</P>
<!-- CODE SNIP //-->
<PRE>
FFT.main();
</PRE>
<!-- END CODE SNIP //-->
<P>The code for the <I>FFT.main</I> method follows:</P>
<!-- CODE SNIP //-->
<PRE>
 public static void main(String args[]) &#123;
      testDFT();
      timeFFT();
      testFFT();
 &#125;
</PRE>
<!-- END CODE SNIP //-->
<P>The test methods are run on an eight-point input array consisting of a linear ramp, providing a short sequence of input data that can be verified by printing. The timing is performed on 2,048 samples stored in two arrays of 2,048 doubles each (real and imaginary). The output of the main method follows:
</P>
<!-- CODE //-->
<PRE>
Executing DFT on 8 points...
Executing IDFT on 8 points...
j     x1[j]     re[j]       im[j]      v[j]
0     0         3.5         0          -3.10862e-15
1     1         -0.5        1.20711    1
2     2         -0.5        0.5        2.00000
3     3         -0.5        0.207107   3
4     4         -0.5        0          4
5     5         -0.500000   -0.207107  5
6     6         -0.500000   -0.5       6
7     7         -0.5        -1.20711   7
fft: bit reversal
Time for 2048point fftTime 0.178000 sec
fft: bit reversal
Time for 2048point ifftTime 0.164000 sec
Starting 1D FFT test...
fft: bit reversal
fft: bit reversal
j     x1[j]     re[j]       im[j]      v[j]
0     0         3.5         0          0
1     1         -0.5        1.20711    1.00000
2     2         -0.5        0.5        2.00000
3     3         -0.500000   0.207107   3.00000
4     4         -0.5        0          4
5     5         -0.5        -0.207107  5
6     6         -0.5        -0.5       6
7     7         -0.500000   -1.20711   7
</PRE>
<!-- END CODE //-->
<P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="266-273.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="278-282.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>

<hr width="90%" size="1" noshade><div align="center"><font face="Verdana,sans-serif" size="1">Copyright &copy; <a href="/reference/idgbooks00001.html">IDG Books Worldwide, Inc.</a></font></div>
<!-- all of the reference materials (books) have the footer and subfoot reveresed --><!-- reference_subfoot = footer --><!-- reference_footer = subfoot --></BODY></HTML><!-- END FOOTER -->

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -