---
# System prepended metadata

title: DSP. Assigment 4 Report

---

# DSP. Assigment 4 Report

[ToC]

## General

> **Author**: Ruslan Sabirov 
> **E-mail**: r.sabirov@innopolis.ru
> **Group**: B17-DS-02


## Tasks
The assignment consist of two parts:
1. Design lowpass and highpass filters to remove noise at certain frequencies.
2. Design a filter to remove the echo from the sound.

## Solution
### 1. Construct filters and remove noise.

1. Read signal, take the first chanel.
![](https://i.imgur.com/gKm4KRw.png =400x)

2. Since it is much easier to see the noice in frequency domain, lets take an FFT of the signal to move from the time domain to the frequency domain.
![](https://i.imgur.com/97CZJnV.png =400x)

3. Construct two filters: lowpass and highpass. Lowpass passes only frequencies below 6500 Hz, highpass passes only frequencies above 40 Hz.
![](https://i.imgur.com/AFvynuy.png =330x) ![](https://i.imgur.com/H9WUqDt.png =330x) 


4. Move to time domain. Since we cannot see the future, we want our filter to be causal. To solve the problem we need to shift the filter.
![](https://i.imgur.com/oKctvRW.png =330x) ![](https://i.imgur.com/lG2erUu.png =330x)


5. To solve the problem of non-zero filter (which makes filter impractical) we need to apply window function to the filter.
![](https://i.imgur.com/giAahjX.png =330x) ![](https://i.imgur.com/u101QVq.png =330x) 


6. Return to frequency domain. Observe that graph is smoother that in the original one (without shift and window function).
![](https://i.imgur.com/b0SJobi.png =330x) ![](https://i.imgur.com/o3zKZdk.png =330x)


7. Apply the filter. See that all frequencies from ~40 Hz to ~6500 Hz were not changed, all others are lowered.
![](https://i.imgur.com/7LFFguy.png =400x)

8. Listen the [result](https://drive.google.com/open?id=1yW-mbX8306e-NVM8smxNdRNKWXHa377v). Noise is fully canceled.

### 2. Cancel echo of the room.
1. Read signal and IRC, take the first channel.
![](https://i.imgur.com/6ImpvP4.png =330x) ![](https://i.imgur.com/X9Nnfxh.png =330x)

2. Apply FFT and move to frequency domain.
![](https://i.imgur.com/Ch6W1Ye.png =330x) ![](https://i.imgur.com/jemOhzF.png =330x)


3. Add the echo to the signal by convolving it with IRC.
![](https://i.imgur.com/PanGy9o.png =330x)


4. Compute the filter: calculate the inverse IRC, shift and apply window function.
![](https://i.imgur.com/mXK7Rmf.png =330x)


4. Remove the echo from the signal by convoling signal with echo and filter. 
![](https://i.imgur.com/x0Lcir5.png =400x)


5. Compare the result with real delta signal. They are pretty similar.
![](https://i.imgur.com/92yCzCn.png =300x) ![](https://i.imgur.com/cIz84Ru.png =300x)


6. Listen to the [result](https://drive.google.com/open?id=1yW-mbX8306e-NVM8smxNdRNKWXHa377v). There is a noise in the result this is because after applying the window function, the filter cannot perfectly restore the original signal.


## Conclusion
### Outcomes
* I have learned how to constuct highpass and lowpass filters to left only human voice and remove the noise and how to constuct filter to remove echo of the room.
* I have practiced with using SciLab.

### Problems
I have faced with several technical issues:
* Accidently I have plotted different graphs on the same figure and result was very strange. Solution was to add `figure(id)` before plotting each function.
* My laptop were broken and I was not able to turn it on. I was forced to spend some time to fix the issue, reinstall the OS and Scilab. Fortunately, code was saved.

### Results improvements
The solution could be optimized by applying other constants in filters construction and using another window function.

## Questions
1. **Discuss the question of interchangeability of DTFT and DFT**
DFT: $$X[k] = \sum_{n=0}^{N−1} x[n] \cdot e^{−j2πnk/N}$$
DTFT: $$\hat{X}(e^{jω}) = \sum_{-\infty}^{ \infty } \hat{x}[n] \cdot e^{−jωn}$$

|      | Input              | Output               |
|------|--------------------|----------------------|
| DFT  | discrete, periodic | discrete, periodic   |
| DTFT | discrete, infinite | continuous, periodic |
From the above table is is clear that for finite length and periodic signal DFT and DTFT are essentially interchangeable. A signal with finite length can be treated as, and represent a periodic signal.

2. **What is a Hermitian function?**
Hermitian function is such complex funtion that its complex conjugate is equal to the original function with the variable changed in sign: $\displaystyle f^{*}(x)=f(-x)$. 

3. **What are the criteria for the designed filter to have only real values?**
The function $f$ is real-valued if and only if the Fourier transform of $f$ is Hermitian.

4. **Why does one need to introduce a linear-phase shift?**
Frequency response of the filter has only real part, and imaginary part is equal to zero. Such filters are called zero-phase filter, and in general such filters are not causal. To solve this problem, we needs to introduce linear phase to the frequency response.

5. **What is the difference between various window functions? Why does one need to apply a window function?**
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 lowered away from the middle.
Different window functions have different shapes, height, width and thus, provide different result after applying. They are used to remove the noise, change the pace and so on.

6. **What is the spectral equivalent of applying a window function?**
Convolution in spectral domain.

7. **Can a signal have finite support in both temporal and sprectral domains?**
???

8. **How can you explain the residual after the echo cancellation?**
There is a residual noise in the result this is because after applying the window function, the filter cannot perfectly restore the original signal.