# Selecting the Low Pass FIR Filter, Decimation, DSP

I'm studying DSP, but I have weakness about it.

But, I don't know how select the Low Pass Filter.

I am assuming that this depends on the sampling frequency, But I need explanation "as with clay".

I know what is a FIR Low Pass Filter, but I don't know what is the specification for this case (Decimation)..

Thank you!!

• What exactly do you mean by "select the low pass filter"? Do you mean how to select the filter coefficients? What exactly is it that you are trying to do? – Jim Clay Jan 16 '15 at 5:15
• @JimClay, i think, given the context of SRC, Anita wants the lowpass filter that has cutoff at $\frac{f_\text{Nyquist}}{M}$ (or $\frac{\pi}{M}$ in normalized angular frequency as in the DTFT) where $M$ is the downsampling factor. – robert bristow-johnson Mar 17 '15 at 18:14

When you are decimating a signal x(n), to x(an) (a>1),in the frequency domain the spectrum expands. This might lead to aliasing of the adjacent spectral bands.So to avoid it we use a "anti aliasing filter".

Now choosing an FIR low pass filter depends on many factors like, order of the filter, attenuation in stop band, range of pass band frequencies, etc..

Till my knowledge, sampling is not at all a point of concern while designing the filter. you only decimate the signal after filtering.

To quote an example, in the base band part of digital communication, at the transmitter side, you upsample the signal and you use a anti imaging filter, to avoid multiple copies of the same spectrum being repeated. where as in the receiver you first filter out the signal and then decimating it for further processing.

Cheers, phani tej

• Yes, but I don't know how to specific frequencies to pass (frequency to stop) or frecuency to pass, then frecuency to cut... I have clear the attenuation (order filter) and type of Window, but I don't know what frequencies must be stopped – Anita Jan 16 '15 at 16:16
• thats depending on your requirement.you normalize your passband and stop band frequencies by your sampling frequency. now using fir1 command in matlab, specify the type of filter you want. Thats all! :-) – phanitej Jan 17 '15 at 7:30
• When I need a Low Pass Filter, I have clear that I want, but Now I'm only want downsampling (decimating) then I don't know what High Frequencies must be to stop, because I don't want filter, Only I want reduce Sample frequency, then to select the cut frequency for Low Pass Filter isn't clear. What frequency for my Low Pass Filter I need to select? For example: I have a wav file with 32K, Now I want to reduce to 16K and 8K a) First from 32K to 16K, later from 16K to 8K b) from 32K to 8K directly What's my cut frequency, because I'm not interested to lose information High frequency. – Anita Jan 17 '15 at 21:31
• take a look at this.en.wikipedia.org/wiki/… – phanitej Jan 18 '15 at 5:04
• I read it, but it is very confusing to me. Thank you for your time, but I need something clearer. With example :( and I am convinced that Matlab is a software application but not teaching, because all the functions and techniques are a black box, and the concept is not explained explicitly. – Anita Jan 19 '15 at 1:27

Firstly your FIR LPF design depends on factors such as sampling rate, maximum frequency, cut off frequency, bandwidth and impulse response. For generating your impulse response, you can use sinc function.

Based on your question, I understand that your asking how to select the cut off frequency with respect to the sampling rate. If that's the case, I will give a brief about it with an example.

So, consider an input signal with a sampling rate of 1000sps. Lets assume that we want to pass frequencies only up to 100Hz and block the higher frequencies those are above 100 Hz. So, now your cut off frequency is 100 Hz. Note that your selected cut off frequency must be below the maximum frequency present in the signal. Mathematically:

We know that, Sampling Rate ,

                              F_s = 1000 sps


Then the maximum frequency is given by,

                        F_max = F_s/2 = 1000/2 = 500 Hz


So, from above, we know that the maximum frequency present in the signal is 500 Hz, therefore , your selected cut off frequency must be below 500 Hz to avoid aliasing. So, In general, the value of your cut off frequency must be of the value between 0 to 0.5. Since the normalized sampling frequency value is 1 and 0.5 represents half of the sampling rate i.e. 500 in this case.

In our example, we have selected a cut off frequency of 100 Hz, so Mathematically:

  cut off frequency, F_c = 100/1000 = 0.1 ---> Less than 0.5 i.e. 500 Hz


And, just for the understanding purpose, what If we had selected the cut of frequency as 600 Hz instead of 100 Hz?. Lets calculate and see.

             F_c = 600/1000 = 0.6 -----> Greater than 0.5


In the above, we can see that the cut off frequency selected is greater than 500 Hz and this will create aliasing. So to avoid this, we always select F_c to be less than 0.5.

However, additional factors such as transition bandwidth and impulse response length must also be considered when designing your FIR LPF.

Now coming to down sampling, It basically means your dropping some samples from the existing one's to reduce the number of samples present in your output signal. I will just present a simple down sampling code for you to get some idea:

int M;                   // sampling factor - integer value
int N = 1024;
double *inputsignal[N];  // generate input signal/data using sin function
double *outputsignal[N]; // To accumulate the downsampled signal
int input_samplerate;    // input signal sampling rate
int output_samplerate;   // desired output signal sampling rate
int set_input_output_samplerate(); //function to set rate & calc factor
int downconvert();

int set_input_output_samplerate()
{
M = input_samplerate/output_samplerate; // for 100/50 = M = 2
return M;
}
int downconvert()
{

int index = 0;
for(int i =0 ; i<input_samplerate/M ; i++)
{
outputsignal[index++] = inputsignal[i*M]; //drop 2 samples from input for each iteration and copy the data to output array and increment it
}
}
int main()
{
call set_input_output_samplerate(); //call function to set rate & calc M
call  downconvert(); // call function to downsample
}


Note : The above code is only for downsampling by integer factors and it does not include for filtering. So, you have to low pass filter your signal before downsampling it using the above. I hope this helps.