# 2. Unbounded Grids: the Semidiscrete Fourier Transform

## Aliasing



```julia
h = 0.25
k1 = π/(4h)
k2 = 9π/(4h)
```


```julia
using PyPlot
```


```julia
x0 = -1:h:1
xx = -1:0.01:1

y01 = sin.(k1.*x0)
y02 = sin.(k2.*x0)
yy1 = sin.(k1.*xx)
yy2 = sin.(k2.*xx);

```


```julia
plot(xx, yy1 )
plot(xx, yy2)
plot(x0, y01, "bo")
```

## Função `sinc`

$$
\text{sinc}(x) = \frac{\sin\pi x}{\pi x}
$$


```julia
xx = -15:0.01:15
yy = sinc.(xx)
plot(xx, yy, color="k")
axhline(0, ls="--", color="k")
for i in 1:15
    axvline(i, ls=":", color="r")
    axvline(-i, ls=":", color="b")
end
```

## Program 3


```julia
fun1(x) = float(x==0)
fun2(x) = float(abs(x) <= 3)
fun3(x) = max(0.0, 1-abs(x)/3)

function plotfun(plt, h, xmax, f)
    x = -xmax:h:xmax
    xx = -xmax-h/20:h/40:xmax+h/20
    
    v = f.(x)
    
    subplot(3,1,plt)
    plot(x, v, "k.")
    nxx = length(xx)
    nx = length(x)
    p = zeros(nxx)
    for i = 1:nx
        p .= p .+ v[i] .* sinc.((xx .- x[i])./h)
    end
    
    plot(xx, p, "k")
end

```


```julia
plotfun(1, 1.0, 10.0, fun1); grid(ls=":")
plotfun(2, 0.5, 10.0, fun2); grid(ls=":")
plotfun(3, 1.0, 10.0, fun3); grid(ls=":")



```

# Exercises

## Exercise 2.1

Let $\mathcal{F}$ denote the Fourier transform operator defined by (2.1), so that $u,v \in L^2(\mathbb{R})$ have transforms $\hat{u}=\mathcal{F}\{u\}$, $\hat{v}=\mathcal{F}\{v\}$. Verify the following properties. 

### (a) Linearity
$$
\mathcal{F}\{u+v\} = \int_{-\infty}^\infty e^{-ikx}\left[u(x) + v(x)\right]\:dx = \int_{-\infty}^\infty\left[e^{-ikx}u(x) + e^{-ikx}v(x)\right]\:dx = \int_{-\infty}^\infty e^{-ikx}u(x) \:dx + \int_{-\infty}^\infty e^{-ikx}v(x) \:dx = \mathcal{F}\{u\} + \mathcal{F}\{v\} = \hat{u}(k) + \hat{v}{k}
$$    

$$
\mathcal{F}\{cu\} = \int_{-\infty}^\infty e^{-ikx}\left[cu(x)\right]\:dx = c \int_{-\infty}^\infty e^{-ikx}u(x)\:dx =  c\mathcal{F}\{u\} = c\hat{u}(k) 
$$


### (b) Translation
Substitute $y = x + x_0$, so that $dy= dx$ and $x = y-x_0$
$$
\mathcal{F}\{u(x+x_0)\} = \int_{-\infty}^\infty e^{-ikx}u(x+x_0)\:dx = \int_{-\infty}^\infty e^{-ik(y - x_0)}u(y)\:dy = \int_{-\infty}^\infty e^{i k x_0}e^{-iky}u(y)\:dy = e^{i k x_0} \mathcal{F}\{u\} =  e^{i k x_0} \hat{u}(k)
$$    

### (c) Modulation

\begin{align}
\mathcal{F}\{e^{ik_0x}u(x)\} = \int_{-\infty}^\infty e^{-ikx}e^{ik_0x}u(x)\:dx &=  \int_{-\infty}^\infty e^{-ikx + ik_0x}u(x)\:dx = \\ =  \int_{-\infty}^\infty e^{-i(k-k_0)x}u(x)\:dx  &=   \hat{u}(k-k_0)
\end{align}

### (d) Dilation

Substitute $y = cx$ so that $dy= c dx$ and $x = y/c$

