Cody

Problem 45480. Find the Fourier coefficients of a periodic function

Solution 3085061

Submitted on 6 Oct 2020
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test Status Code Input and Output
1   Fail
T = 2; Ts = 0.01; t = 0:Ts:T-Ts; A = 2; f = zeros(size(t)); f(t < (T/2)) = A; f((t>=(T/2)) & (t<T)) = -A; N = 10; coeffs_correct =[0 0.04 0 0.04 0 0.04 0 0.04 0 0.04 0;0 2.546 0 0.848 0 0.508 0 0.362 0 0.281 0]; assert(any(any(abs(fourier_series(f,N,T,Ts,'real')-coeffs_correct)<1e-3)))

Undefined function 'lengh' for input arguments of type 'double'. Error in fourier_series (line 3) t = 0:lengh(f); Error in Test1 (line 10) assert(any(any(abs(fourier_series(f,N,T,Ts,'real')-coeffs_correct)<1e-3)))

2   Fail
T = 1; Ts = 0.01; t = 0:Ts:T-Ts; N = 10; f = sin(2*pi*2*t) - 3*sin(2*pi*3*t) + 2*cos(2*pi*4*t); coeffs_correct = [0 0 2 0 0-3i 0 0+1i 0 0 0 0 0 0 0 0-1i 0 0+3i 0 2 0 0]; assert(any(any(abs(fourier_series(f,N,T,Ts,'complex')-coeffs_correct)<1e-3)))

Undefined function 'lengh' for input arguments of type 'double'. Error in fourier_series (line 3) t = 0:lengh(f); Error in Test2 (line 7) assert(any(any(abs(fourier_series(f,N,T,Ts,'complex')-coeffs_correct)<1e-3)))

Suggested Problems

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!