# Output of an LTI System through both Fourier transform and Convolution

1 view (last 30 days)
Abdelrhman Abdelfatah on 24 May 2022
Answered: Chandra on 26 May 2022
I have an LTI System x(t) and h(t), and i want to get the output twice, one time using Convolution, and another time using Fourier Transform to and compare between them, but the output graphs are not very identical, is there any problem in my code below?
clear all; clc
t=-0:0.001:5;
x = (sign(t - 1) - sign(t - 3))/2; % My Input x(t)
h = (exp(-t)); % My Transfere function h(t)
y1=conv(h,x); %Getting Ouput by convolution
y11=fft(y1); % Doing TF of y(t)
x_w=fft(x); % Doing TF of x(t)
h_w=fft(h); % Doing TF of h(t)
y2=x_w.*h_w; % Getting the output s
subplot(4,1,1)
plot(t,x)
subplot(4,1,2)
plot(t,h)
subplot(4,1,3)
plot(y11)
subplot(4,1,4)
plot(y2)
##### 1 CommentShowHide None
Jonas on 24 May 2022
try plotting the abs value of your y11 and y2 to get a clue how and why they are different at the moment. they look more similar than you think right now

Chandra on 26 May 2022
Hi,
add zero padding to the signal before converting to frequency domain because it should match the length of convolution signal.
clear all; clc;close all;
t=-0:0.001:5;
figure,
x = (sign(t - 1) - sign(t - 3))/2; % My Input x(t)
h = (exp(-t)); % My Transfere function h(t)
y1=conv(h,x); %Getting Ouput by convolution
y11=fft(y1); % Doing TF of y(t)
%% sectin that need to change%%
x_w=fft([x zeros(1,length(h)-1)]); % Doing TF of x(t) with padding
h_w=fft([h zeros(1,length(x)-1)]); % Doing TF of h(t) with padding
%% section ends%%
y2=x_w.*h_w; % Getting the output s
subplot(4,1,1)
plot(x) % remove t to avoid conflicts when variable lenght of x and h (or) give appropriate length
subplot(4,1,2)
plot(h)
subplot(4,1,3)
plot((y11))
subplot(4,1,4)
plot((y2))
refer to the link for padding zeros.