<< Chapter < Page | Chapter >> Page > |
The constructor begins in Listing 4 . The code in Listing 4 is identical to that shown earlier in Listing 2 . This code generates the five sinusoidal pulses and stores the data representing those pulses in the arrays referred to by data1 through data5 . So far, except for the declaration of some extra variables, this program isn't much different from the program named Dsp031a discussed earlier in this module.
Listing 4. Beginning of the constructor. |
---|
public Dsp031(){//constructor
//Create the raw datafor(int x = 0;x<len/16;x++){
data1[x]= amp*Math.cos(2*pi*x*freq);
}//end for loopfor(int x = 0;x<len/8;x++){
data2[x]= amp*Math.cos(2*pi*x*freq);
}//end for loopfor(int x = 0;x<len/4;x++){
data3[x]= amp*Math.cos(2*pi*x*freq);
}//end for loopfor(int x = 0;x<len/2;x++){
data4[x]= amp*Math.cos(2*pi*x*freq);
}//end for loopfor(int x = 0;x<len;x++){
data5[x]= amp*Math.cos(2*pi*x*freq);
}//end for loop |
The remainder of the constructor is shown in Listing 5 . This code calls the transform method of the ForwardRealToComplex01 class five times in succession to perform the spectral analysis on each of the five pulses shown in Figure 1 .
(I explained the transform method in detail in the previous module titled Spectrum Analysis using Java, Sampling Frequency, Folding Frequency, and the FFT Algorithm .)
Listing 5. Perform the spectral analysis. |
---|
mag1 = new double[len];real = new double[len];imag = new double[len];angle = new double[len];ForwardRealToComplex01.transform(data1,real,
imag,angle,mag1,zeroTime,lowF,highF);mag2 = new double[len];real = new double[len];imag = new double[len];angle = new double[len];ForwardRealToComplex01.transform(data2,real,
imag,angle,mag2,zeroTime,lowF,highF);mag3 = new double[len];real = new double[len];imag = new double[len];angle = new double[len];ForwardRealToComplex01.transform(data3,real,
imag,angle,mag3,zeroTime,lowF,highF);mag4 = new double[len];real = new double[len];imag = new double[len];angle = new double[len];ForwardRealToComplex01.transform(data4,real,
imag,angle,mag4,zeroTime,lowF,highF);mag5 = new double[len];real = new double[len];imag = new double[len];angle = new double[len];ForwardRealToComplex01.transform(data5,real,
imag,angle,mag5,zeroTime,lowF,highF);}//end constructor |
Each time the transform method is called, it computes the magnitude spectrum for the incoming data and saves it in the output array.
(Note that the real, imag, and angle arrays are not used later, so they are discarded each time a new spectral analysis is performed.)
The Dsp031 class also implements the interface named GraphIntfc01 . The remaining code in the program consists of the methods required to satisfy thatinterface. Except for the identification of the arrays from which the methods extract data to be returned for plotting, these methods are identical to thosedefined in the earlier class named Dsp031a . Therefore, I won't discuss them further.
Notification Switch
Would you like to follow the 'Digital signal processing - dsp' conversation and receive update notifications?