For today you should:
1) Read Chapter 3 on NB and make comments/ask questions.
2) Work on exercises.
3) Review case study ideas in Lecture 02.
Today:
1) Frequency, cycles, and phase.
2) Diagnostic 1
3) Non-periodic signals
4) Spectrograms
For next time:
1) Read Chapter 4 on NB and make comments/ask questions.
2) Work on exercises.
Suppose you are watching a spinning wheel and counting how many times it has spun.
cycles = number of times it has gone around, which you can split into an integer (number of complete cycles) and a fraction (where you are in the current cycle.
phase = 2 pi cycles = cycles expressed in radians
cycles and phase are PON (plain old numbers, dimensionless, no units)
phase is useful for evaluating sine and cosine signals:
class CosSignal(Signal):
def evaluate(self, ts):
phases = PI2 * self.freq * ts + self.offset
ys = self.amp * math.cos(phases)
return ys
For other kinds of signals, its easier to work with cycles:
class SawtoothSignal(Sinusoid):
cycles = self.freq * ts + self.offset / PI2
frac, _ = numpy.modf(cycles)
ys = normalize(unbias(frac), self.amp)
return ys
When frequency is constant:
cycles = f t
phase = 2 pi f t
More generally, when frequency varies in time:
cycles = \int_0^t f(blah) dblah
phase = 2 pi \int_0^t f(blah) dblah
So, for example:
class Chirp(Signal):
def evaluate(self, ts):
"""Evaluates the signal at the given times.
ts: float array of times
returns: float wave array
"""
freqs = numpy.linspace(self.start, self.end, len(ts)-1)
return self._evaluate(ts, freqs)
def _evaluate(self, ts, freqs):
dts = numpy.diff(ts)
dps = PI2 * freqs * dts
phases = numpy.cumsum(dps)
phases = numpy.insert(phases, 0, 0)
ys = self.amp * numpy.cos(phases)
return ys
Exercise 3.1 asks you to combine Chirp and Sawtooth to make a SawtoothChirp.