MATLAB script assistance, please! I'm trying to graph a function based on its Fourier series coefficients. I'm able to successfully calculate and graph every coeffecient, but when I try to combine the coeff's to graph the actual function, see line ~20 where I create "f", it doesn't work and hits me with an error no matter what I try. Can someone fix that part of my script and explain why/how? Thank you!!!   syms t n T=6; w0=2*pi/T; n=-5:5;   a0 = (1/T)*int(t,t,0,1) +((1/T)*int(1,t,1,3) )+((1/T)*int(((-1*(t-3))+1),t,3,4))   an = (2/T)*int(t*cos(n*w0*t),t,0,1) +((2/T)*int(1*cos(n*w0*t),t,1,3) )+((2/T)*int(((-1*(t-3))+1)*cos(n*w0*t),t,3,4))   bn = (2/T)*int(t*sin(n*w0*t),t,0,1) +((2/T)*int(1*sin(n*w0*t),t,1,3) )+((2/T)*int(((-1*(t-3))+1)*sin(n*w0*t),t,3,4))   Cn = sqrt((an.^2)+(bn.^2)) %Cn calculated using an's and bn's   Dn = abs(Cn)/2 % as given by the formula sheet. Cn=2|Dn| abs_Cn = abs(Cn) % Magnitude of the coefficients angle_Cn = angle(Cn) % Phase angle of the coefficients abs_Dn = abs(Dn); % Magnitude of the coefficients angle_Dn = angle(Dn) % Phase angle of the coefficients   f=a0+(an*cos(n*w0*t))+(bn*sin(n*w0*t));   %subplot(5, 1, 1); plot(n, f); xlabel('t'); ylabel('f(t)'); title('c');     % Plot the Fourier spectra (magnitude and phase) subplot(5, 1, 2); stem(n, abs_Cn); xlabel('n'); ylabel('|Cn|'); title('Fourier Spectra (Magnitude)'); grid on;   subplot(5, 1, 3); stem(n, angle_Cn); xlabel('n'); ylabel('Phase C (rad)'); title('Fourier Spectra (Phase)'); grid on;   % Plot the exponential Fourier spectra (magnitude and phase) subplot(5, 1, 4); stem(n, abs_Dn); xlabel('n'); ylabel('|Dn|'); title('Exponential Fourier Spectra (Magnitude)'); grid on;   subplot(5, 1, 5); stem(n, angle_Dn); xlabel('n'); ylabel('Phase D (rad)'); title('Exponential Fourier Spectra (Phase)'); grid on;

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
MATLAB script assistance, please! I'm trying to graph a function based on its Fourier series coefficients. I'm able to successfully calculate and graph every coeffecient, but when I try to combine the coeff's to graph the actual function, see line ~20 where I create "f", it doesn't work and hits me with an error no matter what I try. Can someone fix that part of my script and explain why/how? Thank you!!!
 
syms t n
T=6;
w0=2*pi/T;
n=-5:5;
 
a0 = (1/T)*int(t,t,0,1) +((1/T)*int(1,t,1,3) )+((1/T)*int(((-1*(t-3))+1),t,3,4))
 
an = (2/T)*int(t*cos(n*w0*t),t,0,1) +((2/T)*int(1*cos(n*w0*t),t,1,3) )+((2/T)*int(((-1*(t-3))+1)*cos(n*w0*t),t,3,4))
 
bn = (2/T)*int(t*sin(n*w0*t),t,0,1) +((2/T)*int(1*sin(n*w0*t),t,1,3) )+((2/T)*int(((-1*(t-3))+1)*sin(n*w0*t),t,3,4))
 
Cn = sqrt((an.^2)+(bn.^2)) %Cn calculated using an's and bn's
 
Dn = abs(Cn)/2 % as given by the formula sheet. Cn=2|Dn|
abs_Cn = abs(Cn) % Magnitude of the coefficients
angle_Cn = angle(Cn) % Phase angle of the coefficients
abs_Dn = abs(Dn); % Magnitude of the coefficients
angle_Dn = angle(Dn) % Phase angle of the coefficients
 
f=a0+(an*cos(n*w0*t))+(bn*sin(n*w0*t));
 
%subplot(5, 1, 1); plot(n, f); xlabel('t');
ylabel('f(t)'); title('c');
 
 
% Plot the Fourier spectra (magnitude and phase)
subplot(5, 1, 2);
stem(n, abs_Cn);
xlabel('n');
ylabel('|Cn|');
title('Fourier Spectra (Magnitude)');
grid on;
 
subplot(5, 1, 3);
stem(n, angle_Cn);
xlabel('n');
ylabel('Phase C (rad)');
title('Fourier Spectra (Phase)');
grid on;
 
% Plot the exponential Fourier spectra (magnitude and phase)
subplot(5, 1, 4);
stem(n, abs_Dn);
xlabel('n');
ylabel('|Dn|');
title('Exponential Fourier Spectra (Magnitude)');
grid on;
 
subplot(5, 1, 5);
stem(n, angle_Dn);
xlabel('n');
ylabel('Phase D (rad)');
title('Exponential Fourier Spectra (Phase)');
grid on;
Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Disjoint Set forest
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education