<a href="https://colab.research.google.com/github/alirezash97/Time-frequency-analysis-course/blob/main/TayPaper/Tay2005.ipynb" target="_parent"></a>


```
import math
import numpy as np
import matplotlib.pyplot as plt
import sympy as sym
from sympy import *

```


```

def K(x):

   
   
  output = []
  for i in range(int((filter_length-1)/2)):
     
    combination_statement =  math.factorial(filter_length) / (math.factorial(i) * math.factorial(filter_length-i))
    second_statement = np.multiply( np.power(x, i), np.power( (1-x), filter_length-i ))
    final_statement = np.multiply(combination_statement, second_statement)
    output.append(final_statement)
  
  return np.sum(output)

 ######################################

```


```

def kl(x, l):


  combination_statement =  math.factorial(filter_length) / (math.factorial(l) * math.factorial(filter_length-l))
  second_statement = np.multiply(np.power(x, l), np.power((1-x), (filter_length-l))) 
  tirth_statement = np.multiply( np.power(x, (filter_length-l)), np.power((1-x), l))
  final_statement = np.multiply(combination_statement, (second_statement - tirth_statement))

  return final_statement

  #####################################

```


```
def B(x, alpha_list):


  sigma = []
  for l in range( Vanishing_moments, int((filter_length-1)/2) ):
    sigma.append(np.multiply( kl(x, l), alpha_list[l]))
  final_equation = K(x) - np.sum(sigma)
  
  return final_equation
```


```
def main_function():
  
  
  # inputs
  global filter_length 
  global Vanishing_moments
  filter_length = int(input("Please enter filter length: "))
  Vanishing_moments = int(input("Please enter the number of vanishing moments: "))
  while int(((filter_length-1)/2-Vanishing_moments)) %2 != 0:
    Vanishing_moments = int(input("Please enter another number for vanishing moments: "))
  else:
    pass
  
  global number_of_pin
  number_of_pin = int(1/2*((filter_length - 1) /2-Vanishing_moments))
  print("You have to choose %d"%number_of_pin, "pins")
  global zero_pinning
  zero_pinning = []
  for i in range(number_of_pin):
    temp = float(input("Enter %dth pin: " %(i+1)))
    zero_pinning.append(temp)
    #############

  # create symbols
  global alpha_list
  alpha_list = []
  for i in range(1, filter_length+1):
    alpha_list.append(sym.symbols('alpha%d'%i))

  global x_list
  x_list = []
  for i in range(len(zero_pinning)):
    x_list.append(sym.symbols('x%d'%i))
  #############

  # create equations
  global my_equations
  my_equations = []
  for i in range(len(x_list)):

    Eq1 = sym.Eq(B(x_list[i], alpha_list), 0)
    my_equations.append(Eq1)

    Eq2 = sym.Eq(diff(B(x_list[i], alpha_list), x_list[i]))
    my_equations.append(Eq2)
  ##############

  # replace x with zero pinning values
  global replaced_equations
  replaced_equations = []
  for i, equation in enumerate(my_equations):
    replaced = equation.subs(x_list[math.floor(i/2)], zero_pinning[math.floor(i/2)])
    replaced_equations.append(replaced)
  ###############

  # find alphas using equations
  global alpha_results
  alpha_results = solve([i for i in replaced_equations], [j for j in alpha_list[Vanishing_moments : int((filter_length-1)/2)]])
  ###############


  # plot 
  my_array = []
  for key in alpha_results:
    my_array.append(alpha_results[key])
  alpha_values = np.zeros((len(alpha_list)))
  alpha_values[Vanishing_moments : int((filter_length-1)/2)] = my_array
  x = np.linspace(0, 1, num=100)
  fx = []
  for i in range(len(x)):
    fx.append(B(x[i], alpha_values))
  plt.plot(x, fx)


  return alpha_values, alpha_results



```


```
alphas_list, alpha_results = main_function()
print(alpha_results)
```


```
alphas_list, alpha_results = main_function()
print(alpha_results)
```


```
alphas_list, alpha_results = main_function()
print(alpha_results)
```


```
# spectoral factorization
z = sym.symbols('z')
spectoral_factorization = np.multiply(-1/4*z, np.power((1-np.power(z, -1)), 2))
based_on_z = B(spectoral_factorization, alphas_list)
print(based_on_z)
```

    -0.000663369854565131*z**9*(1 - 1/z)**18*(0.25*z*(1 - 1/z)**2 + 1)**3 - 0.00613771873923674*z**8*(1 - 1/z)**16*(0.25*z*(1 - 1/z)**2 + 1)**4 + 3.5048497472446*z**4*(1 - 1/z)**8*(0.25*z*(1 - 1/z)**2 + 1)**8 - 0.720337075701222*z**3*(1 - 1/z)**6*(0.25*z*(1 - 1/z)**2 + 1)**9 + 4.125*z**2*(1 - 1/z)**4*(0.25*z*(1 - 1/z)**2 + 1)**10 - 3.0*z*(1 - 1/z)**2*(0.25*z*(1 - 1/z)**2 + 1)**11 + 1.0*(0.25*z*(1 - 1/z)**2 + 1)**12



```

```

3a4427b9d6ba658cb6a00491bb64f4d87a977e89
ipynb
Jupyter Notebook
TayPaper/Tay2005.ipynb
alirezash97/Time-frequency-analysis-course
9e326ba32a43d411a338e68611ef5e8e75b78fa3
MIT
TayPaper/Tay2005.ipynb
alirezash97/Time-frequency-analysis-course
9e326ba32a43d411a338e68611ef5e8e75b78fa3
MIT
TayPaper/Tay2005.ipynb
alirezash97/Time-frequency-analysis-course
9e326ba32a43d411a338e68611ef5e8e75b78fa3
MIT
Qwen/Qwen-72B
1. YES
2. YES