# Plot the frequency response of MTI delay line canceller using Octave

I try to plot the frequency response of the delay line canceller (FIR filter which used for MTI).

The delay line canceller has the following structure:

              +-----+
|     |
x [k] >---+---|  T  |
|   |     |
|   +-----+
|      |
|   +-----+
|   |     |
|   |x -1 |
|   |     |
|   +-----+
|      |
|   +-----+
|   | ___ |
\---| \   |---> y [k]
| /__ |
+-----+


Its frequency response is well known (Pg 20) and equal:

$$H(\omega) = 2 \cdot \left|\sin (\frac{\omega \cdot T} {2})\right| \tag{1}$$

I also try obtain frequency response of the canceller using algorithm which described on this question:

$$y [k] = x [k] - x [k - 1] \tag{2}$$

$$Y (z) = X (z) - X (z) z ^{-1} \tag {3}$$

$$H(z) = 1 - z^{-1} \tag{4}$$

Now I try to plot (using GNU Octave) both of responses (1) and (4).

w = linspace (0, 2 * pi, 100);
z = exp (-j .* w);

H_z = 1 - z .^ -1;
H_w = 2.0 * abs (sin (w / 2) );

hold ("on");
plot (w, H_z, "1", "linewidth", 2);
plot (w, H_w, "2", "linewidth", 2);
title ("Frequency response of the delay line canceler.");
set (gca, 'XTick',     0: pi / 2: 2 * pi)
set (gca, 'XTickLabel',{'0', 'pi / 2', 'pi', '3 pi / 2','2 pi'})
xlabel ("Angular frequency.");
ylabel ("Magnitude.");
legend ("H (z)", 'H (\omega)');


I expect that they will be the same, but they are different.

Where is my mistake?

P.S. If I add modulus for (4) (like: H_z = abs (1 - z .^ -1);) they will became the same.

• That's what I told you in my previous answer. The frequency response is actually a complex-valued function. This is what you get when you evaluate $H(z)$ on the unit circle. You have to take the magnitude to get what you call the "frequency response" (which is usually referred to as "magnitude response" or simply "magnitude of the frequency response"). – Matt L. Mar 4 '15 at 8:22
• @MattL.,You have to take the magnitude to get what you call the "frequency response" (which is usually referred to as "magnitude response" or simply "magnitude of the frequency response"). - Thanks a lot! This should be the answer. – Gluttton Mar 4 '15 at 10:16

Magnitude |H(z)| is always defined as an absolute value of your transfer function H(z) values which are complex. What you are plotting is the vector that contains complex numbers. You need to take their absolute value and that will give you magnitude.

If you call the angle function then you are going to get phase. Transfer function H(z) is always complex. Try to print values of real(H_z) and imag(H_z), then you will see real and imaginary values of $H(z)$. Now magnitude |H(z)| is sqrt(real * real + imag * imag) for every sample...

• Magnitude is actually SQRT(real*real + imag*imag) (i.e. don't forget the square root). – Matt L. Mar 4 '15 at 9:14
• Thanks for your answer it is useful! I have dealt with suggested functions and it helps me understand the Frequency response better. But my mistake is that I mix up Frequency response and Magnitude response. – Gluttton Mar 4 '15 at 10:16
• I think it is still worth of accepting so it won't appear over and over again on the main page. – jojek Mar 4 '15 at 14:22
• @jojek, I have proposed @Matt L. to write answer based on his comment and I will accept it. Another way is edit this answer and add info about magnitude response from comment @Matt L. and add missed SQRT. – Gluttton Mar 4 '15 at 14:48
• @Gluttton i updated answer – Black Yasmin Mar 12 '15 at 9:25