Commit 461a3205 authored by Jochen Schulz's avatar Jochen Schulz
Browse files

added exercises 24

parent 7bc10581
%% Cell type:markdown id: tags:
# Exercise 24
## problem 1
The module `Data.Array.Repa.FFTW` provides functions for Fast Fourier Transforms (FFT) for Repa arrays of up to three dimensions. Use the 1-d version to implement a simple low-pass filter that works as follows:
- First, an FFT is applied to the input signal.
- The coefficients corresponding to frequencies over some pre-determined cutoff are set to 0, the other ones are left untouched.
- Then an inverse FFT is performed.
The map from index `k` of the resulting array to the corresponding frequency for an FFT of length `n` is
```haskell
frq n k
| 2*k < n = k
| otherwise = k - n
```
Use the low-pass filter to denoise a signal created by adding uniformly distributed noise between $-0.03$ and $0.03$ to the function $x \mapsto exp(-x^2)$ for $x$ sampled on 200 points between $-2$ and $2$ and plot the results.
Note:
- The function, its noisy version and the filtered version should be real, but the FFT functions require and return `Complex Double` arrays.
- The FFT functions work with arrays in representation `F` (foreign). To convert from and to `D` or `U`, `copyS` can be used.
- A simple way to generate a list of `n` random numbers without using `IO` is
```haskell
take n . randomRs (-0.03, 0.03) $ mkStdGen 0
```
%% Cell type:markdown id: tags:
## problem 2
Implement a parallel Jacobi solver for linear systems using Repa arrays. Since Repa's `mmultP` (from `Data.Array.Repa.Algorithms.Matrix`) only works on `DIM2` arrays, the right hand side should be a matrix as well, i.e. you should effectively solve
$$A X = Y$$
for $X$, where $A$, $X$ and $Y$ are matrices. "Conventional" linear systems can then be solved by taking $X$ and $Y$ as matrices with only a single column.
In order to actually use the parallelisation, this exercise should not be done in the notebook interface. You should also test your program on the 1d Poisson example from lecture 21 and examine its behaviour in ThreadScope. HMatrix matrices can be converted to Repa `DIM2` arrays using `matrixToRepa` from `Data.Packed.Repa`.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment