diff --git a/main-figure/unnamed-chunk-10-1.png b/main-figure/unnamed-chunk-10-1.png new file mode 100644 index 0000000..9aa8a70 Binary files /dev/null and b/main-figure/unnamed-chunk-10-1.png differ diff --git a/main-figure/unnamed-chunk-11-1.png b/main-figure/unnamed-chunk-11-1.png new file mode 100644 index 0000000..7bd3218 Binary files /dev/null and b/main-figure/unnamed-chunk-11-1.png differ diff --git a/main-figure/unnamed-chunk-12-1.png b/main-figure/unnamed-chunk-12-1.png new file mode 100644 index 0000000..fbf70df Binary files /dev/null and b/main-figure/unnamed-chunk-12-1.png differ diff --git a/main-figure/unnamed-chunk-13-1.png b/main-figure/unnamed-chunk-13-1.png new file mode 100644 index 0000000..7820ef9 Binary files /dev/null and b/main-figure/unnamed-chunk-13-1.png differ diff --git a/main-figure/unnamed-chunk-9-1.png b/main-figure/unnamed-chunk-9-1.png new file mode 100644 index 0000000..4a6348c Binary files /dev/null and b/main-figure/unnamed-chunk-9-1.png differ diff --git a/main.Rpres b/main.Rpres index 04e0cc1..8130890 100644 --- a/main.Rpres +++ b/main.Rpres @@ -51,7 +51,7 @@ $f:\mathbb{R}\rightarrow\mathbb{C}$ $$ \begin{aligned} f(x) &= \int_{-\infty}^\infty F(s) e^{2\pi i s x} ds \\ - F(s) &= \int_{-\infty}^\infty f(x) e^{-2\pi i s x} ds \\ + F(s) &= \int_{-\infty}^\infty f(x) e^{-2\pi i s x} dx \\ \end{aligned} $$ @@ -327,17 +327,241 @@ plot(freqs / w1,Pv, type="b", par(mfrow = c(1,1)) ``` +Example: Time-varying signal 2 +======================================================== + +```{r, echo=FALSE} +N <- 1024*256 +w1 <- 5 +w2 <- 0.7 +w3 <- 1 +a1 <- 15 +a2 <- 3 +a3 <- 1 +mu <- 5 +sigma <- 0.5 +noise <- 3 + +x <- seq(from=0, to=10,length.out = N) + +y0 <- a1*sin(w1*x*2*pi)*dnorm(x, mu, sigma) +y1 <- a2*sin(w2*x*2*pi) + a3*sin(w3*x*2*pi) +y <- y0 + y1 + rnorm(n = N, mean = 0, sd = noise) +par(mfrow = c(2,1)) +plot(x,y1,type="l", ylim = c(-10, 10), + xlab = "t", + ylab = "f(t)") +lines(x,y0, col = "blue", lwd=2) +plot(x,y,type="l", + xlab = "t", + ylab = "f(t)") +par(mfrow = c(1,1)) +``` + +*** + +```{r, echo=FALSE} +Dt <- (max(x) - min(x)) / N +Dw <- 1 / (N * Dt) +Y <- fft(y)/N +P <- Mod(Y)^2 +freqs <- (seq(from=0, to=N-1) * Dw) +plot(freqs / w1,P, type="b", + xlim=c(0,1.2), + xlab = expression("w/w"[1]), + ylab = "P") +``` + + +Short-time Fourier Transform (STFT) +======================================================== +incremental: true + +Make Fourier Transform of *short* segments in the timeseries using a *window* function centered at $\tau$, $w(t-\tau)$ + +$$\hat{F}(\omega, \tau) = +\int_{-\infty}^\infty f(t) w(t-\tau) e^{-2\pi i \omega t} dt$$ + +**Problem:** Choose an appropriate window width + +Frequency vs. time resolution + + +Wavelet transforms +======================================================== +incremental: true + +**Idea:** + +- Narrow windows for large frequencies (good time resolution) +- Wide windows for small frequencies (good frequency resolution) + +Choose a *localized wave* (mother wavelet) $\psi(t)$ and define + +$$\psi_{a,b}(t)=\frac{1}{\sqrt{a}}\psi\left(\frac{t-b}{a}\right)$$ Wavelet transforms ======================================================== +incremental: true + +Example: Mexican-hat wavelet + +$$\psi(t) = \left(1-t^2\right)e^{-t^2/2}$$ +$$\psi_{a,b}(t)=\frac{1}{\sqrt{a}}\psi\left(\frac{t-b}{a}\right)$$ + +*** + +```{r,echo=FALSE} +mhw <- function(t, a, b) { + return((1/sqrt(a)) * (1-((t-b)/a)^2) * exp(-((t-b)/a)^2/2)) +} +x <- seq(from=-5, to=5, length.out = 1000) +y0 <- mhw(x,1.2,0) +y1 <- mhw(x,0.2,0) +plot(x,y1, type="l", xlab = "t", ylab = expression(psi)) +text(0.6,2, labels = "a=0.2") +lines(x,y0, col="blue") +text(1,0.8, labels = "a=1.2", col="blue") +``` + + +Definition of wavelet transforms +======================================================== + +Given $f\in L^2(\mathbb{R})$, we define its *continuous wavelet transform* with respect to the wavelet $\psi$ as + +$$\mathcal{W}_{\psi}[f] (a,b) = \int_{-\infty}^\infty f(t)\overline{\psi_{a,b}(t)}dt$$ + +For $\mathcal{W}_\psi[f]$ to be invertible we require + +$$ 0 < C_{\psi}\equiv\int_{-\infty}^\infty +\frac{\left|\hat{\psi}(\omega)\right|^2}{\left|\omega\right|} d\omega +<\infty $$ + +Example: Time-varying signal CWT +======================================================== + +```{r, echo=FALSE} +N <- 1024*256 +w1 <- 5 +w2 <- 0.7 +w3 <- 1 +a1 <- 15 +a2 <- 3 +a3 <- 1 +mu <- 5 +sigma <- 0.5 +noise <- 3 + +x <- seq(from=0, to=10,length.out = N) + +y0 <- a1*sin(w1*x*2*pi)*dnorm(x, mu, sigma) +y1 <- a2*sin(w2*x*2*pi) + a3*sin(w3*x*2*pi) +y <- y0 + y1 + rnorm(n = N, mean = 0, sd = noise) +par(mfrow = c(2,1)) +plot(x,y,type="l", + xlab = "t", + ylab = "f(t)") +Dt <- (max(x) - min(x)) / N +Dw <- 1 / (N * Dt) +Y <- fft(y)/N +P <- Mod(Y)^2 +freqs <- (seq(from=0, to=N-1) * Dw) +plot(freqs / w1,P, type="b", + xlim=c(0,1.2), + xlab = expression("w/w"[1]), + ylab = "P") +par(mfrow=c(1,1)) +``` + +*** + +Mexican hat CWT + +![](tvs1.png) + +Example: Time-varying signal CWT 2 +======================================================== + +Haar CWT + +![](tvs2.png) + +*** + +Morlet CWT + +![](tvs3.png) + + +Example: Time-varying signal CWT 3 +======================================================== + +Morlet + +![](tvs4.png) + +*** + +Mexican-hat + +![](tvs5.png) + + +Parseval's relation for wavelets +======================================================== + +$$ +\int_{-\infty}^\infty\int_{-\infty}^\infty \mathcal{W}_\psi f (a,b)\overline{\mathcal{W}_\psi g (a,b)} \frac{da db}{a^2} = C_{\psi}\langle f,g\rangle +$$ + +where + +$$ +C_\psi \equiv \int_{-\infty}^\infty \frac{|\hat{\psi}(\omega)|^2}{|\omega|}d\omega +$$ + + +Inverse of a wavelet transform +======================================================== + +$$f(t) = \frac{1}{C_\psi}\int_{-\infty}^\infty\int_{-\infty}^\infty \mathcal{W}_\psi[f](a,b) \psi_{a,b}(t) \frac{da\ db}{a^2}$$ + + +Discrete wavelet transform +======================================================== +incremental: true + +Change the continuous version + +$$\psi_{a,b}(t) = \frac{1}{\sqrt{a}} \psi\left(\frac{t-b}{a}\right),\ \ a,b\in\mathbb{R},\ a\neq 0 $$ + +to a discrete version + +$$\psi_{m,n}(t)=2^{-m/2} \psi \left( 2^{-m} t - n \right),\ \ \ n,m \in \mathbb{Z}$$ + +When can we recover $f(t)$ from $\mathcal{W}_\psi[f](m,n)$ ? + + +Discrete wavelet transform 2 +======================================================== + +When $\psi_{m,n}$ is complete in and orthonormal in $L^2(\mathbb{R})$: + +$$f(t) = \sum_{m,n=-\infty}^\infty \langle f,\psi_{m,n}\rangle\ \psi_{m,n}(t)$$ + + +Multiresolution analysis (MRA) +======================================================== + +> MRA is really an effective mathematical framework for hierarchical decomposition of an image (or signal) into components of different scales (or frequencies). -Used to make *time-frequency* analysis Orthogonality relations ======================================================== -$$\int_{-\infty}^\infty e^{2\pi i (x-x')}dx' = \delta(x) $$ +$$\int_{-\infty}^\infty e^{2\pi i (x-x')}dx' = \delta(x)$$ $$\int_0^p e^{2\pi i x (k-l)/p}dx = \begin{cases} diff --git a/main.md b/main.md index cf87561..27eb132 100644 --- a/main.md +++ b/main.md @@ -51,7 +51,7 @@ $f:\mathbb{R}\rightarrow\mathbb{C}$ $$ \begin{aligned} f(x) &= \int_{-\infty}^\infty F(s) e^{2\pi i s x} ds \\ - F(s) &= \int_{-\infty}^\infty f(x) e^{-2\pi i s x} ds \\ + F(s) &= \int_{-\infty}^\infty f(x) e^{-2\pi i s x} dx \\ \end{aligned} $$ @@ -222,17 +222,163 @@ Example: Time-varying signal ![plot of chunk unnamed-chunk-8](main-figure/unnamed-chunk-8-1.png) +Example: Time-varying signal 2 +======================================================== + +![plot of chunk unnamed-chunk-9](main-figure/unnamed-chunk-9-1.png) + +*** + +![plot of chunk unnamed-chunk-10](main-figure/unnamed-chunk-10-1.png) + + +Short-time Fourier Transform (STFT) +======================================================== +incremental: true + +Make Fourier Transform of *short* segments in the timeseries using a *window* function centered at $\tau$, $w(t-\tau)$ + +$$\hat{F}(\omega, \tau) = +\int_{-\infty}^\infty f(t) w(t-\tau) e^{-2\pi i \omega t} dt$$ + +**Problem:** Choose an appropriate window width + +Frequency vs. time resolution + Wavelet transforms ======================================================== +incremental: true + +**Idea:** + +- Narrow windows for large frequencies (good time resolution) +- Wide windows for small frequencies (good frequency resolution) + +Choose a *localized wave* (mother wavelet) $\psi(t)$ and define + +$$\psi_{a,b}(t)=\frac{1}{\sqrt{a}}\psi\left(\frac{t-b}{a}\right)$$ + +Wavelet transforms +======================================================== +incremental: true + +Example: Mexican-hat wavelet + +$$\psi(t) = \left(1-t^2\right)e^{-t^2/2}$$ +$$\psi_{a,b}(t)=\frac{1}{\sqrt{a}}\psi\left(\frac{t-b}{a}\right)$$ + +*** + +![plot of chunk unnamed-chunk-11](main-figure/unnamed-chunk-11-1.png) + + +Definition of wavelet transforms +======================================================== + +Given $f\in L^2(\mathbb{R})$, we define its *continuous wavelet transform* with respect to the wavelet $\psi$ as + +$$\mathcal{W}_{\psi}[f] (a,b) = \int_{-\infty}^\infty f(t)\overline{\psi_{a,b}(t)}dt$$ + +For $\mathcal{W}_\psi[f]$ to be invertible we require + +$$ 0 < C_{\psi}\equiv\int_{-\infty}^\infty +\frac{\left|\hat{\psi}(\omega)\right|^2}{\left|\omega\right|} d\omega +<\infty $$ + +Example: Time-varying signal CWT +======================================================== + +![plot of chunk unnamed-chunk-12](main-figure/unnamed-chunk-12-1.png) + +*** + +Mexican hat CWT + +![](tvs1.png) + +Example: Time-varying signal CWT 2 +======================================================== + +Haar CWT + +![](tvs2.png) + +*** + +Morlet CWT + +![](tvs3.png) + + +Example: Time-varying signal CWT 3 +======================================================== + +Morlet + +![](tvs4.png) + +*** + +Mexican-hat + +![](tvs5.png) + + +Parseval's relation for wavelets +======================================================== + +$$ +\int_{-\infty}^\infty\int_{-\infty}^\infty \mathcal{W}_\psi f (a,b)\overline{\mathcal{W}_\psi g (a,b)} \frac{da db}{a^2} = C_{\psi}\langle f,g\rangle +$$ + +where + +$$ +C_\psi \equiv \int_{-\infty}^\infty \frac{|\hat{\psi}(\omega)|^2}{|\omega|}d\omega +$$ + + +Inverse of a wavelet transform +======================================================== + +$$f(t) = \frac{1}{C_\psi}\int_{-\infty}^\infty\int_{-\infty}^\infty \mathcal{W}_\psi[f](a,b) \psi_{a,b}(t) \frac{da\ db}{a^2}$$ + + +Discrete wavelet transform +======================================================== +incremental: true + +Change the continuous version + +$$\psi_{a,b}(t) = \frac{1}{\sqrt{a}} \psi\left(\frac{t-b}{a}\right),\ \ a,b\in\mathbb{R},\ a\neq 0 $$ + +to a discrete version + +$$\psi_{m,n}(t)=2^{-m/2} \psi \left( 2^{-m} t - n \right),\ \ \ n,m \in \mathbb{Z}$$ + +When can we recover $f(t)$ from $\mathcal{W}_\psi[f](m,n)$ ? + + +Discrete wavelet transform 2 +======================================================== + +When $\psi_{m,n}$ is complete in and orthonormal in $L^2(\mathbb{R})$: + +$$f(t) = \sum_{m,n=-\infty}^\infty \langle f,\psi_{m,n}\rangle\ \psi_{m,n}(t)$$ + + +Multiresolution analysis (MRA) +======================================================== + +> MRA is really an effective mathematical framework for hierarchical decomposition of an image (or signal) into components of different scales (or frequencies). -Used to make *time-frequency* analysis Orthogonality relations ======================================================== -$$\int_{-\infty}^\infty e^{2\pi i (x-x')}dx' = \delta(x) $$ +$$\int_{-\infty}^\infty e^{2\pi i (x-x')}dx' = \delta(x)$$ $$\int_0^p e^{2\pi i x (k-l)/p}dx = \begin{cases} diff --git a/tvs1.png b/tvs1.png new file mode 100644 index 0000000..5a3613d Binary files /dev/null and b/tvs1.png differ diff --git a/tvs2.png b/tvs2.png new file mode 100644 index 0000000..04dd448 Binary files /dev/null and b/tvs2.png differ diff --git a/tvs3.png b/tvs3.png new file mode 100644 index 0000000..b096984 Binary files /dev/null and b/tvs3.png differ diff --git a/tvs4.png b/tvs4.png new file mode 100644 index 0000000..9a28880 Binary files /dev/null and b/tvs4.png differ diff --git a/tvs5.png b/tvs5.png new file mode 100644 index 0000000..dfa5c4e Binary files /dev/null and b/tvs5.png differ