How can I evaluate and plot a Fourier expansion neatly?
1 view (last 30 days)
Show older comments
Hello! I'm trying to rewrite some of my code to make it look "prettier" and easier to manage and read. Currently I manually evaluated 21 coefficients of a complex Fourier expansion, but I'm wondering if there is any easier way to express it and evaluate it to the n'th term as opposed to doing it each time for a negative n value and its pertaining absolute value.
The function I'm trying to expand is C*V.*(1-exp(-x/((R.*C)))) on the interval from 0 to 2. R, C, and V are arbitrary constants defined early in the code, don't really mean anything as long as I can change them to any give value that I want.
Currently, I have this:
C0b=@(x) C*V.*(1-exp(-x/((R.*C)))).*(exp((-1i.*4.*0.*pi.*x)./(R.*C)));
%Integrand for expansion of 0th term The 0 after the -1i is where the n will go.
C0a = integral(C0b,0,2);
%Evaluation of integral of 0th term
C0n= (2/(R*C))*C0a;
%Multiply integral by 2/RC
C0=C0n*exp((4*1i*0*pi*t)/(R*C))
% finish the expansion for the 0th term
Y=C0+rest of terms
%actual Fourier expansion
I have this 21 times (aside for the Y= part) for n values from -10 to 10 and It works perfectly! I'm plotting Y against t ranging from 0 to 20. I just can't seem to get it to work in a for loop for n times. I am getting issues with the integral step. I've tried any help would be greatly appreciated in making this look and operate better! Thank you!
0 Comments
Answers (0)
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!