Question: I've the following matlab code written by myself, in the course of Signal and Systems Fourier Series. How to get the input x ( t

I've the following matlab code written by myself, in the course of Signal and Systems Fourier Series. How to get the input x(t), in frequency domain with the theory of coefficients of fourier series being the frequency domain, (Don't use fourier transform to obtain the frequency domain because there are two methods to get frequency domain right?). And obtain the low pass filter's output in frequency domain, Y(f) by using theory of output_coefficient = c_k * H(k*0), where c_k is the coefficient of input signal. And then get the output in time domain, Y(t) back by using inverse fourier transform (y(t)=[c_k * H(k*0)]* e^(j*k*0*t))? Use MATBLAB. Will upvote if give good answer, and vice versa. Thank you.
%-----------------------Defining all the parameters------------------------
% Parameters
f0=20e3; % Fundamental frequency (Hz)
T0=1/ f0;
%How to convert to fundamental angular frequency (rad/s)?
omega0=2* pi * f0;
%Define the x-axis,
t =-2*T0 : 1e-6 : 2*T0; % Time vector for 5 periods
%The dc component was obtained from manual solution
DC_Component =1/2;
%----------Computing the input,in time domain, x(t) and its plot-----------
% Initialize the signal
AC_Component_5= zeros(size(t));
AC_Component_10= zeros(size(t));
AC_Component_20= zeros(size(t));
%Since n =1,3,5,7,...(Odd Harmonics) until the number of harmonics wanted
%Therefore, Loop from 1 to X, with increment of 2 has syntax as shown
for n =1:2:50
%5 harmonics
if n <=5
%The equation below was copied directly from manual solution
bn =2/(n * pi);
AC_Component_5= AC_Component_5+ bn * sin(n * omega0* t);
end
if n <=10
bn =2/(n * pi);
AC_Component_10= AC_Component_10+ bn * sin(n * omega0* t);
end
if n <=20
bn =2/(n * pi);
AC_Component_20= AC_Component_20+ bn * sin(n * omega0* t);
end
end
% Add the DC component here, because DC component is constant, and don't
% need to be looped! Only the AC component is looped
x_t_5= DC_Component + AC_Component_5;
x_t_10= DC_Component + AC_Component_10;
x_t_20= DC_Component + AC_Component_20;
figure; %This "figure" use only once, so that all subplots appear in 1 fugure
subplot(3,1,1)
%How to let the line to be black, and line width to be 1.5?
%so that it is beautiful?
plot(t, x_t_5,'k', 'LineWidth', 1.5);
title('x(t)');
xlabel('Time (s)');
ylabel('Amplitude');
%Since I want to show the y axis from -1.25 to 1.25, then following
%syntax is used, because I want y=0 to be at center exactly like
%the question given, it's put here behind of each subplot or it
%won't work!
ylim([-1.251.25]);
subplot(3,1,2)
plot(t, x_t_10,'k', 'LineWidth', 1.5);
title('Fourier Series Approximation of x(t)');
xlabel('Time (s)');
ylabel('Amplitude');
ylim([-1.251.25]);
subplot(3,1,3)
plot(t, x_t_20,'k', 'LineWidth', 1.5);
title('Fourier Series Approximation of x(t)');
xlabel('Time (s)');
ylabel('Amplitude');
ylim([-1.251.25]);
%--------Plotting the input, in frequency domain, X(w) and its plot--------
%--------Plotting the Low Pass Filter's Frequency Response Curve----------
% The Cutoff frequency given, in Hz
fc =480e3;
f =0: 10e3 : 1200e3; %This really need to trial and error to get the smooth curve
%Inputting the transfer function derived manually,
%Input log10 instead of log10, it produces different result
%Define the Low-Pass Filter Transfer function derived from my manual method
%Magnitude only
H_f_magitude =1./ sqrt(1+(f / fc).^2);
%Conver to gain (dB)
gain =20*log10(H_f_magitude);
%Start another figure
figure;
%I want the x-axis to have unit of scale of kHz, so I make all the f to be
%devided by 1000, or "1e3"
%Since I want the curve to be black colour, black is "k"
plot(f/1e3, gain,'k', 'LineWidth', 1.5);
title('Frequency Response Curve of Low Pass Filter');
%This curve is actually a hard fact, every f_c gives different curve!
%But just depend on where is my f_0
%f_c only, just plotting the transfer function only
xlabel('Frequency (kHz)');
ylabel('Gain (dB)');
%Make the axis show from 0 to 600 khz only
xlim([0600]);
grid on;
%Since the fc should give a gain of -3 dB theoretically
%To verify this, fc and -3dB line was plotted
%Dashed line, so use --, solid line, use -, followed by the code of colour
%Want the label alligned vertically (90 degree rotated)? then put
%'LabelVerticalAlignment' at behind,
%Plot my f_c line
xline(fc /1e3,'--b', 'Cutoff Frequency (f_c)', 'LabelVerticalAlignment', 'bottom');
%Plot my f_0 line
xline(20,'--b', 'Input Frequency (f_0)', 'LabelVerticalAlignment', 'top');
%Plot the -3 dB horizontal line
yline(-3,'--b','-3 dB', 'LabelHorizontalAlignment' ,'center');
%-------------------Computing the output and its plot----------------------

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!