ME 365 EXPERIMENT 8 FREQUENCY ANALYSIS Objectives: There are two goals in this laboratory exercise. The first is to reinforce the Fourier series analysis you have done in the lecture portion of this course. The second is to improve your LabVIEW programming skills. These goals are to be met with the student s completion of a Fourier-based LabVIEW program. After completing this lab, you should be able to: Find the Fourier coefficients for a periodic signal. Reconstruct a periodic signal using a combination of sinusoids Decompose a periodic signal into its Fourier series and understand why this is useful. About the program: The VI that you will construct today is modeled after the Sine-only form of the Fourier series, given with: 2 nt y(t) M / 2 M sin( ) o n n T n 1 where between the k is the phase term. From the pre-lab exercise you should be comfortable converting A k and in the Sine-only Fourier expression. B k in the Sine and Cosine Fourier expression and the related coefficients Now load Fourier.vi from the 365 library. As a starting block, you are given the front panel shown below in figure 1. Your work will occur on the associated wiring diagram. 1
Figure 1: The Front Panel (Location: vi... /DESKTOP /ME365 /ME365.LLB /Fourier.vi) This is the completed front panel. You should recognize that all of the numeric constants are controllers, or inputs to the VI. The outputs are the Front Panel s graphical display as well as a continuously generated voltage corresponding to the waveform. This continuous waveform will come out of DAC0 port on the data acquisition interface. It is your task to correctly complete a VI which will take the VI s inputs, generate the function y(t), graph it, and send it to the D/A output port. What follows is an outline of the steps you will need to take. Procedure: Based on the form of the Sine only Fourier series an algorithm can be developed: 1. Collection and organization of the inputs Before you do any wiring you should be comfortable with what the inputs are. Each row of amplitude, phase, and frequency multiplier will provide information for the generation of one sinusoid. Therefore you must be careful to keep the sets together. The inputs of fundamental 2
frequency and sampling frequency are used several times. For example, they will be used in the generation of each sinusoid. Locate each of these inputs in the Wiring Diagram and make an effort to keep organized. 2. Generation of sinusoids As the Fourier series is a collection of sinusoids, you will need a method of sine wave generation. To do this we will use an existing Sine Pattern VI. It is located by expanding the tools menu, selecting Signal Processing, then Signal Generation, then Sine Pattern.VI. Its wiring diagram and location are shown in figure 2. Figure 2: Sine Pattern This VI has four inputs: number of points (samples), amplitude, phase and cycles. It is important to note that the vi expects phase in degrees, not radians. The number of points to be used in the generation is equal to the sampling frequency divided by the fundamental frequency (take a minute to verify this). The fundamental frequency multiplier corresponds to the Fourier summation counter k. For clarity, when k=1 we will generate the fundamental sinusoidal component. Its period, given by T 0 =1/ f 0, is the period of the function y(t). When k=2 we will generate a sinusoidal component that goes through two of full oscillations in T 0 seconds. NOTE: The cycles input can only be positive integers. Sine Pattern.vi outputs the generated sinewave. Although it is not necessary, it will be easiest to use a separate Sine Pattern.vi for each of the six input sets; you can use cut and paste to save time. NOTE: You may create a DC term by using a Numerical Control labeled as DC OFFSET. 3
3. Collection of sinusoids Once all the appropriate sinusoids are generated they must be summed together. For this task you may use BigSum.vi shown in figure 3. array inputs output array Figure 3: BigSum.vi (Location: Select a VI... / ME365 /ME365_support.LLB /BigSum.vi) This VI was built for this exercise and replaces multiple summing blocks. It takes up to six arrays as inputs and sums them term by term to generate one array as its output. Use this to simplify the wiring in your Wiring Diagram. 4. Graphing and outputting To view the function we will need to send it to the Front Panel s Time History plot. Call up Scope.vi and follow its wiring directions as shown in figure 4. inputs: sampling freq fundamental freq array loop counter "i" Figure 4: Scope.vi output bundle (Location: Select a VI... /ME365 /ME365_support.LLB /Scope.vi) This VI was also designed for this specific laboratory. Scope.vi provides two major services: It creates the appropriate time axis for the Time History on the Front Panel you ve been given. It also automatically sends the generated waveform to the DAC0 port which can be viewed on the oscilloscope. NOTE: In order to create a continuous signal from a waveform of finite length you must incorporate a loop. That is to say, everything you ve done in your Wiring Diagram now needs to be encased in one giant While Loop. In fact, the counter (i) from the loop is 4
one of Scope.vi s required inputs. To make the loop run continuously you will also need to add a logic constant, set on true. Wire this to the loop s small green continuation arrow. Looping your code like this will allow you to observe the contribution of each sinusoidal component as it is entered into the Front Panel. The other inputs are the sample frequency, the fundamental frequency, and the array coming out of BigSum.vi. The output from Scope.vi is a cluster containing the waveform and corresponding time information. It must be sent to the Front Panel s Time History plot. With this connected, you are ready to test your VI. VI implementation Use your VI to generate the signals listed below. Display the generated signal on your oscilloscope and then measure it using the Simple Spectrum Analyzer VI, described on pages 6 and 7. Use the continuous run mode of the VI in order to see how the various waves are formed as individual sinusoids are added one by one. 1. Square-wave: The ratios of the coefficients for a square wave with odd symmetry will have only odd number terms. Calculate the coefficients and generate the wave. 2. Sawtooth-wave: The ratios of the coefficients of an odd symmetry sawtooth will have both even and odd numbered term. Calculate the coefficients and generate the wave. 5
Simple Spectrum Analyzer.vi Simple Spectrum Analyzer.vi acquires and analyzes a waveform. The VI breaks the signal up into its individual frequency components and displays their magnitudes. The front panel is shown in figure 5. You need not fully understand all of the inner workings of this VI. Just the same, brief descriptions of each user option are given below and on the next page. Figure 5: Simple Spectrum Analyzer.vi (Location: vi... /DESKTOP /ME365 /ME365.LLB / Simple Spectrum Analyzer.vi) Input channel number is Ch 3 for this VI. number of samples: This is the total number of points used in the Fourier analysis. For quickest results, this should be a power of 2. The more points you use, the finer the resolution (more data points) on the spectral plot. sample rate: This is the frequency at which the data is sampled. Watch out for aliasing! 6
Window: Remember that Fourier analysis is based on the fundamental assumption that the signal being analyzed is periodic. As most experimental data is not truly periodic, windows are used to force periodicity. Basically, they multiply the input by zero at its start and end, and by a non-zero value everywhere else. This pinches the sampled signal to zero at its ends and ensures that it has the same starting and ending value. Windows themselves come in a variety of shapes, each with their own benefits to the spectral plots. You should experiment briefly with this option to see if a particular window works best for your data. None and Hanning are the most commonly used. Display Unit: Here you can select the amplitude units for the spectral plot. Choosing Vpk will give you the Fourier coefficients. Choosing Vrms allows you to view the spectral power. Log/Linear: Viewing the spectrum on a log scale can give you details which the linear plot might miss. It is important, however, to keep clear what the relative spectral magnitudes are. The log plot can be misleading in this regard. 7