I would like to implement a low pass filter in order to smooth a noisy periodic signal (temporal response ). Out(t)= h(t) * In(t) , the problem is to find an h(t) in temporal representation.
Any suggestions? References would be appreciated .
Although the previous answers were sensible suggestions, I explain how I do generate a low-pass FIR (or any filter of any shape, the procedure is the same). I am working in Adobe Audition 1.5, but almost any other sound editor, such as Audacity, can be used.
In the following there is NO THEORY.
1) Generate an empty waveform (silence) of proper length, for example 1s (48000 samples, if you work at 48 kHz sampling rate as I usually do)
2) Zoom in until you see the individual samples
3) Drag one sample from zero to full-scale
4) What You have generated is a waveform containing all zeroes, and juts one sample at 1.o - I usually place this not-zero sample at location #1024.
5) Save this "digital impulse" file as DIRAC.WAV
6) Now apply to it the effect which you like. For example, a Scientific Filter, Butterworth, Low pass, of the order and corner frequency which you prefer.
7) If the amplitude of the filtered signal is too weak, you can boost it at will (but please, keep note of the gain applied)
8) Save the filtered impulse in another WAV file, for example named Lowpass.WAV
9) you are done, you can now use your FIR filter in any convolution software you like.
10) remember that, if you want to compare the unfiltered signal with the filtered one, that convolution with a FOR filter always introduce some latency, If you want to compensate this latency, the "Unfiltered" signal should be convolved with the DIRAC.WAV impulse. As the two filters will have the same latency, the results become directly comparable.
Although the previous answers were sensible suggestions, I explain how I do generate a low-pass FIR (or any filter of any shape, the procedure is the same). I am working in Adobe Audition 1.5, but almost any other sound editor, such as Audacity, can be used.
In the following there is NO THEORY.
1) Generate an empty waveform (silence) of proper length, for example 1s (48000 samples, if you work at 48 kHz sampling rate as I usually do)
2) Zoom in until you see the individual samples
3) Drag one sample from zero to full-scale
4) What You have generated is a waveform containing all zeroes, and juts one sample at 1.o - I usually place this not-zero sample at location #1024.
5) Save this "digital impulse" file as DIRAC.WAV
6) Now apply to it the effect which you like. For example, a Scientific Filter, Butterworth, Low pass, of the order and corner frequency which you prefer.
7) If the amplitude of the filtered signal is too weak, you can boost it at will (but please, keep note of the gain applied)
8) Save the filtered impulse in another WAV file, for example named Lowpass.WAV
9) you are done, you can now use your FIR filter in any convolution software you like.
10) remember that, if you want to compare the unfiltered signal with the filtered one, that convolution with a FOR filter always introduce some latency, If you want to compensate this latency, the "Unfiltered" signal should be convolved with the DIRAC.WAV impulse. As the two filters will have the same latency, the results become directly comparable.
Thank you for you suggestions! I have no doubt that would help me in future steps. But for the moment the problem is in the THEORY; I have a digital signal x(n) which is a noisy periodic, I would like to design a digital low pass filter h(n)= an*yn+ an-1*yn-1+....+an*xn + an-1*xn-1....; How to choose the coefficients : ai, ... & bi, ... ?
To understand the solution i create a simple digital noisy periodic single with OpenCV in C++ ( attached image) how to define the filter to find the smoothed signal
That is the structure for an IIR filter, not for a FIR filter. In a FIR filter you only process the x values, and there are no coefficients to be multiplied for the y values.
I warmly discourage you from using IIR filters. These are obsolete objects nowadays, when FIR filters can operate both more efficiently (thanks to the partitioned convolution algorithm and the FFT) and are much easier to design.
In the past, when IIR filters where widely employed, very complex theories were developed for the design of their coefficients, There are whole book sof hundreths of pages on this topic..
The things become very complex, you need to employ the Laplace transform or the Z-transform, and design the filters by means of "Poles" and "zeros" on the complex plane, taking care of staying away from the "Unit circle", here the IIR filter becomes unstable...
As said, there is no need of this nowadays.
For designing a linear phase (symmetrical) FIR filter, you imply define the spectrum that you want. It can be of any shape, just draw a chart of the gain vs. frequency.
Generate the spectrum of the magnitude of the filter on a linear frequency axis, with a number of spectral lines ranging equal to a power of 2, for example 4096 lines, and covering with constant resolution the whole spectrum, from 0 Hz to the Nyquist frequency (that's half of the sampling rate, for example 24000 Hz f you work at 48 kHz).
OK, more precisely, the number of spectral lines, including the 0th-one (DC) will be 4097 (that is, 2^12+1).
If you want a low pass at, say 100 Hz, you create a complex spectrum of 4097 complex numbers (a vector, called H). The imaginary part is set to zero for al of them.
The real part contains the magnitude.
This will be 1.0 until close to the corner frequency, the "Gracefully" bring the gain to zero, as shown here:
Line n. f (Hz) Real Imag
0 0.00 1 0
1 5.86 1 0
… ….. 1 0
14 82.03 1 0
15 87.89 1 0
16 93.75 1 0
17 99.61 0.9 0
18 105.47 0.7 0
19 111.33 0.5 0
20 117.19 0.3 0
21 123.05 0.1 0
22 128.91 0.05 0
23 134.77 0.02 0
24 140.63 0.01 0
25 146.48 0.005 0
26 152.34 0.002 0
27 158.20 0.001 0
28 164.06 0.0005 0
29 169.92 0.0002 0
30 175.78 0.0001 0
31 181.64 0.00005 0
32 187.50 0.00002 0
33 193.36 0.00001 0
34 199.22 0 0
35 205.08 0 0
… ….. 0 0
4096 24000.00 0 0
Now apply an IFFT to your complete singe-sided spectrum (you need a "real" IFFT, of course), which will produce a time-domain sequence of real values, 8192 points long.
As the phase was set to zero,the filter is acausal: you need to "fftshift" the resulting time domain waveform before using the set of filtering coefficients.
The simplest way is to cut away the first 4096 samples, and paste them at the end
This is your (quite short) FIR filter, and it looks like a central pulse with decaying oscillations around, both on left and right sides.
As said, by design, this is a linear phase, symmetrical FIR filter.
If your design curve is very steep in frequency domain, the resulting time-domain waveform tends to be very long. If it is really very long, an 8192-points window will not suffice for accomodating it anymore, and you need to generate a longer FIR.
Just recreate a new spectrum with a larger number of lines (for example 16384 lines, which will create a time-domain filter of 32768 samples).
If you don't want to go into the theory and you have MATLAB (and the signal processing toolbox), just type 'fdatool' in the command window to open the 'filter design and analysis tool'. You can input filter specifications and the tool will compute the coefficients for you.