\begin{align}
\mathcal{F}\{u(cx)\} = \int_{-\infty}^\infty e^{-ikx}u(cx)\:dx =  \int_{-\infty}^\infty e^{-iky/c}u(y)\:\frac{dy}{c} =    \frac{1}{c}\hat{u}\left(\frac{k}{c}\right)
\end{align}

### (e) Conjugation

Substitute $y = cx$ so that $dy= c dx$ and $x = y/c$

\begin{align}
\mathcal{F}\{\overline{u(cx)}\} = \int_{-\infty}^\infty e^{-ikx}\overline{u(x)}\:dx &=  \int_{-\infty}^\infty \overline{e^{+ikx}u(x)}\:dx = \\
\overline{\int_{-\infty}^\infty e^{+ikx}u(x)\:dx} &= \overline{\hat{u}(-k)}
\end{align}

### Differentiation

$$
d( u e^{-ikx}) = u(x)(-ik) e^{-ikx}dx + u_x e^{-ikx}dx
$$

Therefore, 
$$
u_x e^{-ikx} dx = d(ue^{-ikx}) + ik u(x) e^{-ikx}dx
$$

Substituting into the Fourier transform:

$$
\mathcal{F}\{u_x\} = \int_{-\infty}^\infty e^{-ikx}u_x\:dx = 
\int_{-\infty}^\infty ik u(x) e^{-ikx}\:dx + \int_{-\infty}^\infty \:d\left(e^{-ikx}u\right)
$$

But for the Fourier transform to converge, 

$$
\lim_{x\longrightarrow\pm\infty} u(x) = 0
$$

and we have
$$
\mathcal{F}\{u_x\} = \int_{-\infty}^\infty ik u(x) e^{-ikx}\:dx = ik\hat{u}(k)
$$



### (g) Inversion

$$
\mathcal{F}^{-1}\{\hat{u}\}(x)= \frac{1}{2\pi}\int_{\infty}^{\infty} \hat{u}(k) e^{ikx}\:dk
$$

$$
\mathcal{F}^{-1}\{u\}(x)= \frac{1}{2\pi}\int_{\infty}^{\infty} u(k) e^{ikx}\:dk
$$
Changing the names of the variables, $x\longrightarrow k$ and $k\longrightarrow x$, 
$$
\mathcal{F}^{-1}\{u\}(k)= \frac{1}{2\pi}\int_{\infty}^{\infty} u(x) e^{ikx}\:dx = \frac{1}{2\pi} \hat{u}(-k)
$$





## Exercise 2.2

Let $u \in L^2(\mathbb{R})$ hava Fourier transform $\hat{u}$. Verify the following identities. *( a hermitian (skew-hermitian) function $f(x)$ is one with $f(-x) = \overline{f(x)}$ ($f(-x) = - \overline{f(x)}$).)*


### (a) $u(x)$ is even (odd) $\Longleftrightarrow$ $\hat{u}(k)$ is even (odd)

$u(x)$ is even

$$
\hat{u}(-k) = \int_{-\infty}^\infty e^{ikx} u(x)\:dx = 
\int_{-\infty}^\infty e^{ikx} u(-x)\:dx = \\
-\int_{y=+\infty}^{y=-\infty} e^{-iky} u(y)\:dy = 
\int_{-\infty}^\infty e^{-ikx} u(x)\:dx = \hat{u}(k)
$$

$\hat{u}(k)$ is even

$$
u(-x) = \frac{1}{2\pi} \int_{-\infty}^\infty e^{-ikx} \hat{u}(k)\:dk = 
\frac{1}{2\pi} \int_{-\infty}^\infty e^{-ikx} \hat{u}(-k)\:dk = \\
\frac{-1}{2\pi} \int_{l=+\infty}^{-\infty} e^{ilx} \hat{u}(l)\:dl = 
\frac{1}{2\pi} \int_{-\infty}^\infty e^{ikx} \hat{u}(k)\:dk = u(x)
$$

$u(x)$ is odd

$$
\hat{u}(-k) = \int_{-\infty}^\infty e^{ikx} u(x)\:dx = 
-\int_{-\infty}^\infty e^{ikx} u(-x)\:dx = \\
+\int_{y=+\infty}^{y=-\infty} e^{-iky} u(y)\:dy = 
-\int_{-\infty}^\infty e^{-ikx} u(x)\:dx = -\hat{u}(k)
$$

