Lab 7: Signal

Note: This assignment has no GitHub Classroom link (see the Getting Started & Submission Format section below)

Please put your answers to written questions in this lab, if any, in your submission file.

Introduction

Welcome to Lab 7! As you might know, video, audio, and even electrocardiograms of your heart are all innately continuous signals. However, computers can only store and process a finite collection of values, which means that those continuous signals must be somehow converted into discrete signals (a quick reminder of their differences here).

In this lab, you will explore how we transform signals between continuous and discrete representations, and what information will be preserved, distorted, or otherwise lost when we use different signal processing techniques.

To help simplify your conceptual understanding of this topic, all of the examples used throughout this lab are one-dimensional. Nonetheless, the same ideas apply to multi-dimensional graphics concepts such as image filtering and resizing, which you will be doing in Project 4: Antialias.

Objectives

  1. Understand the Nyquist limit and understand how to choose an appropriate sampling rate to avoid aliasing,
  2. Compare reconstruction filters and describe how they affect the quality of a reconstructed signal,
  3. Interpret a signal in both its spatial (or time) domain and frequency domain, and
  4. Explain the relationship between a signal and its Fourier-domain dual.

Conceptual Background

Signals and Domains

A signal, in simple terms, is a function whose value changes over some input domain. A one-dimensional audio wave, for example, assigns an amplitude to each moment in time (a.k.a. the time domain). Similarly, an image can be viewed as a two-dimensional signal that assigns a color to each location on the image plane (a.k.a. the spatial domain). Note that the terms "time domain" and "spatial domain" both describe the same kind of representation: signal values as a function of their independent variables (time or position, depending on the context of the signal). Since we are mainly working with image processing, we will refer to the input domain as the spatial domain from here on.

Another important concept is the frequency domain, which tells us how much of each frequency is present in the signal. In an image, for example, low frequencies correspond to broad regions of slowly changing color, while high frequencies generally represent sharp edges and fine details.

The Fourier transform converts a signal from its spatial domain to its corresponding frequency domain, both of which represent the same signal but are useful for different purposes.

Example of Spatial Domain vs. Frequency Domain
Figure 1: Example of Spatial Domain vs. Frequency Domain

Sampling and Reconstruction

Sampling converts a continuous signal into a discrete one by recording its value at a finite number of locations. The sampling rate determines how many samples we take per unit of the input domain. You will learn about the Nyquist limit and its relation to the sampling frequency below.

To display and use sampled data, we also need to construct values between samples to make up for the lost parts when transforming a continuous signal into a discrete one. This process is called reconstruction.

Filtering and Fourier Duality

Lastly, a filter changes a signal by preserving some frequencies and suppressing others. A low-pass filter keeps low frequencies and removes high frequencies, producing a smoother or blurrier signal. On the other hand, a high-pass filter emphasizes rapid changes. Before sampling, we often apply a low-pass filter to remove details with high frequencies that the sampling process cannot represent after reconstruction. This is called pre-filtering.

Connecting back to the concept of multiple domains previously, operations in one domain have related effects in the other. Specifically, multiplication in the frequency domain corresponds to convolution in the spatial domain. Thus, multiplying a frequency spectrum by a low-pass filter is equivalent to convolving the original signal with a spatial-domain blur kernel. This relationship is known as the Fourier duals: a function in one domain has a corresponding function in the other. Please refer to the lecture slides if you need a refresher on this topic.

Getting Started & Submission Format

As you may notice, there is no executable code for this lab. Instead, there will be a few interactive components that you will play around with and conceptual questions that you will answer. You may write your answers to these conceptual questions in any format you like (handwritten, typed, etc.), but we ask you to convert your file into a single PDF file and submit it to the Gradescope assignment. Please still come to TA hours to get your answers checked off.

The Nyquist Limit

The Nyquist limit, also known as the Nyquist frequency, states that, in order to accurately sample a continuous signal without introducing aliasing, we must sample at a rate greater than two times the highest frequency present in the signal. This means that if we want to capture frequencies up to , we need to sample at a rate of at least . We will see why that is shortly.

First, please open up the Nyquist limit demo here. In this demo, we have a few components. Feel free to play around with them:

  • : This is the original continuous signal that we want to sample. In this demo, it is a regular sine function.
    • You can adjust its frequency of this signal using the slider from to .
  • : This is a graph of discrete samples of the original signal
    • You can adjust the number of samples taken from using the slider from to .
    • Note that we are sampling at a constant rate in this demo (i.e., the samples are evenly spaced).
  • : This is the attempted reconstruction of the original signal , obtained by applying a Gaussian filter to the discrete samples .

Sampling at Exactly the Nyquist Limit

Now, fix the frequency at , and set the number of samples to . This means that we are sampling at exactly the Nyquist limit. You should notice that the reconstructed signal is a flat line, which is not a good reconstruction of the original signal .

Answer the following questions briefly:

  • Why is the reconstruction a flat line? Remember to check the specifications above of how , , and are defined.
  • Outside of this demo, will it always be the case that sampling at exactly the Nyquist limit will result in a flat line reconstruction?

Trying Different Sample Rates

Now, while keeping the frequency at , try changing the number of samples to and . You should notice that the reconstruction is no longer a flat line, but it is still not a perfect reconstruction of the original signal.

Answer the following questions briefly:

  • Why does the reconstruction still look not exactly like the original signal?

  • What is the important quality these reconstructed functions capture, even if it is not a perfect reconstruction?

    Hint:

    Try changing the number of samples to and instead. What property is different in those reconstructions compared to the ones with and samples?

Using Different Filters

As a reminder once again, this demo uses a Gaussian filter in to reconstruct the original continuous signal from the discrete samples.

Answer the following questions briefly:

  • What happens if we were to use a triangle filter instead of a Gaussian filter? How would you expect the quality of the reconstruction to change?
  • What about a sinc filter?

Duality of Domains

Visualizing Sinc and Box Duals

Take a look at the box function in Figure 1 (left) below. Its dual in the frequency domain is the sinc function, in Figure 1 (right). Note that there are no labels on the axes, by design.

A box functionA sinc function
Figure 2: A box function with its dual, a sinc function.

Draw out a sketch of the dual of the box function in Figure 2. Your drawing doesn't need to be perfectly accurate; but enough to show that you understand the concept.

Another box function, about twice as wide as before
Figure 3: Another box function, about twice as wide as before.

Frequency Plots

Now, examine the following frequency plot of a 1D, continuous signal. If you were going to sample this signal at a rate of 8 samples per unit, to avoid aliasing, you would use what we know about the Nyquist limit to pre-filter it.

Draw out the new frequency plot after someone has performed this pre-filtering step optimally. Make sure to include any relevant amplitude and/or frequency values.

A frequency spectrum. It plots amplitude against frequency.
Figure 4: A frequency spectrum. It plots amplitude against frequency.

End

Congrats on finishing the Signal lab! Now, it's time to submit your responses and get checked off by a TA. Be prepared to go through your answers with a TA during hours.

Submission

Submit your file, in PDF format, to the "Lab 7: Signal" assignment on Gradescope, then get checked off by a TA at hours.

Reference the GitHub + Gradescope Guide here.