This shows you the differences between two versions of the page.
milestone_2_task_2 [2023/01/18 14:15] scott [Resources] |
milestone_2_task_2 [2023/01/23 12:11] (current) scott [Anti-Aliasing Filter Design] |
||
---|---|---|---|
Line 16: | Line 16: | ||
===== General Notes ===== | ===== General Notes ===== | ||
- | For the noise analysis, you will use a previously measured time-domain signal of optical noise in a lab room. Like you did in Milestone 1 Task 1, you will analyze a signal that is 500ms (half second) in duration, sampling at a rate of 100 ksamples/s, yielding a total of 50,000 samples. In this case, we simply want an optical noise signal without any player frequency signal on top of it. While you could use one of your 'noise only' signals acquired from last lab, I suggest you use the provided optical noise signal {{:light.zip|light.zip}}, since it is known to have sufficient noise to be detectable in this lab. | + | For the noise analysis, you will use a previously measured time-domain signal of optical noise in a lab room. Like you did in Milestone 1 Task 1, you will analyze a signal that is 500ms (half second) in duration, sampling at a rate of 100 ksamples/s, yielding a total of 50,000 samples. In this case, we simply want an optical noise signal without any player frequency signal on top of it. While you could use one of your 'noise only' signals acquired from last lab, I suggest you use the provided optical noise signal {{:light.zip|}}, since it is known to have sufficient noise to be detectable in this lab. |
===== Specifications ===== | ===== Specifications ===== | ||
Line 31: | Line 31: | ||
==== Optical Noise Sample ==== | ==== Optical Noise Sample ==== | ||
- | * Time-domain signal of optical noise: {{:light.zip|light.zip}} | + | * Time-domain signal of optical noise: {{:light.zip|}} |
+ | * Format: zipped MATLAB file (.mat) for storing workspace variables | ||
+ | * Contains two variables, t and y | ||
- | After uncompressing the archive, use the MATLAB ''load'' command to read in the data. | + | After unzipping the archive, use the MATLAB ''load'' command to read in the data. |
<code> | <code> | ||
Line 63: | Line 65: | ||
Use the MATLAB fft command to produce the Fourier transform of your signal. Your signal should look like the image shown below (if you only plot the positive frequency axis after doing the FFT). Zoom in on the spikes and make sure that they are centered at 3 kHz and 6 kHz. If your signal does not look like this plot then you might want to go back and review the [[MATLAB |MATLAB fft command]]. | Use the MATLAB fft command to produce the Fourier transform of your signal. Your signal should look like the image shown below (if you only plot the positive frequency axis after doing the FFT). Zoom in on the spikes and make sure that they are centered at 3 kHz and 6 kHz. If your signal does not look like this plot then you might want to go back and review the [[MATLAB |MATLAB fft command]]. | ||
- | {{ :sin_fft_2.jpg?300 |}} | + | {{ :sin_fft_2.jpg?400 |}} |
Now you are going to down-sample the data to a sampling frequency of Fs = 10 kHz. (This is the sampling frequency that you designed your 10 bandpass filters for.) We will accomplish this by taking every tenth sample of the original signal. Here is MATLAB code to perform the down-sampling: | Now you are going to down-sample the data to a sampling frequency of Fs = 10 kHz. (This is the sampling frequency that you designed your 10 bandpass filters for.) We will accomplish this by taking every tenth sample of the original signal. Here is MATLAB code to perform the down-sampling: | ||
Line 77: | Line 79: | ||
Use the MATLAB fft command to calculate the frequency domain plot of your new downsampled signal. You should produce a plot that looks something like this: | Use the MATLAB fft command to calculate the frequency domain plot of your new downsampled signal. You should produce a plot that looks something like this: | ||
- | {{::alias_fig2_v2.png?200|}} | + | {{ :alias_fig2_v2.png?600 |}} |
Again, you can see the formerly 6 kHz signal aliasing in to the new frequency range as a 4 kHz signal. | Again, you can see the formerly 6 kHz signal aliasing in to the new frequency range as a 4 kHz signal. | ||
Line 85: | Line 87: | ||
The performance of the laser tag system can be improved by reducing the noise that ultimately ends up across the band of frequencies we care about (~1 - 5 kHz). We are not going to be investigating all of the noise sources in our system, but we are going to look into one of the easiest noise sources to reduce: the optical noise produced by the fluorescent lights in our lab room. | The performance of the laser tag system can be improved by reducing the noise that ultimately ends up across the band of frequencies we care about (~1 - 5 kHz). We are not going to be investigating all of the noise sources in our system, but we are going to look into one of the easiest noise sources to reduce: the optical noise produced by the fluorescent lights in our lab room. | ||
- | We measured the signal produced by the fluorescent lights and saved it as a MATLAB file. {{:light.zip|You can download the data here.}} This data is all noise. After unzipping this file you can load it directly into MATLAB. It contains two variables, t and y. (Use the MATLAB load command.) | + | We measured the signal produced by the fluorescent lights and saved it as a MATLAB file ({{:light.zip|}}). This data is all noise. After unzipping this file you can load it directly into MATLAB. It contains two variables, t and y. (Use the MATLAB load command.) |
You should get a plot similar to the following. | You should get a plot similar to the following. | ||
- | {{ :alias_fig3.jpg?200 |}} | + | {{ :alias_fig3.jpg?600 |}} |
As mentioned, this signal is all noise. It is hard to imagine the ability to detect a signal with an amplitude of ~10mV if the noise has an amplitude of ~1000 mV. That is the beauty of signal processing. To be able to understand this noise signal we need to plot it in the frequency domain. | As mentioned, this signal is all noise. It is hard to imagine the ability to detect a signal with an amplitude of ~10mV if the noise has an amplitude of ~1000 mV. That is the beauty of signal processing. To be able to understand this noise signal we need to plot it in the frequency domain. | ||
Line 101: | Line 103: | ||
Produce a frequency domain plot of the noise you loaded from the file provided. It should look something like the following: | Produce a frequency domain plot of the noise you loaded from the file provided. It should look something like the following: | ||
- | {{ :alias_fig4.jpg?300 |}} | + | {{ :alias_fig4.jpg?600 |}} |
- | This plot shows that the noise in clumped around three main locations (1) low frequencies, (2) near 21 kHz, and near 42 kHz. | + | This plot shows that the noise is clumped around three main locations (1) low frequencies, (2) near 21 kHz, and near 42 kHz. |
- | + | ||
- | For the rest of this lab, you are going to use your own acquired optical noise data instead of the data that we provided you. Just like in Milestone 1, export 500ms of data sampled at 100 kHz (yielding 50,000 samples), but this time point your sensor upwards towards the fluorescent lights in the lab room. Plot the FFT of your new acquired optical noise data, with an appropriate frequency axis and paying attention to the amplitude scaling of your FFT data. | + | |
Zoom in on the plot and calculate the amplitude of the frequency components in the band where our player frequencies are located (1kHz < f < 5 kHz). | Zoom in on the plot and calculate the amplitude of the frequency components in the band where our player frequencies are located (1kHz < f < 5 kHz). | ||
- | Now, as we discussed in lab lecture, this data will be acquired at a sampling frequency of 100 kHz by the ZYBO board. However, the 10 bandpass filters that we designed in Milestone 2 Task 1 are designed to process signals sampled at 10 kHz (since we only care about signals < 5 kHz and we want to keep our computations simple so our filtering can be done in real time on the ZYBO board). That means we need to down-sample the data to a 10 kHz sampling rate. | + | Now, as we discussed in lab lecture, the ZYBO board sampling frequency is 100 kHz. However, the 10 bandpass filters that we designed in Milestone 2 Task 1 are designed to process signals sampled at 10 kHz (since we only care about signals < 5 kHz and we want to keep our computations simple so our filtering can be done in real time on the ZYBO board). That means we need to down-sample the data to a 10 kHz sampling rate. |
Let's first try getting to the new lower sampling rate by simply using every tenth sample like we did before when we reviewed aliasing. Down-sample your measured signal (which is 50,000 samples long, sampled at 100 kHz) to a 5,000 sample signal by taking every tenth sample. | Let's first try getting to the new lower sampling rate by simply using every tenth sample like we did before when we reviewed aliasing. Down-sample your measured signal (which is 50,000 samples long, sampled at 100 kHz) to a 5,000 sample signal by taking every tenth sample. | ||
- | Plot the down-sampled signal in both the time domain and frequency domain. It should look similar to the following (although you may have some more or less pronounced frequency peaks in your own data depending on how well your receiver board filtered some of the higher frequencies): | + | Plot the down-sampled signal in both the time domain and frequency domain. It should look similar to the following : |
- | {{ :alias_fig5.jpg?300 |}} | + | {{ :alias_fig5.jpg?600 |}} |
Notice that the time domain signal looks very similar. However, the frequency domain signal now has a maximum frequency of 5 kHz (i.e., half of your new sampling frequency of 10 kHz). The noise in our desired frequency band (1kHz < f < 5kHz) is now drastically higher than it was prior to down-sampling. This increase in the noise is caused by aliasing of some of the higher frequency peaks in the original signal (in our noise data, there is a peak at f = 21 kHz and f = 42 kHz that alias into the band we are interested in). | Notice that the time domain signal looks very similar. However, the frequency domain signal now has a maximum frequency of 5 kHz (i.e., half of your new sampling frequency of 10 kHz). The noise in our desired frequency band (1kHz < f < 5kHz) is now drastically higher than it was prior to down-sampling. This increase in the noise is caused by aliasing of some of the higher frequency peaks in the original signal (in our noise data, there is a peak at f = 21 kHz and f = 42 kHz that alias into the band we are interested in). | ||
Line 132: | Line 132: | ||
When we actually implement decimation on our ZYBO board for real-time processing, that's exactly what we'll do. For now, however, let's design our FIR filter, determine the filter coefficients, and then simply use the 'filter' command in MATLAB, followed by down-sampling. This will be perfectly adequate for testing our signal processing algorithms before we implement them on the ZYBO board. | When we actually implement decimation on our ZYBO board for real-time processing, that's exactly what we'll do. For now, however, let's design our FIR filter, determine the filter coefficients, and then simply use the 'filter' command in MATLAB, followed by down-sampling. This will be perfectly adequate for testing our signal processing algorithms before we implement them on the ZYBO board. | ||
- | The specifications of the filter are provided at the top of the lab. You will be using the FIR filter design process that you used in ECEN 380 Lab #5 Task #2. For your convenience, here are links to the ECEN 380 Lab #5 and Dr. Rice's discrete filter design handout: | + | The specifications of the filter are provided at the top of the lab. You will be using the FIR filter design process that you used in ECEN 380 Lab #5 Task #2. For your convenience, here are links to the ECEN 380 Lab #5 and the discrete filter design handout: |
- | {{:lab_5_fall2016.pdf|ECEN 380 Lab #5}} | + | {{:lab5_fall2018.pdf|ECEN 380 Lab #5}} |
{{:filter_design_notes.pdf|Handout on discrete time filter design.}} | {{:filter_design_notes.pdf|Handout on discrete time filter design.}} | ||
Line 183: | Line 183: | ||
With this in mind, a low pass filter with a corner frequency of 5 kHz that operates on data sampled at 100 kHz would be a **rect** function that goes from -0.05 to 0.05 in cycles/sample. (Can you see why? We want the low-pass filter to go from -5 kHz to 5 kHz, and the data was sampled at Fs = 100 kHz. So, in units of cycles/sample, our rect goes from -5kHz/100kHz = -0.05 to 5kHz/100kHz = 0.05 cycles/sample.) | With this in mind, a low pass filter with a corner frequency of 5 kHz that operates on data sampled at 100 kHz would be a **rect** function that goes from -0.05 to 0.05 in cycles/sample. (Can you see why? We want the low-pass filter to go from -5 kHz to 5 kHz, and the data was sampled at Fs = 100 kHz. So, in units of cycles/sample, our rect goes from -5kHz/100kHz = -0.05 to 5kHz/100kHz = 0.05 cycles/sample.) | ||
- | IMPORTANT: If you are using the FIR filter design code from the Dr. Rice's filter design handout, note that the frequencies are done in units of cycles/sample. Also note that the code given produces a bandpass filter (so you'll need to set your center frequency to 0 for a lowpass filter), and the B parameter in that code is really the full width of the filter, not the half width. If you took ECEN 380 Fall 2016 or later, your code from Lab #5 Task #2 is likely written with frequencies in Hz. | + | IMPORTANT: If you are using the FIR filter design code from the filter design handout, note that the frequencies are done in units of cycles/sample. Also note that the code given produces a bandpass filter (so you'll need to set your center frequency to 0 for a lowpass filter), and the B parameter in that code is really the full width of the filter, not the half width. If you took ECEN 380 Fall 2016 or later, your code from Lab #5 Task #2 is likely written with frequencies in Hz. |
Plot the resulting sinc function for both a long (N = 2001) and short (N = 21) filter length. Your resulting plots should look like the following: | Plot the resulting sinc function for both a long (N = 2001) and short (N = 21) filter length. Your resulting plots should look like the following: | ||
- | {{ :filter_time.jpg?200 |}} | + | {{ :filter_time.jpg?600 |}} |
| | ||
Notice how the longer filter looks a lot more like the sinc function than the shorter one. | Notice how the longer filter looks a lot more like the sinc function than the shorter one. | ||
Line 195: | Line 195: | ||
Use the **freqz** function to plot the frequency response of your N = 2001 and N = 21 length filters. Your plots should look like the following: | Use the **freqz** function to plot the frequency response of your N = 2001 and N = 21 length filters. Your plots should look like the following: | ||
- | {{ :filter_freq.jpg?200 |}} | + | {{ :filter_freq.jpg?600 |}} |
//Notice that the long filter looks a lot more like your desired low pass filter.// | //Notice that the long filter looks a lot more like your desired low pass filter.// | ||
Line 232: | Line 232: | ||
This wider transition band means that some noise within the transition band can alias into our passband. However, we fortunately don't have much optical noise in these frequency bands, as shown here: | This wider transition band means that some noise within the transition band can alias into our passband. However, we fortunately don't have much optical noise in these frequency bands, as shown here: | ||
- | {{ :alias_fig6.jpg?200 |}} | + | {{ :alias_fig6.jpg?600 |}} |
You can see that the noise is fairly low in the transition band, so our looser specification should not result in too much additional noise aliasing, and shouldn't have too much impact on our final signal. | You can see that the noise is fairly low in the transition band, so our looser specification should not result in too much additional noise aliasing, and shouldn't have too much impact on our final signal. | ||
Line 257: | Line 257: | ||
==== Noise Reduction ==== | ==== Noise Reduction ==== | ||
- | Now that you have finished the design of the anti-aliasing filter, your final job is to see how well it reduces the aliased noise. Do the following: | + | Now that you have finished the design of the anti-aliasing filter, your final job is to see how well it reduces the aliased noise. Do the following: |
- | - Load in your optical noise sample (the one that is 500ms long with 50,000 samples) | + | - Load in the optical noise sample ({{:light.zip|}}, which is 500ms long with 50,000 samples) |
- | - Plot the noise spectrum (frequency domain) **without using your FIR filter** (just like you did before) | + | - Plot the noise spectrum (frequency domain) **without using your FIR filter** (like you did before) |
- Down-sample to Fs = 10kHz | - Down-sample to Fs = 10kHz | ||
- Plot the noise from 1kHz to 5 kHz | - Plot the noise from 1kHz to 5 kHz | ||
- | - Plot the noise spectrum (frequency domain) **using your FIR filter before down-sampling** | + | - Plot the noise spectrum (frequency domain) **using your FIR filter** |
- | - Filter the noise signal with your FIR filter | + | - Filter the noise signal with your FIR filter //before down-sampling// |
- Down-sample the signal to Fs = 10kHz | - Down-sample the signal to Fs = 10kHz | ||
- Plot the noise from 1kHz to 5 kHz | - Plot the noise from 1kHz to 5 kHz | ||
Line 323: | Line 323: | ||
The following items need to be shown to the TAs for pass off: | The following items need to be shown to the TAs for pass off: | ||
- MATLAB code portion showing design of FIR low pass anti-aliasing filter | - MATLAB code portion showing design of FIR low pass anti-aliasing filter | ||
- | - List of FIR filter coefficients | + | - List of FIR filter coefficients (with at least 17 significant digits) |
- List of achieved filter specifications | - List of achieved filter specifications | ||
- Frequency response plot of the low pass FIR filter | - Frequency response plot of the low pass FIR filter |