All problems
Fourier Square-Wave Coefficient
Problem
For the unit-amplitude square wave on (-pi, pi), the Fourier sine coefficient is b_n = 4 / (n * pi) for odd n and 0 for even n.
Given a positive integer n, return b_n using 3.141592653589793 for pi.
Hint
Only odd harmonics appear because the square wave has half-wave symmetry.
Test cases
case 1
in: [1]
expected: 1.2732395447351628
case 2
in: [2]
expected: 0
case 3
in: [3]
expected: 0.4244131815783876
case 4
in: [5]
expected: 0.25464790894703254
case 5
in: [7]
expected: 0.18189136353359467
Starter codePython
def square_wave_coefficient(n):
# Your code here
pass5 test cases · run your code against them in the editor