# Designing bandpass FIR filter MATLAB

I am trying to design a FIR bandpass filter for a STM32F407 microcontroller with a passband of 1kHz between 59500 Hz and 60500 Hz or something similar (since I don't really know how tight I can squeeze it). I am trying to design the filter in MATLAB so I can get the co-efficents for later implementing them in C.

While simulating it in MATLAB the problem seems to be with the high sampling frequency. The microcontroller that I'm using is sampling at 5.25 MSPS so the FIR filter will have a pretty high filter order and I am wondering if there is something that I can change or can a filter really have this high order? Because it kind of looks like it would be working if the order is around 3000-4000.

Am I doing this correct and are these parameters even realistic? % MATLAB Code
% Generated by MATLAB(R) 8.3 and the DSP System Toolbox 8.6.
% Generated on: 28-Jun-2016 09:43:38

% FIR Window Bandpass filter designed using the FIR1 function.

% All frequency values are in Hz.
Fs = 5250000;  % Sampling Frequency

N    = 3500;     % Order
Fc1  = 59500;    % First Cutoff Frequency
Fc2  = 60500;    % Second Cutoff Frequency
flag = 'scale';  % Sampling Flag
% Create the window vector for the design algorithm.
win = blackman(N+1);

% Calculate the coefficients using the FIR1 function.
b  = fir1(N, [Fc1 Fc2]/(Fs/2), 'bandpass', win, flag);
Hd = dfilt.dffir(b);
%----------------------------------------------------------

t = 0:1/Fs:0.01;    % time vector

signal1  = sin(2*pi*58000*t);
signal2  = sin(2*pi*60000*t);
signal3  = sin(2*pi*62000*t);
signal4  = sin(2*pi*80000*t);

hold on;

length = size(t);

subplot(4,1,1);
plot(filter(Hd,signal1));
axis([0 length(2) -1 1]);
title('58kHz');

subplot(4,1,2);
plot(filter(Hd, signal2));
axis([0 length(2) -1 1]);
title('60kHz');

subplot(4,1,3);
plot(filter(Hd, signal3));
axis([0 length(2) -1 1]);
title('62kHz');

subplot(4,1,4);
plot(filter(Hd, signal4));
axis([0 length(2) -1 1]);
title('80kHz');

hold off;

• Can't you reduce the sampling rate such that the filter operates at a (much) lower sampling rate than your ADC? – Matt L. Jun 28 '16 at 11:38
• I asked my boss if I were aloud to change the sampling rate of the ADC so we wouldn't need to use that high order but he said that there is no reason to lower the sampling rate and the ADC is used for other things so that wasn't allowed.. – Pethead Jun 28 '16 at 11:48
• You can leave the ADC alone, but you could maybe downsample after the ADC for your filtering operation (and use the higher rate where ever you need it). – Matt L. Jun 28 '16 at 11:54
• So for example if I only read every 10th sample and dont't care about the rest? – Pethead Jun 28 '16 at 11:57
• Possible duplicate of How many taps does an FIR filter need? – Marcus Müller Jun 28 '16 at 14:39