Lab 5: Signal and Noise

Due Nov 18th, 4pm

The goal: Use averaging to see small signals. We'll implement some hardware (i.e. Arduino based) based averaging to detect an artificial signal that you can't see but you know should be there. This is a standard part of experimental design. Inject a fake 'signal' into your experiment before you try to measure nature to make sure your experiment can actually detect what you are tying to detect.


Introductory Bits

The basic idea for this lab is to create an artificial "signal" and then see what we can do experimentally to make it easier or harder to detect. The fake signal will be an oscillating brightness of an LED. This can be accomplished by using the PWM output and changing the brightness value like so: \begin{equation} f(t) = A+B\sin(\omega t) \end{equation} where $A$ is the baseline brightness, and the oscillating term is added to it. $B$ will indicate the strength of the added signal and the frequency is determined by the argument of the $\sin()$ function.

The following simple sketch will create an oscillating ($f = 1 \; \textrm{Hz}$) brightness on the LED. Try it out before going any further. (Don't forget to include a 220 $\Omega$ resister in series with your LED! Otherwise, the arduino will supply too much current and it will overheat and destroy the LED)


  const int ledPin = 9;       // pin that the LED is attached to
  const int TWOPI = 2*3.1415926;

  int brightness;

  void setup() {
    pinMode(ledPin, OUTPUT);
  }

  void loop() {
    brightness = 100+50*sin(1.0*TWOPI*millis()/1000);
    analogWrite(ledPin,brightness);
    delay(5);
  }

Next, set up a voltage divider circuit with the PhotoResistor so that you can measure the brightness of the LED.

You should be able to reproduce this effect, shown in the animation. The LED is changing brightness periodically. Play with the parameters of the $\sin()$ function to make sure you understand what's going on there.

And you should be able to obtain a plot like this of the 'faked' signal.

Make sure you can do all this before moving forward. (This is just the introduction - the actual experiment hasn't started.)


If you look closely at your data (try adding the line: ax.set_xlim([1,3]) right after your plot command to restrict the range of the horizontal axis), you should a not very pretty sin function. The amplitude is certainly oscillating, but there is a lot of 'noise'. This noise is an artifact arising from the fact that in addition to our added oscillations at frequency $f$, there is also a blinking occurring at a much faster frequency due to the PWM that controls the brightness. Remember, the LED is only changing it's apparent brightness to our eyes because the duty cycle is being changed.

You can review this concept here: https://www.arduino.cc/en/Tutorial/Foundations/PWM if it's still unclear.

The experiment

  1. Impliment an averaging function into your sketch so that the data recorded is averaged over a short time. This will effectively 'smooth out' the noise. You can use this tutorial as a starting point: Arduino Smoothing
  2. You should be able to obtain a plot that shows a much smoother sinusoidal function.

  1. Now, Prepare three such plots, for three different averaging widths: 1, 5, and 10. (see tutorials on course page for python code to plot multiple time series)

  1. Now, go back to your 'fake' signal function:
      
        brightness = 100+50*sin(1.0*TWOPI*millis()/1000);
    
    The 50 is effectively the amplitude of the fake signal that we are trying to detect. Try lowering that to say, 5 or so, and adjust your averaging routine so that you can detect it (and look with your eyes at the LED - you probably can't detect any change in brightness visually). Prepare a plot of that very small signal. Here's a plot where the amplitude is just 2. Notice how we can see the resolution of the Analog-Digital converter here.

If we didn't include any averaging, then our small signal measurement would look like this. It's impossible to see the 1 Hertz oscillations now, since they are dominated by the PWM fluctuations that are occurring at much faster times scales.

Extra

Also, the above lab used what could be called hardware averaging, since we modified the measurement instrumentation to do the averaging. Another tactic can be software averaging which would involve something the noisy data using code, after the measurement is taken. So far we have usually done all our 'processing' after the measurement. This lab focuses on doing a little more work during the measurement.


Report Instructions:

Your report should be formatted in a single document (pdf) that contains the following:

  1. Introductory text describing the experiment
  2. Circuit Diagram of your LED & PhotoResistor measurement setup
  3. Photograph of your board in operation.
  4. Plots showing the oscillating LED brightness you detected.
  5. Plots showing the affects of averaging parameters.
  6. Plots showing the small signal you detected
  7. Discussion of the results
  8. Any references used
  9. Links to csv/code files online.