aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWojtek Kosior <kwojtus@protonmail.com>2019-06-02 21:49:12 +0200
committerWojtek Kosior <kwojtus@protonmail.com>2019-06-02 21:49:12 +0200
commit81b832d9576fdb1b26281e2b6aa695d1742e5c13 (patch)
treed2ffab557f3be9c780c592c95f40f0e906c6774f
parenta873a4c8702f8133d104814e855cc6d3738f331f (diff)
downloadfortran-assignment2-81b832d9576fdb1b26281e2b6aa695d1742e5c13.tar.gz
fortran-assignment2-81b832d9576fdb1b26281e2b6aa695d1742e5c13.zip
add non fortran-related part of the README
-rw-r--r--README.md26
1 files changed, 21 insertions, 5 deletions
diff --git a/README.md b/README.md
index 6e8932b..b5703c1 100644
--- a/README.md
+++ b/README.md
@@ -37,19 +37,19 @@ This directory contains relevant plots of signals and frequency spectrums as req
##Building##
As a prerequisite, fftw3, make and a fortran compiler, either gfortran or ifort, are required (didn't want to support proprietary compiler :c but had to). It is assumed, that include files for fftw3 are installed under `/usr/include`.
-Run:
+Run
$ make
to build the program executable `fourier`.
-The makefile checks which one of the 2 compilers is present and uses it. Alternatively, one can specify fortran compiler explicitly, e.g.:
+The makefile checks which one of the 2 compilers is present and uses it. Alternatively, one can specify fortran compiler explicitly, e.g.
$ make FC=gfortran
-or:
+or
$ make FC=ifort
##Running##
-The executable is `fourier`. It's mandatory first argument is name of the function to work with - 'f1' or 'f2'. If there're no other arguments - program prints datapoints for plotting the original function. If second argument is 'dft' - program prints datapoints of function's frequency spectrum as obtained from discrete fourier transform. If second argument is 'filtered' - program prints datapoints of filtered function (with frequency components of low values removed).
+The executable is `fourier`. It's mandatory first argument is name of the function to work with - '_f1_' or '_f2_'. If there're no other arguments - program prints datapoints for plotting the original function. If second argument is '_dft_' - program prints datapoints of function's frequency spectrum as obtained from discrete fourier transform. If second argument is '_filtered_' - program prints datapoints of filtered function (with frequency components of low values removed).
$ ./fourier f2 filtered
0.0000000000000000 0.99737967443382569
@@ -61,9 +61,25 @@ The executable is `fourier`. It's mandatory first argument is name of the functi
0.99998474097810330 0.99739171675277982
1.0000000000000000 0.99738570017718042
-Text files and plots in `res/` can be regenerated by issuing
+Text files and plots in `res/` can be regenerated by issuing
$ make pngs
from the main project directory.
+##Fast Fourier transform##
+The first part of the task was to use fftw3 library to convert the signal `x = sin(2·π·t·200) + 2·sin(2·π·t·400)` (represented by function `f1` in the program) into sum of signals. To perform the discrete Fourier transform, I took values of _f1()_ at 8192 equadistant points from 0.0 to 1.0. The plot of this function (with _x_ axis constrained to [0.0; 0.15] so that anything can be seen) is
+![plot original (untransformed) f1 function](res/f1_original.png)
+In general, the result of a Fourier transform is the frequency spectrum of the input signal. In case of dft we don't get a continuous spectrum, but rather a sequence of values representing the strength of their respective frequency components in the signal. Those values can be plotted and connected by lines to get an approximation of the continuous spectrum. Te result of doing this for _f1_ (_y_ scale logarithmic) is
+![plot discrete Fourier transform of f1 function](res/f1_dft.png)
+We can see the pikes at 200 and 400 that correspond to the sinuses in equation for _x_. Despite what one might expect - other values, although lower, are not zero. This is because we're trying to approximate something infinite using a finite set of discrete values. One can notice, that when the number of points we use is increased - the pikes het higher. In the limit, when going to ∞ points, we would get a Dirac-type distribution.
+Sum of components `cos(k·t) + i·sin(k·t)` with weights being the values we got from the transformation approximates the input function _f1_, hence it is the answer to the first part of the task. What hasn't been mentioned yet is the fact, that for this the weights have to be complex numbers - and they are. In the dft plot above what is shown is not directly the set of values computed by fftw3 library, but rather their absolute values.
+
+The second part of the task was to perform a dft of a cosinus function with some small random number (noise) added to each of it's values. The period of the cosinus was not specified, so `x = cos(2·π·t)` was assumed (represented by function `f2` in the program) and pseudorandom values in the range [-0.01; 0.01] were taken. This is the plot of the original signal
+![plot original (untransformed) f2 function](res/f2_original.png)
+And the plot of it's dft (with _x_ axis range of [0; 150] and logarithmic _y_ scale)
+![plot discrete Fourier transform of f2 function](res/f2_dft.png)
+We can see, that there's a single pike at frequency 1 (corresponding to our main cosinus signal) and all other values are low and seemingly random.
+The last part of the task was to remove all values of the dft with absolute value smaller than 50 and perform the inversed Fourier transform. This zeroed almost all of the 'random' part of the dft. Since the __noise__ in the dft was the result of the __noise__ in the original function, the result of the inversed Fourier transform was an almost perfect cosinus as can be seen below
+![plot f2 function filtered from noise](res/f2_filtered.png)
+This worked, because the amplitude of the noise was small and so the amplitude of frequency components resulting from it was small (almost all absolute values of dft for frequencies other than 1 were 0). In case of stronger noise or a cap smaller than 50 this could possibly not work as well. Nevertheless, this (fast) Fourier transform example also presents one of the method used used for filtering periodical signals from noise. Other ways of filtering dft values also exist (e.g. convoluting with a predefined filter-function). \ No newline at end of file