Upload
vankhuong
View
232
Download
4
Embed Size (px)
Citation preview
myDAQ: Filter a Signal
1
Lab 1B LabVIEW Filter Signal
Due Thursday, September 12, 2013
Submit Responses to Questions (Hardcopy)
Equipment: LabVIEW
Setup: Open LabVIEW
Skills learned:
• Create a low-‐pass filter using LabVIEW and modify its parameters • Measure characteristics of the filtered signal – amplitude and spectrum • Learn the difference between high-‐pass filters, low-‐pass filters, and band-‐pass filters • Observe different types of filters including Butterworth and Chebyshev
Further Study:
• High-‐pass filters • Band-‐pass filters • Fourier Transforms • Fast Fourier Transforms
myDAQ: Filter a Signal
2
Filter a Signal
What we are doing: Learning to filter a signal. Filters remove a specific frequency or frequency range from a signal. We will create a filter and use it to filter an artificial signal. Then we will observe the results. This particular filter will be a 3rd Order Low Pass Butterworth Filter.
Why we are doing it: Sometimes the signal we observe contains noise that interferes with our ability to analyze it. High-‐frequency noise may alias down into frequencies we need to observe, low-‐frequency noise may cause an inconsistent ‘baseline’ for the signal, or a specific extraneous frequency may be present (such as 60 Hz noise from United States powerlines). Filters can help to condition the signal prior to analysis.
myDAQ: Filter a Signal
3
http://www.r-‐bloggers.com/ecg-‐signal-‐processing/
myDAQ: Filter a Signal
4
1. Open a new blank VI. Save it as my_filter.vi .
2. Go to the Block Diagram window. From the Express Pallet, click Signal Analysis. Click Filter and put it on the block diagram.
myDAQ: Filter a Signal
5
3. A window will appear marked Configure Filter [Filter]. Here you can set various parameters for the filter. We will leave it with the default values: -‐Filtering Type Lowpass -‐Filter Specifications 100Hz Cutoff Frequency -‐IIR filter, -‐Butterworth Topology, -‐Order=3 (3rd Order Filter). Click OK. SAVE YOUR WORK!!
myDAQ: Filter a Signal
6
4. Create an input signal. Here we will create a sine wave to input into the filter. From the Express menu, select Simulate Signal. Place on the Block Diagram, left of the Filter.
myDAQ: Filter a Signal
7
5. A window will appear,
labeled Configure Simulate Signal [Simulate Signal]. Leave it at the default values -‐Signal type Sine -‐Frequency 10.1 Hz -‐Amplitude 1 -‐Samples per Second 1000 -‐Number of Samples 100 Click OK
myDAQ: Filter a Signal
8
6. Wire together the Sine and the Signal (input) of the Filter.
SAVE YOUR WORK!!
7. To the right of ‘Filtered
Signal’ on the Filter, there is a small arrow. Right click on that arrow, a menu will appear. Click on Create, then click Graph Indicator. A graph indicator will appear on the block diagram, connected to ‘Filtered Signal’.
myDAQ: Filter a Signal
9
8. Here we can change the label of our new graph to something more meaningful. We will also change it from the properties menu, so that the new name appears the same in both the block diagram, and in the front panel. Right-‐click on the new ‘Filtered Signal’ graph in the block diagram, and click Properties. A Graph Properties popup will appear. -‐In the Label area, check “Visible” -‐Type into the box ‘Filtered Signal’ if it’s not already there -‐If the Caption box doesn’t show ‘Filtered Signal’, first type that into the box, THEN uncheck “Visible”. NOTE: Type BEFORE unchecking Visible, because after unchecking, the box won’t allow input. -‐Click OK Note: You can also explore other options for the graph by clicking different tabs inside the Graph Properties box “Display Format” etc. SAVE YOUR WORK!!
myDAQ: Filter a Signal
10
9. At this point, we will go to the Front Panel and make sure everything’s working properly. Then we will move on. Go to the Front Panel and click the Run button. You should see a Graph, with a Sine Wave. Otherwise, return to previous steps and double-‐check your work.
10. Now that the filter is working, we will
also make an indicator showing the original input signal, for comparison. Go to the Block Diagram window. Using the same approach we applied to create the Graph Indicator for the Filtered Signal, right-‐click on the small triangle next to Sine on the Simulate Signal VI. Choose CreateàGraph Indicator. A Graph will appear, drag it down a little so the wires are visible.
myDAQ: Filter a Signal
11
SAVE YOUR WORK!!
11. Go to the Front Panel. Move the Sine graph to the left of the Filtered Signal. Click Run. You should see the output shown. SAVE YOUR WORK!!
myDAQ: Filter a Signal
12
12. Now we would like to modify some of the Filter parameters. Let’s make some indicators on the front panel, so that we can access them easily. From the Block Diagram window, extend the Filter VI so the inputs are visible. Do the same for the Simulate Signal VI. Move the Graph Indicators if necessary.
13. For the filter, create a control that sets the Filter Cut-‐off frequency. Right-‐click on Lower Cut-‐Off, select CreateàControl. Move the Control around if necessary.
14. Create a control for the signal frequency by repeating 13 for ‘Frequency’ in the Simulate Signal VI.
SAVE YOUR WORK!!
myDAQ: Filter a Signal
13
15. Go to the Front Panel and move the Controls around to convenient positions. A suggested layout is shown.
SAVE YOUR WORK!!
16. Now test the filter.
Switch to the Front Panel window. On the Tools Palette, switch to the Operate Value cursor (by clicking on the Arrow icon). Change the Frequency to 100, and the Lower Cut-‐Off to 10. Click Run. You should see the following output.
myDAQ: Filter a Signal
14
17. Notice the Amplitude on the two graphs
has changed. They can be manually fixed to specific values, by right-‐clicking on the axis, and setting the Properties as shown. -‐unclick Autoscale -‐set Minimum to -‐1 -‐set Maximum to 1 Click OK
myDAQ: Filter a Signal
15
Now the chart should appear as shown. SAVE YOUR WORK!!
myDAQ: Filter a Signal
16
Spectral Analysis of a Pure Tone (Sine Wave) So far, we’ve created a low-‐pass filter, and placed graphs so we can see the original signal (the Sine wave) and the signal after it is passed through the filter (Filtered Signal). Since a Filter is used to limit the frequency content of a signal, it might be helpful to also provide a graph showing the frequency content of the signal. A graph that shows the frequencies in a signal is called a Spectrogram, and is often created using a computation called a Fast Fourier Transform (FFT). Look it up!
18. Create a spectrogram for the output
signal using the following process: Go to the Express palette and choose Signal Analysisà Spectral .
19. Place the VI on the Block Diagram, and
the following window will appear. Leave the values at their default settings, and click OK.
myDAQ: Filter a Signal
17
20. Connect the Spectral Measurements VI to the Filter output. -‐Wire the Signals input to the Filtered Signal output of the Filter -‐Right-‐click on FFT-‐RMS and CreateàGraph Indicator. SAVE YOUR WORK!!
21. Go to the Front Panel and move the new
Graph around as shown. Change the title of the new graph to Filtered Signal Spectrum. Save and click Run to test. Note the peak at frequency = 100. The input frequency is 100, so this is expected. Note that the Frequency is not a spike at 100 Hz. There is a small but significant signal spectrum around it, around 80-‐120 Hz. This is due to the type of filter used, and the shape of the window. What would we expect the signal to look like? Let’s make a spectrogram for the input signal for comparison.
myDAQ: Filter a Signal
18
22. Create a new spectrogram, but this time, connect it directly to the simulated signal. The Block Diagram should appear as shown. Remember to change the title of the new Waveform graph to Input Signal Spectrum by right-‐clicking and selecting Properties. Save your work.
23. Adjust the Front Panel as shown. Save and run the VI.
myDAQ: Filter a Signal
19
Congratulations! You have built a low-‐pass filter! This filter can also be converted to a high-‐pass, or a band-‐pass filter, by right-‐clicking on the Filter VI and changing the parameters.
Testing the Filter
Now that you have a Low-‐Pass Filter, let’s see how it works!
The purpose of the following section is to examine the performance of the filter, and find the “3 dB” point. The 3dB point is an important characteristic of a filter – it is the frequency where the output power is half of the input power. For convenience it’s often referred to as the 3dB point, because on the decibel scale, this half-‐power point corresponds to -‐3dB.
# of dB = M dB = 20 log(Vout/Vin) with Vout<Vin thus Vout = (Vin) * 10 ( -‐M / 20 )
Therefore, for an input signal of 1.00 Vpp, the 3 dB voltage would be (1.00 V)*(10^(-‐3/20) = 0.707 Vpp. This corresponds to +0.354V peak on the graph, assuming the signal is centered on 0 Volts and there is no DC offset voltage shifting it up or down.) Different types of filters have varying trade-‐offs in the rate of cut-‐off, design complexity, implementation cost, etc. Note… in LabVIEW we can directly plot the dB output of the signal! HOWEVER… we are going to measure and calculate it the old-‐fashioned way, so that we learn how to do it. This will help us to understand how it works, so we can develop an intuition for filter design. This intuition is valuable because it helps us to notice if our design produces unexpected results, so we can adjust it. It is good to do a ‘sanity check’ on the output of your designs and your equations.
myDAQ: Filter a Signal
20
QUESTION 1. What do you see? Anything expected? Anything unexpected?
Hint: This is partly due to the type of filter applied, and the order of the filter. Although the output filtered signal appears to be less optimal than the input, when we begin to combine input signals, and observe noisy signals, we will understand why we’d want to apply a filter.
QUESTION 2: What is the 3 dB Frequency of 3rd Order Low-‐Pass Butterworth Filter with a cut-‐off frequency of 1kHz?
Hint: take the VI you just built, and set the Lower Cut-‐off to 1 kHz. Then using the table below, type the Frequency Measurements into the Frequency box, and read the measurements from the Sine and Filtered Signal Amplitudes (NOT the spectrographs!) Also, consider the sampling theorem and set the number of samples per second (fs) in the signal source such that the signals are properly sampled and the cut-‐off frequency at the filter is at least less than fs/2. You should check what the signal looks like at the highest frequency in the time domain plot by observing 1-‐2 periods of the signal (change the x-‐axis , that is time, scale). 2.1 Fill in the following table.
Input Frequency Input Amplitude Output (Filtered) Amplitude 1.5 kHz 1.0 kHz 500 Hz 100 Hz 50 Hz
myDAQ: Filter a Signal
21
10 Hz
2.2 The observed 3 dB cut-‐off frequency is: ____________________________________________
2.3 The Calculated 3 dB cut-‐off frequency is: ____________________________________________
2.4 What is the difference? Possible causes for this difference: ____________________________________________
2.5 Repeat for a frequency of your choosing.
Choose your own frequency, and repeat the process.
Input Frequency Input Amplitude Output (Filtered) Amplitude
2.6 The observed 3 dB cut-‐off frequency is: ____________________________________________
2.7 The Calculated 3 dB cut-‐off frequency is: ____________________________________________
2.8 What is the difference? Possible causes for this difference: ____________________________________________
QUESTION 3: What is the 3 dB Frequency of 3rd Order Low-‐Pass Chebyshev Filter with a cut-‐off frequency of 1kHz?
Hint: take the VI you just built, and set the Lower Cut-‐off to 1 kHz. Then type the Frequency Measurements into the Frequency box, and read the measurements from the Sine and Filtered Signal Amplitudes (NOT the spectrographs!)
myDAQ: Filter a Signal
22
In the BLOCK DIAGRAM, RIGHT-‐CLICK ON FILTER, AND CLICK PROPERTIES. CHANGE THE TOPOLOGY TO CHEBYSHEV. RE-‐SAVE YOUR VI AS ‘my_filter_chebyshev.vi’. 3.1 Fill in the following table.
Input Frequency Input Amplitude Output (Filtered) Amplitude 1.5 kHz 1.0 kHz 500 Hz 100 Hz 50 Hz 10 Hz
3.2 The observed 3 dB cut-‐off frequency is: ____________________________________________
3.3 The Calculated 3 dB cut-‐off frequency is: ____________________________________________
3.4 What is the difference? Possible causes for this difference: ____________________________________________
Spectral Analysis after filtering a Broad Spectrum Signal In the last example, we passed a pure tone (Sine wave) through a filter. A sine wave, in theory, only contains one frequency. Filters can attenuate pure tones, but they are even more useful for broad spectrum signals (which have multiple frequencies. We will now observe the filter’s effects on a signal that contains many frequencies – a Square wave. In theory, a square wave contains infinite frequencies. We will observe the change in the signal when we remove some of those frequencies.
myDAQ: Filter a Signal
23
24. In the Block Diagram, right-‐click on the Simulate Signal VI and select Properties.
25. The Configure Stimulate Signal window
will appear. Change the signal type to Square. SAVE YOUR WORK AS my_filter_square.vi !!
myDAQ: Filter a Signal
24
26. Open the Front Panel and run the filter.
QUESTION 5. What do you see? Anything expected? Anything unexpected?
Hint: Observe the multimodal input signal, and the changes in the different components in the output signal.