I made this question https://dsp.stackexchange.com/questions/19731/newbieplotting-fft-and-impulse-response-coefficients-using-java

I have the IRC: Impulse Response Coefficients:

$h(k), k = 0, 1,.., N-1$

Low Pass: $h_D(k)=\sin(k\omega_c)/{k\pi} , k\neq0; h_D(0)=2f_c$

High Pass: $h_D(k)=-\sin(k\omega_c)/{k\pi}, k\neq0; h_D(0)=1-2f_c$

Band Pass: $h_D(k)=(\sin(k\omega_{cH})-\sin(k\omega_{cL}))/{k\pi}, k\neq0; h_D(0)=2(f_{cH}-f_{cL}) $

Band Stop: $h_D(k)=(\sin(k\omega_{cL})-\sin(k\omega_{cH}))/{k\pi}, k\neq0; h_D(0)=1-2(f_{cH}-f_{cL}) $

Hamming Window Function:

$w(k)=0.54+0.46\cos( \frac{2\pi k}{N} )$

so we have: $h(k) = w(k)\times h_D(k)$

obviusly my $h(k)$ can be represented as:

double[] h = new double[N];  //N:odd integer
//hD[(N-1)/2] -> center or hD(0)
for (int  k = 0; k < N; k ++) {
  h[k] = hD[k]*w[k];

I want to get the formula to evaluate the h[k]

In matlab to do this:

[hFlt,fFlt] = freqz(h,1,256);
mLP = 20*log10(abs(hFlt)); 

enter image description here

I want to obtain hLP and fLP values to plot filters response (without using matlab).

But I don't know the formulas(procedure or algorythm) to plot the frequency response.

  • $\begingroup$ It's not clear at all what you are asking. You seem to be able to plot the frequency response just fine. Also, what are hLP and fLP? Please edit your question to make clear what you need. $\endgroup$ – MBaz Jan 14 '15 at 23:46
  • $\begingroup$ You need the Discrete Fourier transform (DFT). This is what the Matlab command freqz does, it transforms coefficients to the frequency domain. Look up DFT, and you'll find a lot of information. Note that you do not need an FFT, because efficiency is not an issue here. $\endgroup$ – Matt L. Jan 15 '15 at 8:12

Assuming you have a set of (windowed) filter coefficients $h[n]$, $n=0,1,\ldots,N-1$, and you want to evaluate the corresponding frequency response at $ M\ge N$ equidistant normalized frequency points

$$f_k=\frac{k}{2M},\quad k=0,1,\ldots,M-1\tag{1}$$

then you need to evaluate the following formula, which is the discrete Fourier transform (DFT):

$$H[k]=\sum_{n=0}^{N-1}h[n]e^{-j\pi nk /M},\quad k=0,1,\ldots, M-1\tag{2}$$

The actual frequencies in Hz are given by $f_k\cdot f_s$, where $f_s$ is the sampling frequency.

Equation (2) is exactly what you get with the Matlab command

[H,w] = freqz(h,1,M)

where $f_k=$ w(k+1)/(2*pi) (because Matlab indices start at $1$, not at $0$).

If you want to evaluate the frequency response at arbitrary, not necessarily equidistant normalized frequencies $f_k$, you need to evaluate

$$H[f_k]=\sum_{n=0}^{N-1}h[n]e^{-j2\pi nf_k},\quad 0\le f_k\le 0.5\tag{3}$$

which for the choice of $f_k$ according to (1) of course reduces to Eq. (2).

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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