Question: Why is my input and output waveform not same? One is from matlab using Fourier series approximation for input, one is from multisim using resistor

Why is my input and output waveform not same? One is from matlab using Fourier series approximation for input, one is from multisim using resistor and capacitor as low pass. Is my matlab coding wrong? Or is my multisim wrong? Below shows my matlab coding. Please teach me. Thank you. Below is my matlab coding:
f0=1000e3; % Fundamental frequency (Hz)
T0=1/ f0; % Fundamental period
omega0=2* pi * f0; % Angular frequency
fc =480e3; % Cutoff frequency of the low-pass filter (Hz)
%Number of periods I want, so that i can easily manage the x-axis here,
%make it show more periods or less periods
N_T0=2;
%Frequency domain display limit
Freq_x_axis =10e6;
% Time vector, x-axis, for time domain
t =-N_T0*T0 : 1e-9 : N_T0*T0;
DC_Component =1/2;
AC_Component = zeros(size(t));
for n =1:2:100
bn =2/(n * pi);
AC_Component = AC_Component + bn * sin(n * omega0* t);
end
x_t = DC_Component + AC_Component;
% Compute the Frequency Domain, X(w)
%Building a new axis, for frequency
N = length(t); % Number of samples
%t(2) means 2nd element of the array
Fs =1/(t(2)- t(1)); % Sampling frequency
%The new x-axis array/vector is
f =(-N/2: (N/2)-1)*(Fs / N);
%Get the input into frequency domain
X_f = fft(x_t);
%Shift the DC component to the center
X_f = fftshift(X_f);
%Normalize the X_f
X_f = X_f / N;
%The magnitude of Low Pass Filter Transfer function, in frequency domain
H_f_mag =1./ sqrt(1+(f / fc).^2);
%Calculate the output, filtered, in frequency domain or apply the filter to the frequency domain representation of x(t)
Y_f = H_f_mag .*(X_f); %not abs(x_f), cuz 20khz should show about same graph
%Convert the output to the time domain
%By doing inverse fourier transform
y_t = ifft(ifftshift(Y_f))* N;
%---------------------------------------------------------------------------
%--All plots put together here to easily manage and modify all the plots---
%---------------------------------------------------------------------------
figure;
%Input, in the Time Domain
%input of filter
plot(t, x_t,'k', 'LineWidth', 1.5);
hold on
%output of filter
plot(t, abs(y_t),'b', 'LineWidth', 1.5);
title('Fourier Series Approximation of input (Time Domain)');
xlabel('Time (s)');
ylabel('Amplitude');
% Set y-axis limits
clear ylim %need this clear ylim or it bugged one, can't work as expected
ylim([-0.51.25]);
figure;
%Input, in the Time Domain
subplot(3,2,1);
%input of filter
plot(t, x_t,'k', 'LineWidth', 1.5);
hold on
%output of filter
plot(t, abs(y_t),'b', 'LineWidth', 1.5);
title('Fourier Series Approximation of input (Time Domain)');
xlabel('Time (s)');
ylabel('Amplitude');
% Set y-axis limits
clear ylim %need this clear ylim or it bugged one, can't work as expected
ylim([-0.51.25]);
%Frequency domain, use the f as x axis
%Input, in the Frequency Domain
subplot(3,2,2);
plot(f, abs(X_f),'k', 'LineWidth', 1.5);
%Since making the x-axis has label kHz, then the x-axis need to be divided
%by 1k, but don't do this, because matlab there auto shows 10e5 something,
%then gets very messy!!!
title('Fourier Series Approximation of magnitude of input (Frequency Domain)');
xlabel('Frequency (Hz)');
ylabel('|X(f)|');
xlim([-Freq_x_axis Freq_x_axis]);
%ylim([-1010]);
grid on;
%H(f), Low Pass Transfer function, in Frequency Domain
%Compared to that sketched by desmos, the points, this is confirmed correct
subplot(3,2,4);
plot(f, H_f_mag, 'k', 'LineWidth', 1.5);
title('|H(f)|(Frequency Domain)');
xlabel('Frequency (Hz)');
ylabel('Amplitude');
xlim([-Freq_x_axis Freq_x_axis]);
grid on;
%Filtered Signal in, Time Domain
subplot(3,2,5);
plot(t, abs(y_t),'k', 'LineWidth', 1.5);
title('Filtered Signal (Time Domain)');
xlabel('Time (s)');
ylabel('Amplitude');
clear ylim
ylim([-0.51.25]);
%Filtered Signal in, Frequency Domain
subplot(3,2,6);
plot(f, abs(Y_f),'k', 'LineWidth', 1.5); % Time-domain plot of filtered signal
title('Filtered Signal (Frequency Domain)');
xlabel('Frequency (Hz)');
ylabel('Amplitude');
xlim([-Freq_x_axis Freq_x_axis]);
%clear ylim
ylim=([011.5]);
Why is my input and output waveform not same? One

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Electrical Engineering Questions!