Please help with creating the code as follows: Task 2(a): Implement the FFT algorithm using the above pseudocode as the function FFT(). Notethat we have introduced a sign parameter in the FFT pseudocode to specify the sign of the exponent in ωn.If sign is 1, ωn = e2πi/n. If sign is -1, ωn = e−2πi/n.Task 2(b): Then implement the inverse FFT as the function IFFT() that calls the FFT function youwrote with the appropriate inputs, and then normalizes the output by n. Example Task 2(a): Fast Fourier Transform   FFT <input_file.txt> <output_file.txt>where input_file.txt contains the coefficients of the polynomial, this query should read thenumbers from input_file.txt, compute the FFT, and output the result to output_file.txt.Note: This FFT query has the same name as the FFT function in the pseudocode. It should beclear from the context which one we are referring to.Example 1:task2a_input1.txt1.0002.0003.000FFT task2a_input1.txt task2a_output1.txttask2a_output1.txt6.000 0.000-2.000 2.0002.000 0.000-2.000 -2.000Note: The FFT algorithm expects the number of coefficients to be a power of 2. The output ofFFT will be a vector with n_effective components (where n_effective is a power of 2 thatdepends on the number of coefficients in the input). As the FFT algorithm expects n to be apower of 2, if necessary add ‘zero padding’ to the input so that the higher order coefficients arezero and n_effective becomes a power of 2. In the above example, the input contains threenumbers so pad it with one zero to make n_effective = 4, the next power of 2. Similarly, If theinput had five numbers, three zeroes have to be added to make n_effective = 8, the next powerof 2.Example 2:task2a_input2.txt1.0002.0003.0002.0004.000FFT task2a_input2.txt task2a_output2.txttask2a_output2.txt 12.000 0.000-3.000 5.8282.000 0.000-3.000 -0.1724.000 0.000-3.000 0.1722.000 0.000-3.000 -5.828 Example Task 2(b): Inverse Fast Fourier Transform IFFT <input_file.txt> <output_file.txt>where input_file.txt contains a vector of (possibly complex) numbers, this query should read thenumbers from input_file.txt, compute the IFFT, and output the result to output_file.txt.Example:task2b_input.txt2.000 2.0003.000 -1.0001.000 -2.000IFFT task2b_input.txt task2b_output.txttask2b_output.txt-1.5000 -0.2500.000 0.2500.000 0.2500.500 1.750Note: The output of IFFT will be a vector of numbers, and the number of elements depends onthe length of the input. IFFT runs using the FFT algorithm. As the FFT algorithm expects n to bea power of 2, add ‘zero padding’ to the input so that n effectively becomes a power of 2. In theabove example, the input contains three numbers so pad it with one zero to make n_effective=4, the next power of 2. Similarly, If the input had five numbers, three zeroes have to be added tomake n_effective= 8, the next power of 2.

icon
Related questions
Question

Please help with creating the code as follows:

Task 2(a): Implement the FFT algorithm using the above pseudocode as the function FFT(). Note
that we have introduced a sign parameter in the FFT pseudocode to specify the sign of the exponent in ωn.
If sign is 1, ωn = e2πi/n. If sign is -1, ωn = e−2πi/n.
Task 2(b): Then implement the inverse FFT as the function IFFT() that calls the FFT function you
wrote with the appropriate inputs, and then normalizes the output by n.

Example Task 2(a): Fast Fourier Transform
 
FFT <input_file.txt> <output_file.txt>
where input_file.txt contains the coefficients of the polynomial, this query should read the
numbers from input_file.txt, compute the FFT, and output the result to output_file.txt.
Note: This FFT query has the same name as the FFT function in the pseudocode. It should be
clear from the context which one we are referring to.
Example 1:
task2a_input1.txt
1.000
2.000
3.000
FFT task2a_input1.txt task2a_output1.txt
task2a_output1.txt
6.000 0.000
-2.000 2.000
2.000 0.000
-2.000 -2.000
Note: The FFT algorithm expects the number of coefficients to be a power of 2. The output of
FFT will be a vector with n_effective components (where n_effective is a power of 2 that
depends on the number of coefficients in the input). As the FFT algorithm expects n to be a
power of 2, if necessary add ‘zero padding’ to the input so that the higher order coefficients are
zero and n_effective becomes a power of 2. In the above example, the input contains three
numbers so pad it with one zero to make n_effective = 4, the next power of 2. Similarly, If the
input had five numbers, three zeroes have to be added to make n_effective = 8, the next power
of 2.
Example 2:
task2a_input2.txt
1.000
2.000
3.000
2.000
4.000
FFT task2a_input2.txt task2a_output2.txt
task2a_output2.txt
12.000 0.000
-3.000 5.828
2.000 0.000
-3.000 -0.172
4.000 0.000
-3.000 0.172
2.000 0.000
-3.000 -5.828

Example Task 2(b): Inverse Fast Fourier Transform

IFFT <input_file.txt> <output_file.txt>
where input_file.txt contains a vector of (possibly complex) numbers, this query should read the
numbers from input_file.txt, compute the IFFT, and output the result to output_file.txt.
Example:
task2b_input.txt
2.000 2.000
3.000 -1.000
1.000 -2.000
IFFT task2b_input.txt task2b_output.txt
task2b_output.txt
-1.5000 -0.250
0.000 0.250
0.000 0.250
0.500 1.750
Note: The output of IFFT will be a vector of numbers, and the number of elements depends on
the length of the input. IFFT runs using the FFT algorithm. As the FFT algorithm expects n to be
a power of 2, add ‘zero padding’ to the input so that n effectively becomes a power of 2. In the
above example, the input contains three numbers so pad it with one zero to make n_effective=
4, the next power of 2. Similarly, If the input had five numbers, three zeroes have to be added to
make n_effective= 8, the next power of 2.
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer