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

📄 300-306.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=300-306//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->

<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="293-300.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="../ch07/307-310.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<H3><A NAME="Heading21"></A><FONT COLOR="#000077">Frequency Shifting Using the FFT</FONT></H3>
<P>To shift the pitch of a time-domain signal, we take the FFT, perform the high-pass filtering shown in the preceding section, shift the spectrum lower, and then perform the IFFT. Recall that the FFT produces a real and an imaging output. Also recall that <I>fftInstance</I> is a class variable in the <I>AudioFrame</I> class. Thus, we design our pitch-shifter as one of many possible spectral modifications that can be performed by the user before the IFFT is taken. The plan is to work on bins 0..<I>N</I>/2 first and then to copy the bins about the <I>N</I>/2 point in the spectrum, assuming that the left-hand and right-hand sides are symmetric (as is always the case for real signals). The code for the pitch-shift follows:</P>
<!-- CODE //-->
<PRE>
public void pitchShift() &#123;
     fftInstance = new FFT();
     double[] r_d = getTruncatedDoubleData();
     int N = r_d.length;
     double[] i_d = new double[N];
     int N_on_4 = N/4;

     fftInstance.forwardFFT(r_d, i_d);
     // shift data down
     for (int i = 0; i &lt; N_on_4; i&#43;&#43;) &#123;
          r_d[i] = r_d[i &#43; N_on_4];
          i_d[i] = i_d[i &#43; N_on_4];
     &#125;
     for (int i= N_on_4; i &lt; N/2; i&#43;&#43;) &#123;
          r_d[i] = 0;
          i_d[i] = 0;
     &#125;

     // reflect about center, assuming a real signal
     int i,j;
     for (i=0,j=N-1; i &lt; N/2; i&#43;&#43;, j&#151;) &#123;
          r_d[j] = r_d[i];
          i_d[j] = i_d[i];
     &#125;

     fftInstance.reverseFFT(r_d,i_d);

     ulc = new UlawCodec(r_d);

     ulc.play();

&#125;
</PRE>
<!-- END CODE //-->
<P>The result for synthetic tones, rich in harmonics, is to filter out some of the lower frequencies and to reduce the upper harmonic content.
</P>
<P>Figure 6.23 shows a square wave and its PSD. Figure 6.24 shows the result of shifting the harmonics of the square wave away from the center of the PSD on the right. On the left of Figure 6.24, we4 see the reconstructed waveform in the time domain.</P>
<P><A NAME="Fig23"></A><A HREF="javascript:displayWindow('images/06-23.jpg',340,234 )"><IMG SRC="images/06-23t.jpg"></A>
<BR><A HREF="javascript:displayWindow('images/06-23.jpg',340,234)"><FONT COLOR="#000077"><B>Figure 6.23</B></FONT></A>&nbsp;&nbsp;The square wave and its PSD.</P>
<P><A NAME="Fig24"></A><A HREF="javascript:displayWindow('images/06-24.jpg',359,231 )"><IMG SRC="images/06-24t.jpg"></A>
<BR><A HREF="javascript:displayWindow('images/06-24.jpg',359,231)"><FONT COLOR="#000077"><B>Figure 6.24</B></FONT></A>&nbsp;&nbsp;The pitch-shifted square wave and its PSD.</P>
<H3><A NAME="Heading22"></A><FONT COLOR="#000077">Resampling and the FFT</FONT></H3>
<P>Resampling a one-dimensional waveform is a common way to perform time-compressed speech. One easy resampling technique is to perform Fairbanks sampling and throw away every other sample [Fairbanks].
</P>
<P>The resampling method performs a 2:1 subsampling in the time domain. The code for the <I>resample</I> method follows:</P>
<!-- CODE //-->
<PRE>
public void resample() &#123;
     double[] r_d = getTruncatedDoubleData();
     int N = r_d.length;
     double [] resampled = new double[N/2];
     for (int i=0; i &lt; N/2; i&#43;&#43;)
          resampled[i] = r_d[2*i];

     ulc = new UlawCodec(resampled);

     ulc.play();

&#125;
</PRE>
<!-- END CODE //-->
<P>Figure 6.25 shows a saw wave and its PSD. Compare Figure 6.25 with Figure 6.26 which shows the saw wave and PSD after the 2:1 subsampling algorithm has been applied.
</P>
<P><A NAME="Fig25"></A><A HREF="javascript:displayWindow('images/06-25.jpg',321,221 )"><IMG SRC="images/06-25t.jpg"></A>
<BR><A HREF="javascript:displayWindow('images/06-25.jpg',321,221)"><FONT COLOR="#000077"><B>Figure 6.25</B></FONT></A>&nbsp;&nbsp;The saw wave and PSD before subsampling.</P>
<P><A NAME="Fig26"></A><A HREF="javascript:displayWindow('images/06-26.jpg',339,213 )"><IMG SRC="images/06-26t.jpg"></A>
<BR><A HREF="javascript:displayWindow('images/06-26.jpg',339,213)"><FONT COLOR="#000077"><B>Figure 6.26</B></FONT></A>&nbsp;&nbsp;The saw wave and PSD after subsampling.</P>
<P>The 2:1 subsampling has doubled the pitch of the harmonics and halved the number of available samples.
</P>
<H3><A NAME="Heading23"></A><FONT COLOR="#000077">Centering the FFT</FONT></H3>
<P>A great many books show that the lowest frequency is toward the center of the PSD when taking an FFT because the process of centering the FFT. The FFT is centered by replacing the sample data with a value that changes from positive to negative when the sample value goes from zero to 1. This can be described by the formula:
</P>
<P ALIGN="CENTER"><IMG SRC="images/06-61d.jpg"></P>
<P>(6.29)
</P>
<P>for the real sample on input. After the IFFT (or IDFT), the formula must be applied again [Myler].</P>
<P>The centered PSD for a pulse is shown in Figure 6.27.</P>
<P><A NAME="Fig27"></A><A HREF="javascript:displayWindow('images/06-27.jpg',349,230 )"><IMG SRC="images/06-27t.jpg"></A>
<BR><A HREF="javascript:displayWindow('images/06-27.jpg',349,230)"><FONT COLOR="#000077"><B>Figure 6.27</B></FONT></A>&nbsp;&nbsp;A pulse with a centered PSD.</P>
<P>You can modify the <I>forwardFFT</I> in the <I>AudioFrame</I> to perform this method:</P>
<!-- CODE //-->
<PRE>
public void forwardFFT(double in_r[], double in_i[]) &#123;
     int id;
     int localN;
     double wtemp, Wjk_r, Wjk_i, Wj_r, Wj_i;
     double theta, tempr, tempi;
     int ti, tj;

     int numBits = log2(in_r.length);
     if (forward) &#123;
          <B>centering(in_r);</B>
     &#125;
</PRE>
<!-- END CODE //-->
<P>The <I>centering</I> method computes Equation 6.28 on the real part of the sample data. Centering can be implemented as follows (in the <I>FFT</I> class):</P>
<!-- CODE SNIP //-->
<PRE>
private void centering(double r[] ) &#123;
     int s = 1;
     for (int i = 0; i &lt; r.length; i&#43;&#43;) &#123;
          s = -s;
          r[i] *= s;

     &#125;
&#125;
</PRE>
<!-- END CODE SNIP //-->
<P>The <I>reverseFFT</I> implements <I>centering</I> after the IFFT has finished:</P>
<!-- CODE SNIP //-->
<PRE>
public void reverseFFT( double in_r[], double in_i[]) &#123;
     forward = false;
     forwardFFT(in_r, in_i);
     forward = true;
     centering(in_r);
&#125;
</PRE>
<!-- END CODE SNIP //-->
<P>Without centering, the PSD is shown with the lowest frequencies on the edges (Figure 6.28). We have adopted this convention for the one-dimensional PSD display (except when explicitly marked otherwise). We are amazed that few books speak about the uncentered magnitude Fourier spectrum and how to correct it. Left uncentered, the FFT and DFT produce results that can match the outputs of other FFT and DFT implementations (as in [Moore]). As a result, we felt it best to leave the spectrum uncentered, at least for the one-dimensional FFT.
</P>
<P><A NAME="Fig28"></A><A HREF="javascript:displayWindow('images/06-28.jpg',244,226 )"><IMG SRC="images/06-28t.jpg"></A>
<BR><A HREF="javascript:displayWindow('images/06-28.jpg',244,226)"><FONT COLOR="#000077"><B>Figure 6.28</B></FONT></A>&nbsp;&nbsp;An uncentered PSD.</P>
<H3><A NAME="Heading24"></A><FONT COLOR="#000077">Summary</FONT></H3>
<P>The close of this chapter marks a sad time for us. Just as things are getting fun, we move to the image processing section of the book (which we hope will be even more fun). Combining a pitch shifter with a resampler to compress speech is not a new idea. In fact, it can be used to help perform skimming on recorded speech (a topic of current research) [Arons].
</P>
<P>The introduction to the DFT, IDFT, FFT, and IFFT is not new either, and the FFT is probably not the fastest. For the fastest Fourier transform in the west, see <A HREF="http://theory.lcs.mit.edu/~fftw">http://theory.lcs.mit.edu/~fftw</A>. It may well be the fastest, but it may also rank as one of the most complex of implementations. It is still <I>O</I>(<I>N</I> log <I>N</I>), but it has a very low constant time. This link also has pointers to public domain software for performing FFTs (including a mixed radix FFT).</P>
<P>As far as we know, the derivation of the Lyon window, using Maple, is new. The Lyon window (two quintics with flat ends) is not new, although its application as a window for signals probably is. In the past, the quintic was viewed as a curvature controlled trajectory for maneuvering a car [Lyon 90]. We make no claim as to the suitability of the Lyon window for signal processing, because the window has not been thoroughly investigated. It poses a topic for future research.</P><P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="293-300.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="../ch07/307-310.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 + -