# Frequency response of discrete PT1 in MATLAB

I want to calculate the frequency response of a discrete PT1 system with T=T1 and K=1. (the code is at the bottom of the question) To validate the magnitude response, I want to use an sinusoidal input signal with linearly increasing frequency from 0 to fs/2. The magnitude response should be the envelope of the transient response. However, this is only the case if I change the line

u = sin(2*pi*f.*t);

to

u = sin(pi*f.*t);

Why? I assume that I have any kind of faulty reasoning here, but I can't find it.

Full code:

clear

%% Input (linear frequency sweep)
Ts = .1e-3;
duration = 30;
t = (0:Ts:duration);
fs = 1/Ts;
f = (fs/2)*t/duration;
u = sin(2*pi*f.*t);

%% PT1-system continuous
T1 = 1e-3;
G = tf(1,[T1 1]);

%% PT1 discretized
H = c2d(G,Ts,'zoh');

%% PT1 trasient response
x0 = 0;
x = lsim(H,u,[],x0,'zoh');

%% PT1 freq. response
[h,~] = freqz(H.Numerator{1:end},H.Denominator{1:end},f,fs);

%% Plot
figure(1),clf(1),hold on
plot(u),plot(x),plot(abs(h))


Found the error by myself now.

I did not use the instantaneous frequency for the calculation of the sweep signal, as stated here or here.

The corrected code is:

clear

%% Input (linear frequency sweep)
Ts = .1e-3;
duration = 30;
t = (0:Ts:duration);
fs = 1/Ts;
f = (fs/2)*t/duration;
finst = 1/2*(fs/2)/duration*t;
u = sin(2*pi*finst.*t);

%% PT1-system continuous
T1 = 1e-3;
G = tf(1,[T1 1]);

%% PT1 discretized
H = c2d(G,Ts,'zoh');
x0 = 0;

%% PT1 trasient response
x = lsim(H,u,[],x0,'zoh');

%% PT1 freq. response
[h,~] = freqz(H.Numerator{1:end},H.Denominator{1:end},f,fs);

%% Plot
figure(1),clf(1),hold on
plot(u),plot(x),plot(abs(h))