Introduction to FIR Filters

Solution

Lab7_notes

## TASK 1

Set parameters such as sampling frequency, signal length, signal frequency and signal-to-noise ratio of the additive white gaussian noise.

```clear all; close all; clc;
Fs = 20e3;
n = 0:1/Fs:(4e-3)-(1/Fs);
f1 = 1e3;
snr = 14;
x = cos(2*pi*f1*n);
x = awgn(x,snr);
```

Time Domain Plot of distorted signal

```figure;
plot(n,x);
xlabel('Time');
ylabel('Amplitude');
title('Distorted Signal');
``` Define filter coefficients of moving average filter

```filter_coeff = 1/7.*ones(1,7);
```

Convolution performed

```y=conv(x,filter_coeff,'same');
```

Zeros appended at th start to recreate latency between input and output in FIR Filter.

```y=[zeros(1,length(filter_coeff)-1) y];
n_ext = 0:length(y)-1;
n_ext = n_ext./Fs;
```

Time Domain Plot of filtered signal

```figure;
plot(n_ext,y);
xlabel('Time');
ylabel('Amplitude');
title('Filtered Signal');
``` ## TASK 2

Implementation of approach utilizing freqz() function.

Filter Difference Equation: Transfer Function: ```num_coeff = [1 2 1];    % numerator coefficients
denom_coeff = 1;        % Denominator coefficients
f_points = 300;         % Granularity of normalized frequency range
[h w] = freqz(num_coeff,denom_coeff,f_points);
```

Plot Magnitude Response of Filter

```figure
plot(w,abs(h));
xlabel('Normalized frequency');
ylabel('Magnitude');
title('Magnitude Response of FIR Filter');
``` ## TASK 3

Recall the vector that stored the 7 point moving average filter coefficients and pass it as argument in the freqz() function.

```[h w]=freqz(filter_coeff,denom_coeff,f_points);
```

Plot Magnitude Response of 7-point Moving Average Filter

```figure
plot(w,abs(h));
xlabel('Normalized frequency');
ylabel('Magnitude');
title('7-point Moving Average Filter');
``` 