Skip to content
Snippets Groups Projects
rapport.md 13.7 KiB
Newer Older
---
title: "Rapport Math"
author: [Troller Fabian, Rivier Nicolas]
date: "2022-04-25"
keywords: [Math, Intégrales]
lang: "fr"
titlepage: true,
titlepage-rule-height: 0
titlepage-background: "background5.pdf"
...
# Introduction Génerale
Pour ce TP, nous avons reçu comme objectif de calculer une convolution de signaux numériquement et à la main d'en calculer l'erreur entre les deux, Ainsi que réussir à enlever le bruit d'une image 

# Introduction théorique

## Intégration numérique
On définit une fonction **f(x)**,  
\begin{equation}
f(x)=-\frac{2x-1}{\exp(x^2-x+2)},
\end{equation}

Ou l'on veut calculer son intégration entre un intervalle de **[a,b]** a un certain **N** d'approximation.

\begin{equation}
I(a,b,N,f(x))=\sum_{i=0}^{N-1} f(a+i\delta x)\delta x,\quad \delta x=\frac{b-a}{N}.
\end{equation}

Afin de pouvoir faire une comparaison d'erreur entre la solution numerique et analytique nous allons prendre la meme intervalle **[a,b]** $=$ **[1,5]** 

## Intégration analytique
Afin de valider notre intégration analytique et étudié l'erreur en fonction du **N** nombre d'intervalle.  
Nous allons calculer la solution analytique de notre fonction.

\begin{equation}
f(x)=-\frac{2x-1}{\exp(x^2-x+2)},
\end{equation}

\begin{equation}
I=\int_a^b f(x)*dx = -\frac{2x-1}{\exp(x^2-x+2)}\mathrm{d}x.
\end{equation}

pour un intervalle [1,5].

\begin{equation}
\int_1^5 -\frac{2x-1}{e^{(-x^2+x-2)}}
\end{equation}

\begin{equation}
\int_1^5 -(2x-1) * \frac{1}{e^{(-x^2+x-2)}}
\end{equation}

\begin{equation}
\int_1^5 (-2x+1) * e^{(-x^2+x-2)^{-1}} 
\end{equation}

\begin{equation}
\int_1^5 (-2x+1) * e^{(-x^2+x-2)}
\end{equation}

Déterminer la transformée en u

\begin{equation}
\int_1^5 du * e^u
\end{equation}

\begin{equation}
u = f(x) = -x^2+x-2
\end{equation}
\begin{equation}
du = F{(x)}'= -2x+1
\end{equation}

\begin{equation}
\int_1^5 e^u * du = \mid_1^5 e^{(-x^2+x-2)}
\end{equation}

selon 
\begin{equation}
\mid_a^b f(x) = f(b) - f(a)
\end{equation}

on obtient

\begin{equation}
\mid_1^5 e^{(-x^2+x-2)} = e^{-5^2+5-2} - e^{-1^2+1-2}
\end{equation}

\begin{equation}
e^{-25+5-2} - e^{-1+1-2} = e^{-22} - e^{-2}
\end{equation}

finalement 

\begin{equation}
I = \frac {1}{e^{22}} - \frac {1}{e^{2}} = -0,135335283
\end{equation}

## Validation
Afin de comparer nos résultats nous allons varier **N** de 5,10,50,100,500,1000 pour une même intervalle a b $=$ **[1,5]** et calculer l'erreur de notre résultat numérique par rapport à la solution analytique.

\begin{equation}
 E(N)=\left|\frac{I-I(a,b,N,f(x))}{I}\right|
\end{equation}

![Graphique E(N) LOG](Graphic_Error_n.pdf "Graphique E(N) Echelle LOG")
![Graphique E(N)](Graphic_Error_n_2.pdf "Graphique E(N)")

Sur ces deux graphiques, on peut constater que l'erreur diminue plus l'itération est grande, sur le premier graphique, l'échelle est logarithmique. Pour le deuxième graphique, l'échelle est standard et permet de voir également cette diminution de l'erreur sous une autre forme.


# Convolutions et filtrage
Afin de se familiariser avec les convolutions, nous allons filtrer des signaux à 1 dimension.

