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?

Filter simulation

% 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);

axis([0 length(2) -1 1]);

plot(filter(Hd, signal2));
axis([0 length(2) -1 1]);

plot(filter(Hd, signal3));
axis([0 length(2) -1 1]);

plot(filter(Hd, signal4));
axis([0 length(2) -1 1]);

hold off;
  • $\begingroup$ Can't you reduce the sampling rate such that the filter operates at a (much) lower sampling rate than your ADC? $\endgroup$
    – Matt L.
    Jun 28, 2016 at 11:38
  • $\begingroup$ 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.. $\endgroup$
    – Pethead
    Jun 28, 2016 at 11:48
  • 1
    $\begingroup$ 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). $\endgroup$
    – Matt L.
    Jun 28, 2016 at 11:54
  • $\begingroup$ So for example if I only read every 10th sample and dont't care about the rest? $\endgroup$
    – Pethead
    Jun 28, 2016 at 11:57
  • 3
    $\begingroup$ Possible duplicate of How many taps does an FIR filter need? $\endgroup$ Jun 28, 2016 at 14:39


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.