$\hat{u}(k)$ is odd

$$
u(-x) = \frac{1}{2\pi} \int_{-\infty}^\infty e^{-ikx} \hat{u}(k)\:dk = 
-\frac{1}{2\pi} \int_{-\infty}^\infty e^{-ikx} \hat{u}(-k)\:dk = \\
+\frac{-1}{2\pi} \int_{l=+\infty}^{-\infty} e^{ilx} \hat{u}(l)\:dl = 
-\frac{1}{2\pi} \int_{-\infty}^\infty e^{ikx} \hat{u}(k)\:dk = -u(x)
$$

### (b) $u(x)$ is real (imaginary) $\Longleftrightarrow$ $\hat{u}(k)$ is hermitian (skew-hermitian)

$u(x)$ is real

$$
\hat{u}(-k) = \int_{-\infty}^\infty e^{ikx} u(x)\:dx = 
\int_{-\infty}^\infty \overline{e^{-ikx}} \overline{u(x)}\:dx = 
\overline{\int_{-\infty}^\infty e^{-ikx} u(x)\:dx} = \overline{\hat{u}(k)}
$$

$\hat{u}(k)$ is hermitian

$$
u(x) = \frac{1}{2\pi}\int_{-\infty}^\infty \hat{u}(k) e^{ikx}\:dk = 
\frac{1}{2\pi}\int_{-\infty}^\infty \overline{\hat{u}(-k)} \overline{e^{-ikx}} \:dk = \\
\overline{ \frac{1}{2\pi}\int_{k=-\infty}^{k=\infty} \hat{u}(-k) e^{-ikx} \:dk } = - \overline{ \frac{1}{2\pi}\int_{l=+\infty}^{l=-\infty} \hat{u}(l) e^{ilx} \:dl} = \\
\overline{ \frac{1}{2\pi}\int_{-\infty}^{\infty} \hat{u}(k) e^{ikx} \:dk} = \overline{u}(x)
$$

If $u(x) = \overline{u(x)}$, $u(x)$ is real.

$u(x)$ is imaginary

$$
\hat{u}(-k) = \int_{-\infty}^\infty e^{ikx} u(x)\:dx = 
\int_{-\infty}^\infty \overline{e^{-ikx}} (-\overline{u(x)})\:dx = 
-\overline{\int_{-\infty}^\infty e^{-ikx} u(x)\:dx} = -\overline{\hat{u}(k)}
$$

$\hat{u}(k)$ is skew-hermitian

$$
u(x) = \frac{1}{2\pi}\int_{-\infty}^\infty \hat{u}(k) e^{ikx}\:dk = 
\frac{1}{2\pi}\int_{-\infty}^\infty \left[-\overline{\hat{u}(-k)} \right]\overline{e^{-ikx}} \:dk = \\
- \overline{ \frac{1}{2\pi}\int_{k=-\infty}^{k=\infty} \hat{u}(-k) e^{-ikx} \:dk } = + \overline{ \frac{1}{2\pi}\int_{l=+\infty}^{l=-\infty} \hat{u}(l) e^{ilx} \:dl} = \\
-\overline{ \frac{1}{2\pi}\int_{-\infty}^{\infty} \hat{u}(k) e^{ikx} \:dk} = -\overline{u}(x)
$$


If $u(x) = -\overline{u(x)}$, $u(x)$ is imaginary.

### (c) $u(x)$ is real and even $\Longleftrightarrow$ $\hat{u}(k)$ is real and even

 * $u(x)$ is real and even $\Longrightarrow$ $\hat{u}(k)$.<br>
   From (a), $\hat{u}(k)$ is even. From (b), $\hat{u}(k)$ is hermitian. An even hermitian funcion is real.

 * $\hat{u}(k)$ is real and even $\Longrightarrow$ $u(x)$.<br>
   From (a), $u(x)$ is even. From (b) $u(x)$ is real.


