1

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

% 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;
Pethead
  • 21
  • 1
  • 5
  • 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
  • 1
    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
  • @Pethead only if you can make absolutely sure the analog signal has no spectral components above $\frac{f_s}{20}$! Otherwise, there will be aliases. – Marcus Müller Jun 28 '16 at 11:59
  • @Pethead what is your transition band width? that's the crucial thing when designing filters; it's what usually dominates among the things defining the length of the resulting filter. Also, what is acceptable ripple in passband, and what is minimum stop band attenuation? – Marcus Müller Jun 28 '16 at 12:04
  • I hope you don't mean factorial(fs / 20) because that is huge...

    I want my transition band to be as short as possible ofcourse, so we don't get any unwanted signals at all. But if I shoot from the hip I could probably say 1kHz transition band or something(?).

    How much ripple in the passband that is allowed, I don't really know...

    – Pethead Jun 28 '16 at 12:13
  • 3
  • well, those are necessary to define your filter, so come back with an idea of that, ideally. Other than that: see duplicate hint above – Marcus Müller Jun 28 '16 at 14:39
  • Okay that looks good atleast, but if I enter my parameters in that formula I get something N = 9.186...e+9 which is ridiculous high – Pethead Jun 28 '16 at 15:56
  • @Pethead, read my entry on decimation and why you need to do it- I think it will help you understand the point Matt L is trying to make: http://dsp.stackexchange.com/questions/31548/fast-integer-8-hz-2nd-order-lp-for-microcontroller/31553#31553 – Dan Boschen Jun 29 '16 at 04:57

0 Answers0