I found this free DSP book by Rutgers University professor Sophocles J. Orfanidis. The book is called Introduction to Signal Processing and the link contains many different implementations of common DSP functions in both MATLAB and C.

My intention is to eventually implement this Butterworth BPF in C for an embedded platform. The BPF is described in section 11.6.4 on page 618 of the PDF version of this book.

On page 622 there is a filter design example 11.6.5 which shows how to obtain the BPF coefficients. As I understand it, these coefficients are for the four stages of a cascaded filter design, $H_0(z), H_1(z), H_2(z), H_3(z)$ as described on page 621 and the overall transfer function is $H(z) = H_0(z)H_1(z)H_2(z)H_3(z)$

I do not understand how to use the output of bpsbutt.m to create $H(z)$ and $h(n)$

My goal is to generate band-limited noise on an embedded platform in real time. I want to do this by generating AWGN and filtering it with a BPF. Platform i am using is an RFSoC with an ARM processor.

The center frequency must be adjustable across a range from 500 MHz to 2000 MHz with a minimum center frequency step of 1 MHz and a maximum of 50 MHz.

The bandwidth of the noise must be adjustable from 100 MHz to 300 MHz.

My question is this: Could you please provide a MATLAB example of how to properly use this function to filter a signal?

  • 2
    $\begingroup$ Hi! You're asking for matlab code, written to your specification! That's explicitly off-topic here. Instead, try to explain the signal processing problem (not the programming problem) that you're trying to solve – why not simply use matlab's own filter design methods? also: are you sure you want to do a butterworth on an embedded device? Filter designs lifted from the analog domain to the discrete-time domain are rarely the optimal choice. $\endgroup$ Commented Aug 18, 2022 at 7:30
  • $\begingroup$ Thank you for replying! I am not sure and thats why im asking questions here. What do you suggest as an alternative? The problem i am trying to solve is to generate band limited noise and my approach is to generate AWGN then filter with a BPF to get band-limited noise. I need the BPF to be tunable and to be able to operate across a frequency range $\endgroup$ Commented Aug 18, 2022 at 13:37
  • 1
    $\begingroup$ then: don't use a variable bandpass filter (which is really annoying to re-design on the fly, especially on a small computer), but a fixed-bandwidth low-pass filter. Multiply its output with a cosine (or a complex sinusoid, if this is complex baseband) to shift the center frequency from 0 to the desired frequency. $\endgroup$ Commented Aug 18, 2022 at 13:43
  • $\begingroup$ I need to be able to adjust the width of the passband of the filter as well not just the center frequency. Generating coefficients is not a problem with the embedded device i am using. It has more than enough resources to be able to do this. $\endgroup$ Commented Aug 18, 2022 at 13:45
  • 1
    $\begingroup$ you can totally forget about creating four billion samples of white noise on the ARM. Does, and will not happen. Source: supervised a FPGA thesis doing gigasample WGN generation on an RFSoC. You're multiple orders of magnitude off in performance from what you need. And I'm talking about hand-assembled highly optimized noise generation, not about matlab. $\endgroup$ Commented Aug 18, 2022 at 14:42

2 Answers 2


That is one of the more tortured output formats I've seen: It's basically cascaded 4th order sections. For embedded implementation I would recommend converting this into cascaded 2nd order sections. If you want to use this format directly in Matlab you can try something like this:

%% Design bandpass from 1kHz to 2kHz, 
fs = 48000; % sample rate
[a,b,p] = bpsbutt(1,fs,1000,2000,1000/sqrt(2),2000*sqrt(2),1,60);
% calcualte the impulse response by cascaded filtering
nx = 2^14; d0 = zeros(nx,1); d0(1) = 1;
h0 = d0;
for i = 1:size(a,1)
  h0 = filter(b(i,:),a(i,:),h0);

%% do a quick plot
fh0 = fft(h0);
frAxis = (1:nx/2)'/nx*fs;
xlabel('Freq in Hz ->');
ylabel('Level in dB ->');
set(gca,'ylim',[-100 3]);
  • $\begingroup$ thank you for replying! This is really helpful! My goal is to generate band-limited noise on an embedded device and my approach is to create AWGN samples and filter them with a BPF that is tunable and can operate across a frequency range. Could you point me to some literature that would be better suited for this application if you think this is not the best approach? $\endgroup$ Commented Aug 18, 2022 at 13:39
  • $\begingroup$ Matlab and Python have perfectly good filter design packages build in. $\endgroup$
    – Hilmar
    Commented Aug 18, 2022 at 16:22

The MATLAB code you have shown just outputs coefficients for IIR butterworth filter, the same can be done with MATLAB's built in butter function. It's probably not required that you implement this into embedded unless absolutely necessary. There's plenty of documentation on how to find the coefficients for the type of filter you want (i.e. butterworth) depending on your application:


The only thing useful MATLAB is probably useful for is quickly calculating the coefficients for your filter offline and hard-code them in your embedded code.

The butterworth filter you have shown is an IIR filter as it provides two sets of coefficients a and b. The link you have provided does not have a .c implementation of such filter (only see a FIR.c implementation). You can search online for implementing IIR filters in C ; example here on stack overflow:


  • $\begingroup$ Thanks for replying. I know the link doesnt have a C implementation thats why i said i want to implement it in C and yes it is necessary for me. I need to generate the coefficients because the filter needs to be tunable and be able to operate across a frequency band so hard coding coefficients is not something i can do. $\endgroup$ Commented Aug 18, 2022 at 13:34
  • $\begingroup$ Are you saying you NEED to compute the filter coefficients in real time on embedded hardware? May I ask why? $\endgroup$
    – Jdip
    Commented Aug 18, 2022 at 13:36
  • 1
    $\begingroup$ Because i need to be able to change my center frequency and bandwidth of operation $\endgroup$ Commented Aug 18, 2022 at 13:43
  • $\begingroup$ I guess it depends on which embedded processor you intend to do this on - If it's anything like microchip, they have their own library code for applying IIR and FIR filter but no libraries for generating coefficients; other platforms may be more generous. $\endgroup$
    – pm101
    Commented Aug 18, 2022 at 13:55
  • $\begingroup$ its a Xilinx Zynq RFSoC $\endgroup$ Commented Aug 18, 2022 at 14:20

Not the answer you're looking for? Browse other questions tagged or ask your own question.