# Lab 4: Digital FIR Filter Design
Filters are common objects in digital signal processing. They are usually used to apply/cance some effect or to separate signals from each other. In this assignment, you are going to try separating speech from noise and canceling echo effect. You are going to apply the DFT and IDFT transform. While these are very similar to DTFT and IDTDF, it is important to remember what are their differences.
[TOC]
# Content
- Suppress noise components from signal
- Specify the desired frequency response
- Compute impulse response in the temporal domain
- Apply a window function
- Evaluate the result
- Canceling undesired effects
- Hyperparameter tuning
- Self-check questions
## Suppress noise components from signal
### Specify the desired frequency response
The recording contains a recording that has a high-frequency noise around 10 kHz, as well as low-frequency noise at 10 Hz and 20 Hz.

Working with signals in time domain (unless these signals are very simple) is not very straihtforward. However, it appears that many signals are separable when projected into the frequency domain. The tool that allows to compute the frequency spectrum is Fourier transform.

### Compute impulse response in the temporal domain
Handle high-frequency noise using low-pass filter

Handle low-frequency noise using high-pass filter

### Apply a window function
Shift the frequency response and apply Kaiser–Bessel window with alpha=100 (this parameters will be explained in the next sections)

### Evaluate the result

As we can see low and high frequency components are successfully handled.
## Canceling undesired effects
Consider some signal passing through an environment . This environment has a certain effect on the signal.
$$\widetilde{s} = h * s$$
This is essentially the way an echo is created. The audio signal
propagates through the room to the signal receiver (microphone) along many paths. This multipath propagation causes the echo to appear.
This effect can be canceled by an additional filtering step so that
$$s = \widetilde{h} * h * s = \delta * s$$
As we know, the convolution of any sequence with a Kronecker sequence does not change the original sequence.
The design of the filter is not straightforward in the time domain but is much easier in th frequency domain.

$$\widetilde{H}(\exp(-jw)) = H^*(\exp(-jw)) / | H(\exp(-jw)) |$$
Let's find invert filter using this formula

Inverse transform reveals similar issue that was observed for the ideal low-pass filter.
Let's solve this problems using same techniques as in previous task.

## Hyperparameter tuning
### Window function
In signal processing and statistics, a window function is a mathematical function that is zero-valued outside of some chosen interval, normally symmetric around the middle of the interval, usually near a maximum in the middle, and usually tapering away from the middle.
#### Rectangular window
The (zero-centered) rectangular window may be defined by


#### Triangular window
The triangular window is the 2nd order B-spline window. The L=N form can be seen as the convolution of two N/2 width rectangular windows. The Fourier transform of the result is the squared values of the transform of the half-width rectangular window.

#### Hanning window


#### Hamming window
The Hamming window is an extension of the Hann window in the sense that it is a raised cosine window of the form


#### Kaizer window

##### alpha = 8

##### alpha = 20

##### alpha = 60

##### alpha = 100

Alpha = 0 corresponds to a rectangular window. Conversely, for larger alpha the width of the main lobe increases in the Fourier transform, while the side lobes decrease in amplitude. Thus, this parameter controls the tradeoff between main-lobe width and side-lobe area.
### Experiment results
Comparison of $\widetilde{h} * h$ and $\delta$ (using Euclidean distance)
Points are in the order :
[Rectangular Triangular Hanning Hamming Kaizer20 Kaizer60 Kaizer100]
So, Kaizer window with alpha = 100 gives best approximation in my experiments

## Self-check questions
### Discuss the question of interchangeability of DTFT and DFT
DFT works with circular signals, DTFT generally with all of l1. If the signal has a period m, then DFT over a gap of length m will give the same result as DTFT over the entire signal.
### What is a Hermitian function?
In mathematical analysis, a Hermitian function is a complex function with the property that its complex conjugate is equal to the original function with the variable changed in sign: (where the indicates the complex conjugate) for all in the domain of.
### What are the criteria for the designed filter to have only real values?
If the values are not real, then after applying to real-valued signals, the result will not be real-valued in the general case.
### Why does one need to introduce a linear-phase shift?
FIR filters can be with a linear phase - this property allows you to save the waveform of the signal.
### What is the difference between various window functions? Why does one need to apply a window function?
The low-pass filter is infinite after conversion from the spectrum.
### What is the spectral equivalent of applying a window function?
Convolution in the spectral domain.
### Can a signal have finite support in both temporal and sprectral domains?
No