### (d) $u(x)$ is real and odd $\Longleftrightarrow$ $\hat{u}{k}$ is imaginary and odd
 
 * $u(x)$ is real and odd $\Longrightarrow$ $\hat{u}(k)$.<br>
   From (a), $\hat{u}(k)$ is odd. 
   From (b), $\hat{u}(k)$ is skew-hermitian and and odd and skew-hermitian function is imaginary.
 
 * $\hat{u}(k)$ is imaginary and odd $\Longrightarrow$ $u(x)$.<br>
   From (a), $u(x)$ is odd. Since $\hat{u}(k)$ is odd and imaginary, it is is skew-hermitian and therefore, $u(x)$ is imaginary

  


### (e) $u(x)$ is imaginary and even $\Longleftrightarrow$ $\hat{u}(k)$ is imaginary and even

 * $u(x)$ is imaginary and even $\Longrightarrow$ $\hat{u}(k)$.<br>
   From (a), $\hat{u}(k)$ is even. From (b), $\hat{u}(k)$ is skew-hermitian. An even skew-hermitian even funcion can only be imaginary

 * $\hat{u}(k)$ is imaginary and even $\Longrightarrow$ $u(x)$.<br>
   From (a), $u(x)$ is even. From (b) $u(x)$ is imaginary.


### (f) $u(x)$ is imaginary and odd $\Longleftrightarrow$ $\hat{u}(k)$ is real and odd

 * $u(x)$ is imaginary and odd $\Longrightarrow$ $\hat{u}(k)$.<br>
   From (a), $\hat{u}(k)$ is odd. From (b), $\hat{u}(k)$ is skew-hermitian. An odd skew-hermitian funcion can only be real

 * $\hat{u}(k)$ is real and odd $\Longrightarrow$ $u(x)$.<br>
   From (a), $u(x)$ is odd. Buta an odd and real function is skew-hermitian and therefore $u(x)$ is imaginary.


## Exercise 2.3
Execute the command plot(sin.(1:3000),".") in Julia . What do you see? What does this have to do with aliasing? Give a quantitative answer, explaining exactly what frequency is being aliased by your eye and brain to what other frequency. Then, for fun, replace 3000 by 1000 to get a gure somewhat harder to explain. (This problem comes from Str91).


```julia
plot(sin.(1:3000), ".")
```


```julia
plot(sin.(1:1000), ".")
```

## Exercise 2.4

Derive 2.12 and 2.13.

 ### Derive 2.12
 
 $$
 S_h'(x_j) = \left\{
 \begin{matrix}
 0 & j=0\\
 \frac{(-1)^j}{jh} &  j\ne 0\\
 \end{matrix}
 \right.
 $$
 
 Quotient rule:
 
 $$
 \frac{d}{dx}\left(\frac{f}{g}\right) = \frac{g\cdot df/dx - f \cdot dg/dx}{g^2}
 $$
 where 
 $$
 f(x) = \sin\left(\frac{\pi x}{h}\right) \qquad g(x) = \frac{\pi x}{h}
 $$
 
 Substituting $y = \pi x/h$,  
  $$
  S'_h(x) = \frac{d S_h}{dy}\cdot \frac{dy}{dx} = \frac{\pi}{h}\frac{d}{dy}\left[\frac{sin(y)}{y}\right] = 
 \frac{\pi}{h} \frac{y\cos y - \sin y}{y^2}
  $$
  
  But $x_j = \pi j h$ and therefore $y_j = \pi j$. For $x_j \ne 0$:
  $$
  S'_h(x_j) = \frac{\pi}{h} \frac{\pi j\cos \pi j - \sin \pi j}{\pi^2 j^2} = \frac{(-1)^j}{j h}
  $$
  
  For $x_j = 0$ we must use L'Hôpital's rule we arrive at 
  $$
  S'_h(0) = 0
  $$
  



```julia

```

7a1c37642111070a9037c7630a42ce00ae5fc499
ipynb
Jupyter Notebook
chapter02.ipynb
pjabardo/spectral-methods-julia
5a4224529614c8e10e5d3964add172dbe31b9c92
MIT
chapter02.ipynb
pjabardo/spectral-methods-julia
5a4224529614c8e10e5d3964add172dbe31b9c92
MIT
chapter02.ipynb
pjabardo/spectral-methods-julia
5a4224529614c8e10e5d3964add172dbe31b9c92
MIT
Qwen/Qwen-72B
1. YES
2. YES