# Transfer function model to frequency response

I have a problem, I wanted to filter the signal with a Butterworth filter built on the basis of a prototype. I have zeros and poles and an $$H (s)$$ answer, and I do not have the frequency response. How do I get it?

I got transfer function using zp2tf and tf.

% z -> zeros
% p_lp -> poles of designed low pass filter
% k -> amplification
[num, den] = zp2tf(z, p_lp, k)
sys_lp = tf(num, den)


result is:

Transfer function 'sys_lp' from input 'u1' to output ...

1.6e+10
y1:  -----------------------------
s^2 + 1.867e+05 s + 1.742e+10

Continuous-time model.


and the body of filter is shown using

bode(sys_lp);


I tried to filter signal "modulated" by using function filter() but it is not that way. The result is not what it should be.

y_lp = filter(num, den, modulated);


Now I am thinking of get reference of bode values to array and multiply by the spectrum of both signal to get a filtered signal. And this is my question, how do I get a frequency response if I have poles, zeros or transfer function using Matlab or octave to used them later to filter the given signal? Thank you.

Full code:

function [osX, P1] = computeFFT(data, freq)
L = length(data);
% fft
transform = fft(data);
osX = 4;
P1 = 5;
% two-sided spectrum
P2 = abs(transform/L);
osX = freq*(0:(length(P2)/2))/length(P2);
##    % single-sided spectrum
P1 = P2(1:L/2+1);
P1(2:end-1) = 2*P1(2:end-1);
endfunction

N = 16;
M = 6;

m = 1;
% CARRIAGE
fc = (100 + 2 * N) * 1000;
% MODULATE SYGNALS
fm1 = 1 * N * 1000;
fm2 = 1.5 * N * 1000;
fm3 = 3.3 * N * 1000;
% sampling frequency
fs = 100 * fc;
t_common = 0: 1/fs: 2000*(1/fs);
% Amplitude = 1
C = 1;
M = 1;
dcoffset = 0;
OMEGA_C = 2 * pi * fc;

% CARRIAGE
c = sin(OMEGA_C * t_common);
% MODULATED SYGNALS
m1 = sin(2 * pi * fm1 * t_common);
m2 = sin(2 * pi * fm2 * t_common);
m3 = sin(2 * pi * fm3 * t_common);
m = (m1 + m2 + m3) / 3;

[osX_C, P1_C] =  computeFFT(c, fs);
[osX_M, P1_M] =  computeFFT(m, fs);

% MODULATED SIGNAL
modulated = (C + m) .* c;
[osX_AM, P1_AM] =  computeFFT(modulated, fs);

Apass = 0.6;  % dB
Astop = 16;   % dB

Gpass = -0.6;
omega_pass = 1; % lucky shoot?
Gstop = -16;
omega_stop = 5; % lucky shoot?

OMEGA = omega_stop/omega_pass;

top = log10( (10^(-Gstop/10) - 1)  / ( (10^(-Gpass/ 10) -1 ) ));
bottom = 2 * ( log10(OMEGA));
m = top / bottom ;
n = ceil(m)

% poles
p = zeros([1 n]);
for k = 1:n
p(k) = exp( ((i*pi)/(2*n)) * (2 * k + n - 1));
end;

p_lp = zeros([1 n]);
for k = 1:n
p_lp(k) = p(k) * (fs-2000);
end;

z = []; % zeros
k = 1.75*10^14; % amplification
% z -> zeros
% p_lp -> poles of designed low pass filter
% k -> amplification
[num, den] = zp2tf(z, p_lp, k)
sys_lp = tf(num, den)
figure(10)
sys_disc = c2d(sys_lp, 1/fs);
bode(sys_disc);
[numd, dend] = bilinear(num, den, fs);
y_lp = filter(numd, dend, modulated);
[osX_lp, P1_lp] = computeFFT(y_lp, fs);

figure(11)
subplot(3,2,4)
stem(osX_lp(1:30)/1000, P1_lp(1:30), "r");
set(gca, 'FontSize', fontSize)
title('FFT CLOSE ONE', "fontsize", 24)
xlabel('f (kHz)', "fontsize", 24)
ylabel('|P1(f)|', "fontsize", 24)
$$$$
`
• You're working in Continous-time mode... Nov 13 '20 at 19:08
• Yes? I really do not get it. Nov 13 '20 at 19:38
• So I used sys_disc = c2d(sys_lp, 1/fs); bode(sys_disc); and the result is very similar when using filter() it is opposite to what I want to get, when I set magniture to -20dB the signal what I am filtering is amplified 20dB times. Nov 13 '20 at 19:53
• Might be easier to help after you add your full source code into your question. Nov 14 '20 at 11:02
• Instead of filter() you could also use lsim(), which also works with continuous time models. Nov 14 '20 at 12:36