# How to construct ideal low pass filter in matlab? [closed]

Firstly, I was asked to construct a signal $x(t)= 2 \cos(2 \pi f_1 t) + 1.5 \sin(2 \pi f_2 t)$ with $f_1= 100, f_2=200, t= 50 \textrm{ms}, Fs= 1\textrm{kHz}$ and number of FFT points $N = 1024$ and my code until this part is below.

f1=100;
f2=200;
fs= 1000;
N= 1024;
t=0:1/fs: 0.05;

x= 2*cos(2*pi*f1*t) + 1.5*sin(2*pi*f2*t)


I don't know that if this is the ideal low pass filter with frequency $f_c$, how to construct it in MATLAB? • 1) It is not the ideal low pass filter, 2) $Fs$ does not come into play, neither on formulas or code (so, why define it?). A discrete signal would be indexed by some variable $n$ denoting the $n^{th}$ sample, 3) The sketch does not correspond to the spectrum of $x$. $x$ is only composed of two spectral lines at $f_1$, $f_2$. Do you think you could do a little bit of reading on the ideal low pass filter and come back if you still have difficulties? In the meantime, please keep in mind, questions requesting code to spec are off topic in DSP.SE – A_A Mar 8 '18 at 9:13

## 1 Answer

The ideal lowpass filter is an infinitely long sinc function. It's Fourier transform is a rectangular shape as shown in your frequency spectrum diagram. In practice you have to window (truncate) it to a certain number of samples. The periodic width of the lobes of the sinc will correspond to the width of your frequency rectangle (lowpass cutoff frequency)