ThinkDSP
This notebook contains an exercise I removed from Chapter 9 because I think it was more confusing than useful.
Copyright 2015 Allen Downey
Exercise: In the section on cumulative sum, I mentioned that some of the examples don't work with non-periodic signals. Try replacing the sawtooth wave, which is periodic, with the Facebook stock price data, which is not, and see what goes wrong.
I think there are actually two problems: the input signal is biased and it's non-periodic.
Solution: I'll start by loading the Facebook data again.
And making a Wave
I'll compute the daily changes using Wave.diff
:
Now I'll run the cumsum
example using change
as the input wave.
Note: Try this with and without unbiasing.
Here's the spectrum before the cumulative sum:
The output wave is the cumulative sum of the input
And here's its spectrum
Now we compute the ratio of the output to the input:
We can compare them with the cumsum filter:
The ratios follow the shape of the filter.
Now we can compute the output wave using the convolution theorem, and compare the results: