Thursday 31 May 2012

FFT

I have wasted to much time trying to write a DFT algoritm in C, source code can be found here. It's not very good, but it computes correctly. Here is an example, where I put in a noisy signal, it contains three sine signals, with frequencies 2Hz, 17Hz and 401Hz with different amplitudes and some noise. It looks like this

And after the Fourier Transform i get this data
In the code I simply checked which frequencies was larger than 0.35 in amplitude, and saved them. The other ones was zeroed. After and inverse fourier transform with the ifft() function. The output was this.
Pretty :)

Tuesday 8 May 2012

Discrete low-pass filter in C

I was interested in trying to make a discrete low-pass filter in C, also make it so that it can take data from from the pipe maybe. Anyway, the filter_rc() function can take data by keep pushing in new values and it takes care of everything.

One problem that my program has is that it cannot run forever, it can only take a limited amount of samples till the buffer is full. I think it is possible to check the value with the first index in the buffer (the last_value[] buffer), and if it is zero the buffer can shift down, I think this will work. Since the zero values in the sum isn't necessary anymore.

Here is a plot of the output, the input is a Sine Wave with 1 Amplitude, and 42Hz. It's plotted over 0.1s. And the filter is C=4.7uF, R=5k. The program can take any input, it doesn't have to be a sine wave. The red curve has 20 samples over 0.1s, and the green has 100 samples over 0.1s.
The Program can be found here https://github.com/Spekkio/dig_filter/blob/master/main.c