Pour cela nous définition un signal composé de deux signaux avec chacun une fréquence différents w1 et w2.

\begin{equation}
s(x)=\sin(2\pi\omega_1 x)+\sin(2\pi\omega_2 x).
\end{equation}

et un certain filtre

\begin{equation}
f(x)=\left\{\begin{array}{ll}
                \frac{1}{\psi},&\mbox{ si }x\in[-\psi/2,\psi/2]\\
                0,&\mbox{ sinon.}
               \end{array}\right.
\end{equation}

Le but est de déterminer l'intervalle du filtre
\begin{equation}
[-\psi/2,\psi/2]
\end{equation} 
afin que la convolution de ces deux fonctions (f*s)(x) annule une des deux composantes sinusoïdales du signal.

## Solution analytique
### Délimitation
La convolution de deux fonctions est définie de la sorte:
\begin{equation}
\int_{-\infty }^{\infty} S(x - t)*f(x)dt
\end{equation}

On va développer dans les intervalles que nous recherchons.

\begin{equation}
\int_{-\infty }^{-\psi/2} S(x - t)*f(x)dt + \int_{-\psi/2 }^{\psi/2} S(x - t)*f(x)dt + \int_{\psi/2 }^{\infty} S(x - t)*f(x)dt
\end{equation}

En observant f(x) on constate que dans l'intervalle [-psi/2, psi/2] f(x) vaut 1/psi sinon 0 :

\begin{equation}
f(x)=\left\{\begin{array}{ll}
                \frac{1}{\psi},&\mbox{ si }x\in[-\psi/2,\psi/2]\\
                0,&\mbox{ sinon.}
               \end{array}\right.
\end{equation}

donc notre domaine de convolution recherché s’étant a  
\begin{equation}
\int_{-\psi/2 }^{\psi/2} S(x - t)*f(x)dt = \int_{-\psi/2 }^{\psi/2} (\sin(2\pi\omega_1 (x - t))+\sin(2\pi\omega_2 (x - t))) * \frac{1}{\psi} dt
\end{equation}

### Transformée primaire

On cherche à déterminer la dérivée primaire du sinus et de sa composante par la factorisation de primitive en fonction de t :

\begin{equation}
f(g(t))' = f'(g(t))*g'(t)
\end{equation}

pour :
\begin{equation}
\int \sin(2\pi\omega(x-t)dt
\end{equation}

\begin{equation}
f(t) = sin(x) 	\quad étant \quad f'(t) = -cos(x)
\end{equation}
\begin{equation}
g(t) = 2\pi\omega(x-t) 	\quad étant \quad g'(t) = 2\pi\omega*0 - 2\pi\omega*1 = - 2\pi\omega
\end{equation}

Ce qui nous donne:
\begin{equation}
\int \sin(2\pi\omega(x-t)dt \neq -\cos(2\pi\omega(x-t) * -2\pi\omega
\end{equation}

Donc pour y remédier on multiplie par 1 l’intégrale:
\begin{equation}
\frac{-2\pi\omega}{-2\pi\omega} = 1
\end{equation}
\begin{equation}
\frac{-2\pi\omega}{-2\pi\omega} * \int \sin(2\pi\omega(x-t)dt = \frac{-2\pi\omega}{-2\pi\omega} * -\cos(2\pi\omega(x-t) * -2\pi\omega
\end{equation}

Ce qui nous donne finalement comme résultat:
\begin{equation}
\int \sin(2\pi\omega(x-t)dt = \frac{-\cos(2\pi\omega(x-t)}{-2\pi\omega} = \frac{\cos(2\pi\omega(x-t)}{2\pi\omega}
\end{equation}

#### Transformée primaire de l’intégral au complet
\begin{equation}
\int_{-\psi/2 }^{\psi/2} (\sin(2\pi\omega_1 (x - t))+\sin(2\pi\omega_2 (x - t))) * \frac{1}{\psi} dt
\end{equation}

\begin{equation}
\mid_{-\psi/2 }^{\psi/2} (\frac{\cos(2\pi\omega_1(x-t))}{2\pi\omega_1} + \frac{\cos(2\pi\omega_2(x-t))}{2\pi\omega_2}) * \frac{1}{\psi}
\end{equation}

Distribution des constante et factoriser au mème dénominateur commun:

\begin{equation}
\mid_{-\psi/2 }^{\psi/2} \frac{\cos(2\pi\omega_1(x-t))}{2\pi\omega_1\psi} + \frac{\cos(2\pi\omega_2(x-t))}{2\pi\omega_2\psi}
\end{equation}

\begin{equation}
\mid_{-\psi/2 }^{\psi/2} \frac{\cos(2\pi\omega_1(x-t))}{2\pi\omega_1\psi}*\frac{\omega_2}{\omega_2} + \frac{\cos(2\pi\omega_2(x-t))}{2\pi\omega_2\psi}*\frac{\omega_1}{\omega_1}
\end{equation}

\begin{equation}
\mid_{-\psi/2 }^{\psi/2} \frac{\cos(2\pi\omega_1(x-t))\omega_2 + \cos(2\pi\omega_2(x-t))\omega_1}{2\pi\omega_1\omega_2\psi}
\end{equation}

### Distribution de la constante de temps

Selon la règle:
\begin{equation}
\mid_{\pi}^{-\pi} f(x-t) = f(x-\pi) - f(x+\pi)
\end{equation}

Notre convolution devient:

\begin{equation}
\mid_{-\psi/2 }^{\psi/2} \frac{\cos(2\pi\omega_1(x-t))\omega_2 + \cos(2\pi\omega_2(x-t))\omega_1}{2\pi\omega_1\omega_2\psi} 
\end{equation}

\begin{equation}
= \frac{\cos(2\pi\omega_1(x-\psi/2))\omega_2 + \cos(2\pi\omega_2(x-\psi/2))\omega_1}{2\pi\omega_1\omega_2\psi} - \frac{\cos(2\pi\omega_1(x+\psi/2))\omega_2 + \cos(2\pi\omega_2(x + \psi/2))\omega_1}{2\pi\omega_1\omega_2\psi}
\end{equation}

\begin{equation}
= \frac{\cos(2\pi\omega_1(x-\psi/2))\omega_2 + \cos(2\pi\omega_2(x-\psi/2))\omega_1 - \cos(2\pi\omega_1(x+\psi/2))\omega_2 - \cos(2\pi\omega_2(x + \psi/2))\omega_1}{2\pi\omega_1\omega_2\psi}
\end{equation}

### Regroupement des variables communes
Pour simplifier, je regroupe la formule en différentes parties :

\begin{equation}
\frac{A + B}{C}
\end{equation}
\begin{equation}
A = \cos(2\pi\omega_1(x-\psi/2))\omega_2 - \cos(2\pi\omega_1(x+\psi/2))\omega_2
\end{equation}

\begin{equation}
B = \cos(2\pi\omega_2(x-\psi/2))\omega_1 - \cos(2\pi\omega_2(x + \psi/2))\omega_1
\end{equation}

\begin{equation}
C = 2\pi\omega_1\omega_2\psi
\end{equation}

### Règles de transformation sinusoïdal

Selon une des régles de transformation de somme en produit du sinus:

\begin{equation}
cos(p) - cos(q) = - 2 sin(\frac{p+q}{2}) sin(\frac{p-q}{2})
\end{equation}

Nous allons appliquer cette régle sur A et B

\begin{equation}
A = \cos(2\pi\omega_1(x-\psi/2))\omega_2 - \cos(2\pi\omega_1(x+\psi/2))*\omega_2
\end{equation}

\begin{equation}
(\cos(2\pi\omega_1(x-\psi/2)) - \cos(2\pi\omega_1(x+\psi/2)))*\omega_2
\end{equation}

\begin{equation}
- 2 sin(\frac{2\pi\omega_1(x-\psi/2) + 2\pi\omega_1(x+\psi/2))}{2}) sin(\frac{2\pi\omega_1(x-\psi/2) - 2\pi\omega_1(x+\psi/2)}{2})*\omega_2
\end{equation}

\begin{equation}
- 2 sin(\frac{2\pi\omega_1((x-\psi/2)+(x+\psi/2))}{2}) sin(\frac{2\pi\omega_1((x-\psi/2) - (x+\psi/2))}{2})*\omega_2
\end{equation}

\begin{equation}
- 2 sin(\frac{2\pi\omega_1(2x)}{2}) sin(\frac{2\pi\omega_1(-2*\psi/2) )}{2})*\omega_2
\end{equation}

\begin{equation}
- 2 sin(\pi\omega_1(2x)) sin(\pi\omega_1(-\psi)))*\omega_2
\end{equation}

\begin{equation}
- 2 sin(2\pi\omega_1x) sin(-\pi\omega_1\psi)*\omega_2
\end{equation}

Puis sur B de la même façon.

\begin{equation}
B = \cos(2\pi\omega_2(x-\psi/2))\omega_1 - \cos(2\pi\omega_2(x + \psi/2))\omega_1
\end{equation}

\begin{equation}
(\cos(2\pi\omega_2(x-\psi/2)) - \cos(2\pi\omega_2(x + \psi/2)))*\omega_1
\end{equation}

\begin{equation}
...
\end{equation}

\begin{equation}
- 2 sin(2\pi\omega_2x) sin(-\pi\omega_2\psi)*\omega_1
\end{equation}


Og's avatar
Og committed
### Finalement en rassemblant A,B et C nous obtenons

\begin{equation}
\frac{- 2 sin(2\pi\omega_1x) sin(-\pi\omega_1\psi)*\omega_2 - 2 sin(2\pi\omega_2x) sin(-\pi\omega_2\psi)*\omega_1}{2\pi\omega_1\omega_2\psi}
\end{equation}

\begin{equation}
\frac{- sin(2\pi\omega_1x) sin(-\pi\omega_1\psi)*\omega_2 - sin(2\pi\omega_2x) sin(-\pi\omega_2\psi)*\omega_1}{\pi\omega_1\omega_2\psi}
\end{equation}

\begin{equation}
\frac{sin(2\pi\omega_1x) sin(\pi\omega_1\psi)*\omega_2 + sin(2\pi\omega_2x) sin(\pi\omega_2\psi)*\omega_1}{\pi\omega_1\omega_2\psi}
\end{equation}

Og's avatar
Og committed
\begin{equation}
Og's avatar
Og committed
\frac{sin(2\pi\omega_1x) sin(\pi\omega_1\psi)}{\pi\omega_1\psi} + \frac {sin(2\pi\omega_2x) sin(\pi\omega_2\psi)}{\pi\omega_2\psi}
Og's avatar
Og committed
\end{equation}



On peut alors observer que les deux composent du signal (les deux signaux sinusoïdaux) dépende d'un sinus(w * x) et sinus(w * phi).
On notera alors que si phi équivaut à la période d'un des deux composant 1/w. phi annule la composent visé.

Démonstration:
\begin{equation}
\psi = \frac{1}{\omega_1}
\end{equation}

Og's avatar
Og committed

Og's avatar
Og committed
\frac{sin(2\pi\omega_1x) sin(\pi\omega_1\frac{1}{\omega_1})}{\pi\omega_1\frac{1}{\omega_1}} + \frac {sin(2\pi\omega_2x) sin(\pi\omega_2\frac{1}{\omega_1})}{\pi\omega_2\frac{1}{\omega_1}}
\end{equation}

\begin{equation}
Og's avatar
Og committed
\frac{sin(2\pi\omega_1x) sin(\pi\frac{\omega_1}{\omega_1})}{\pi\frac{\omega_1}{\omega_1}} + \frac {sin(2\pi\omega_2x) sin(\pi\frac{\omega_2}{\omega_1})}{\pi\frac{\omega_2}{\omega_1}}
Og's avatar
Og committed
\begin{equation}
\frac{sin(2\pi\omega_1x) sin(\pi)}{\pi} + \frac {sin(2\pi\omega_2x) sin(\pi\frac{\omega_2}{\omega_1})}{\pi\frac{\omega_2}{\omega_1}}
\end{equation}
Og's avatar
Og committed

Vu que sinus(PI) équivaut a 0. (calcule en radiant) cela revient a faire:

\begin{equation}
Og's avatar
Og committed
0 + \frac {sin(2\pi\omega_2x) sin(\pi\frac{\omega_2}{\omega_1})}{\pi\frac{\omega_2}{\omega_1}}
\end{equation}

On a belle est bien annulé la premier composant (signal sinusoïdal) composent le signal de base S(x)

Og's avatar
Og committed
### Convolution discrète
poulpe's avatar
poulpe committed

Og's avatar
Og committed

## Convolution en 2 dimensions

### Partie 1 
Calculer a la main le produite de convolution suivant, en utilisant la méthode de gestion de bord par une valeur de zero:
poulpe's avatar
poulpe committed
$$
\underline{\underline{A}}=\begin{pmatrix}
0 & 1 & 0\\
-1 & 0 & -1\\
0 & 1 & 0
\end{pmatrix}, \underline{\underline{B}}=\begin{pmatrix}
1 & 2 & 3\\
4 & 5 & 6\\
7 & 8 & 9
\end{pmatrix}
$$

$$\underline{\underline{A}} \times \underline{\underline{B}} = \begin{pmatrix}
1 & 1 & 4\\
3 & 0 & 7\\
-4 & -11 & 2
\end{pmatrix}$$

### Partie 2
Appliquer différents filtres sur l'image suivante "part2.pgm":  

![part2.pgm](img/part2.png)

#### filtre F0
\begin{equation*}
\underline{\underline{F_0}} = \begin{pmatrix}
0 & 0 & 0\\
0 & 1 & 0\\
0 & 0 & 0
\end{pmatrix}
\end{equation*}

Résultat de la convolution obtenu:

![part2_identitaire.pgm](img/part2_identitaire.png)

On peux déterminer que le filtre F0 prend pas en compte les pixels dans les alentours du puxels focus (central) ce qui revient a faire une copie de la matrix sans changement. On as donc un filtre identitaire.

#### filtre F1
\begin{equation*}
\underline{\underline{F_1}} = \frac{1}{25}\begin{pmatrix}
1 & 1 & 1 & 1 & 1\\
1 & 1 & 1 & 1 & 1\\
1 & 1 & 1 & 1 & 1\\
1 & 1 & 1 & 1 & 1\\
1 & 1 & 1 & 1 & 1
\end{pmatrix}
\end{equation*}

Résultat de la convolution obtenu:

![part2_blur25.pgm](img/part2_blur25.png)

On détermine que le filtre F1 fait la moyenne des différents pixels au alentour du focus, donc on a donc une filtre moyenneur / blur d'une matrix de 5x5. On aperçois donc bien sur l'image traitée un floutage générale.

#### filtre F2
\begin{equation*}
\underline{\underline{F_2}} = \frac{1}{256}\begin{pmatrix}
1 & 4 & 6 & 4 & 1\\
4 & 16 & 24 & 16 & 4\\
6 & 24 & 36 & 24 & 6\\
4 & 16 & 24 & 16 & 4\\
1 & 4 & 6 & 4 & 1
\end{pmatrix}
\end{equation*}
 
Résultat de la convolution obtenu:

![part2_blurCent.pgm](img/part2_blurCent.png)

On détermine que le filtre F2 fait la moyenne des différents pixels au alentour du focus en donnant plus de point au pixels central et ceux qui lui sont le plus proches. On aperçois donc bien sur l'image traitée un floutage générale en donnant plus d'importance au détails.

#### filtre F3
\begin{equation*}
\underline{\underline{F_3}} = \begin{pmatrix}
0 & -1 & 0\\
-1 & 5 & -1\\
0 & -1 & 0
\end{pmatrix}
\end{equation*}

Résultat de la convolution obtenu:

![part2_contourF3.pgm](img/part2_contourF3.png)

#### filtre F4
\begin{equation*}
\underline{\underline{F_4}} = \begin{pmatrix}
0 & -1 & 0\\
-1 & 4 & -1\\
0 & -1 & 0
\end{pmatrix}
\end{equation*}

Résultat de la convolution obtenu:

![part2_contourF4.pgm](img/part2_contourF4.png)