# How to design a lowpass filter using Hamming window and sinc function

I have these three equations and have a noisy voice signal. I have to design a low pass filter of length N=1000 using hamming window technique. I have selected its cutoff frequecny 0.25 (normalized). \begin{eqnarray} h_{id}[n] &=& \frac{\sin{(2\pi f_c (n - \frac{N-1}{2}))}}{\pi (n - \frac{N-1}{2})},\ 0\le n \le N-1 \\ w[n] &=& 0.54-0.46\cos{(\frac{2\pi n}{N})} ,\ 0\le n \le N \\ h_F[n] &=& h_{id}[n]\cdot w[n] \\ \end{eqnarray} Now the problems that I am facing are: if I follow the equations, the dimensions of both $h_{id}[n]$ and $w[n]$ becomes unequal and I cannot multiply them to get the finite length impulse responce of sinc function; also as I am a newbie I really do not know how to apply this filter to the voice signal.

Note: According to the instructions from the Professor, I can not use any built-in function or commands except the "filter" command

Any help would be appreciated.

The Matlab code:

clc; clear all;  close all

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

N = 1000;
n = 0:N-1;
new_n = 0:N;
fc = 0.3;
temp_N = (N-1)/2;

h_id = sin(2*pi*fc *(n - temp_N))./(pi *(n - temp_N));
figure('Name','Voice Signal in Time Domain','NumberTitle','off');
subplot(2,1,1)
plot(n,h_id)
title('Continous Time Plot (not true: as we have a DT signal, it is just for understandings)')
xlabel('Time \rightarrow')
ylabel('Magnitude \rightarrow')
axis([450 550 -0.2 0.7])
subplot(2,1,2)
stem(n,h_id)
title('Discrete Time Plot')
xlabel('Samples \rightarrow')
ylabel('Magnitude \rightarrow')
axis([450 550 -0.2 0.7])

w = 0.54 - 0.46*cos((2*pi*new_n)/N);
h_F = h_id .* w;
freqz(h_F)

fileName = 'D:\Studies\Semester#6\Digital Signal Processing\Assignments\Assignment 2\VOICE.wav';

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

N_FFT = length(y);
time = (1/fs) * N_FFT;
t = linspace(0, time, N_FFT);
figure('Name','Voice Signal in Time Domain','NumberTitle','off');
plot(t,y);
title('Time Domain plot of the Voice Signal')
xlabel('Time \rightarrow')
ylabel('Magnitude \rightarrow')

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

playerObj = audioplayer(y, fs);
play(playerObj);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

signalFFT = fft(y);
figure('Name','Voice Signal in Frequency Domain','NumberTitle','off');
subplot(2,1,1)
xaxis = (0:N_FFT-1)/N_FFT;
plot(xaxis, abs(signalFFT));
title('Frequency Domain Plot of the Voice signal (without shifting[fftshift])')
xlabel('Normalized Frequency \rightarrow')
ylabel('Magnitude \rightarrow')
subplot(2,1,2)
plot(xaxis, fftshift(abs(signalFFT)));
title('Frequency Domain Plot of the Voice signal (with shifting[fftshift])')
xlabel('Normalized Frequency \rightarrow')
ylabel('Magnitude \rightarrow')

• Why are you using n=0..N-1 for h[n] and 0..N for w[n]? Both should be the same, I'll leave you to figure it out which one'sthe good range. Also, is the sinc() argument for frequency correct? I can't tell. Jun 20 '18 at 6:37
• There is an article about this (with C++ sample code) here liquidsdr.org/blog/basic-fir-filter-design Jun 21 '18 at 9:06

You have independent equations for you Sinc function and for your window function - the $$N$$ in both of these equations doesn't have to be equal. So, for the Sinc function you can choose $$N=1000$$, which gives you 1000 points of the Sinc. For the window function you simply let $$N = 999$$. More explicitly you can think of it this way: $$\begin{eqnarray} h_{id}[n] &=& \frac{\sin{(2\pi f_c (n - \frac{N-1}{2}))}}{\pi (n - \frac{N-1}{2})},\ 0\le n \le N-1 \\ w[n] &=& 0.54-0.46\cos{(\frac{2\pi n}{N_2})} ,\ 0\le n \le N_2 \\ h_F[n] &=& h_{id}[n]\cdot w[n] \\ \end{eqnarray}$$
Using $$N=1000$$, and $$N_2 = 999$$ produces a sinc function and a window of the same length which can the multiplied together.
Note - One thing you should ensure is that the sinc function and the window have the same type of symmetry - this ensures that the resulting filter also has the same type of symmetry. As an example if the sinc coefficients were $$[-0.1, 0.5, 1 ,0.5, -0.1]$$ then the window should display the same type of symmetry around the 3rd point (notice this if for a filter with an odd number of coefficients. For a filter with an even number of coefficients e.g. $$[-0.1, 0.5 ,0.5, -0.1]$$ then the window coefficient should have that same type of symmetry, so that when they are multiplied together the result has the same type of symmetry. In using $$N=1000$$, and $$N_2 = 999$$ both the sinc and window have the same type of symmetry, so you should be fine.
Note - If you choose an odd length for the sinc filter, your code would have to handle the middle coefficient which encounters a problem with $$\sin(0)/0$$.