Listings
- Listing 1. Beginning of the class named Dsp029.
- Listing 2. Create array objects to hold sinusoidal data.
- Listing 3. Get the parameters.
- Listing 4. Create the sinusoidal data.
- Listing 5. The code for GraphIntfc01.
- Listing 6. The getNmbr method.
- Listing 7. The method named f1.
- Listing 8. Beginning of the class named Dsp028.
- Listing 9. Declare array variables.
- Listing 10. Beginning of the constructor.
- Listing 11. Create the raw sinusoidal data.
- Listing 12. Perform the spectral analysis.
- Listing 13. The method named f1.
- Listing 14. The beginning of the transform method.
- Listing 15. The remainder of the method and the class.
- Listing 16. Dsp029.java.
- Listing 17. GraphIntfc01.java.
- Listing 18. Graph06.java.
- Listing 19. Dsp028.java.
- Listing 20. Graph03.java.
- Listing 21. ForwardRealToComplex01.java.
- Listing 22. Dsp030.java.
- Listing 23. ForwardRealToComplexFFT01.java.
Preview
Before I get into the technical details, here is a preview of the programs and their purposes that I will present and explain in this module:
- Dsp029 - Provides a visual illustration of the impact of the sampling frequency and the Nyquist folding frequency.
- Dsp028 - Driver program for doing spectral analysis using a DFT algorithm.
- ForwardRealToComplex01 - Class that implements the DFT algorithm.
- Dsp030 - Driver program for doing spectral analysis using an FFT algorithm.
- ForwardRealToComplexFFT01 - Class that implements the FFT algorithm (will defer explanation until a future module).
- Graph03 - Used to display results of spectral analysis. (The concepts were explained in the earlier module titled Plotting Engineering and Scientific Data using Java .)
- Graph06 - Used to display the impact of sampling frequency and the Nyquist folding frequency. Also used to display the results of spectralanalysis. (The concepts were explained in the earlier module titled Plotting Engineering and Scientific Data using Java .)
Discussion and sample code
This will be a long module involving lots of code and lots of explanations, so fill your cup with java and let's get started.
Sampling frequency and the Nyquist folding frequency
I will begin the discussion with the program named Dsp029 , which provides a visual illustration of the impact of the sampling frequency andthe Nyquist folding frequency. A complete listing of this program is shown in Listing 16 near the end of the module.
Display sinusoids
This program generates and displays up to five sinusoids having the same sampling frequency but having different sinusoidal frequencies and amplitudes.The program provides a visual illustration of the way in which frequencies above one-half the sampling frequency fold back into the area bounded by zero andone-half the sampling frequency.
(The frequency at one-half the sampling frequency is known as the Nyquist folding frequency.)
Input parameters
The program gets its input parameters from a file named Dsp029.txt . If that file doesn't exist in the current directory, the program uses a set ofdefault parameters.
Each parameter value must be stored as characters on a separate line in the file named Dsp029.txt . The required parameters are shown in Figure 1 .