I'm trying to find the frequency response and the DC gain, then plot the response and find the cutoff frequency from the graph.
I start off with the impulse response $$h(t)= 1 ; 0\leqslant t\leqslant Ts$$ and my frequency response being $$H(j\Omega)= \int_{0}^{Ts}e^{-j\Omega t}dt$$ $$=\frac{-1}{j\Omega} (1-e^{-j\Omega Ts})$$

Now, I'm having trouble with writing the code. I'm assuming something is missing but I can't figure out what exactly. What I did was define the impulse response and simply find FFT of the function, then plot it (which I'm not sure if the plot is correct). How does that help me find the DC gain or the cut-off frequency? This is a relatively new topic to me and I'm still trying to pin things down.

import numpy as np
from scipy.fftpack import fft
import matplotlib.pyplot as plt

Ts =0.001
n = np.arange(-5,7,1)
h = 1*(n>=0)*(n<=Ts)
Hr = fft(h)

plt.title('Frequency Respone of ZOH')

1 Answer 1


The frequency response of a zero order hold is a Sinc function, and if done properly we can approximate it with a DFT. Since the DFT is the processing of sampled signals, we will have the effects of aliasing from the sampling process to contend with.

A few issues jump out with the OP’s use of the fft approach:

h should be multiple samples of all ones if we wish it to represent a sampled version of the time domain pulse; the higher the sampling rate, the more samples will appear between 0 and .1 s and aliasing errors will be minimized. When done properly h will be something like:


(The OP has implemented n to go from -5 to 7 in steps of 1, so only one sample will meet the test condition. The OP is effectively sampling a 0.1s pulse with a 1 Hz rate so not sampled nearly high enough.)

Zero pad the fft to approximate a continuous frequency response (the DTFT). The fft function will zero pad just by adding the optional total number of samples parameter. In the OP’s case this can be done with N samples (Where N is much larger than the length of h) and scale by the length as follows

Hr = fft(h, N)/L

Where $L$ is the length of $h$, and $N>>L$, all positive integers.

And then we can plot the magnitude and phase of the result separately to get the magnitude and phase frequency response. Note the approach here will pad zeros to the end of the waveform - if we pad zeros in front of the waveform or after or both, this has the effect of a time delay which will only effect the phase of the frequency response but not change the magnitude.

By changing the number of ones in h and repeating above, my comment about reducing aliasing effects will be clear: the expected frequency response is a Sinc function, but the approach outlined here will return what is called “the Dirichlet Kernel”. As the sampling rate increases the Dirichlet Kernel approaches a Sinc function.

  • $\begingroup$ Thank you. I'm still having trouble getting the h to be multiple samples of 1s; I tried increasing the sampling period(Ts >=1) and I did get multiple ones with a few zeros. So should my approach be increasing the sampling period and decreasing the steps in n? $\endgroup$ May 21, 2022 at 9:58
  • $\begingroup$ This is what my output looks like Is this what I'm going for? I've set my Ts at 8, and n between 0,8 with a step of 1 with 1000 Samples $\endgroup$ May 21, 2022 at 11:14
  • $\begingroup$ Yes looks perfect. You can use fftshift() to center the result on 0 if you like. Just pass the result of your fft to be a parameter in fftshift. The way you wrote the code it appeared you wanted to generate a pulse from 0 to .1, now I understand Ts is the sampling rate. If you want to generate a pulse from -5 to +7 in steps on 0.1, use the np.linspace command which will do that directly. $\endgroup$ May 21, 2022 at 13:54

Your Answer

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

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