低域通過特性を有する梯子型回路の規格化素子値(csvファイルに書き込み)

モジュールのインポート

import numpy as np
import csv

csvファイルへの書き込み方法

csvファイルへの書き込みテストを行うと,
nn = np.arange(1, 8, 1) # 段数
with open('test.csv', mode='w', encoding='utf-8', newline='') as file:
    writer = csv.writer(file)
    writer.writerows([nn]) # 1次元配列を2次元配列値として引数で渡す

ユーザ関数

最平坦特性の低域通過梯子型回路の規格化素子値は,
def element_values_maximally_flat(n): # 最平坦特性の低域通過梯子型回路の規格化素子値
    gg = np.empty(0)
    gg = np.append(gg, 1.0)   
    for k in range(1,n+1):
        th = (2.0*k-1.0)*np.pi/2.0/n
        g = 2.0*np.sin(th)
        gg = np.append(gg, g)
    gg = np.append(gg, 1.0)
    return gg
チェビシェフ特性の低域通過梯子型回路の規格化素子値は,
def element_values_equal_ripple(nn,rwdb): # チェビシェフ特性の低域通過梯子型回路の規格化素子値
    ch = 1.0/np.tanh(rwdb/17.37)
    beta = np.log(ch)
    gamma = np.sinh(beta/2.0/nn)
    gg = np.empty(0)
    gg = np.append(gg, 1.0)
    for i in range(1,nn+1):
        th = (2.0*i-1.0)*np.pi/2.0/nn
        ai = np.sin(th)
        bi = gamma**2+(np.sin(i*np.pi/nn))**2
        if i == 1:
            gi = 2.0*ai/gamma
        else:
            gi = 4.0*aim*ai/bim/gim
        aim = ai
        bim = bi
        gim = gi
        gg = np.append(gg, gi)
    if nn % 2 == 1:
        gn1 = 1.0
    else:
        gn1 = (1.0/np.tanh(beta/4.0))**2
    gg = np.append(gg, gn1)
    return gg

最平坦特性

# nn = np.array([3,5,7])
n = nn.max()
icr = n-2
n, nn
(7, array([1, 2, 3, 4, 5, 6, 7]))
csv_filename = 'element_values_maximally_flat.csv' # maximally flat
print(f'{"N":>2s}',end=' ')
[print(f"{'g':>2s}",f"{j:<2.0f}",end=' ') for j in range(n+2)]
print('')
with open(csv_filename, mode='w', encoding='utf-8', newline='') as file:
    writer = csv.writer(file)
    for n in nn:
        gk = element_values_maximally_flat(n) # 特性関数K(s)=s**n
        print(f'{n:2d}',end=' ')
        [print(f"{gk[j]:5.3f}",end=' ') for j in range(n+2)]
        print('')
        writer.writerows([gk]) # csvファイルへの書き込み
    N  g 0   g 1   g 2   g 3   g 4   g 5   g 6   g 7   g 8  
    1 1.000 2.000 1.000 
    2 1.000 1.414 1.414 1.000 
    3 1.000 1.000 2.000 1.000 1.000 
    4 1.000 0.765 1.848 1.848 0.765 1.000 
    5 1.000 0.618 1.618 2.000 1.618 0.618 1.000 
    6 1.000 0.518 1.414 1.932 1.932 1.414 0.518 1.000 
    7 1.000 0.445 1.247 1.802 2.000 1.802 1.247 0.445 1.000

チェビシェフ特性

rwdb = 0.5 # リプル [dB]
csv_filename = 'element_values_equal_ripple_0_5dB.csv' # equal_ripple
print("RW=",rwdb,"[dB], s11=",-10.0*np.log10(1.0-10.0**(-rwdb/10.0)),"[dB]")
RW= 0.5 [dB], s11= 9.635744808383027 [dB]
print(f'{"N":>2s}',end=' ')
[print(f"{'g':>2s}",f"{j:<2.0f}",end=' ') for j in range(n+2)]
print('')
with open(csv_filename, mode='w', encoding='utf-8', newline='') as file:
    writer = csv.writer(file)
    for n in nn:
        gk = element_values_equal_ripple(n,rwdb)
        print(f'{n:2d}',end=' ')
        [print(f"{gk[j]:5.3f}",end=' ') for j in range(n+2)]
        print('')
        writer.writerows([gk]) # csvファイルへの書き込み
N  g 0   g 1   g 2   g 3   g 4   g 5   g 6   g 7   g 8  
1 1.000 0.699 1.000 
2 1.000 1.403 0.707 1.984 
3 1.000 1.596 1.097 1.596 1.000 
4 1.000 1.670 1.193 2.366 0.842 1.984 
5 1.000 1.706 1.230 2.541 1.230 1.706 1.000 
6 1.000 1.725 1.248 2.606 1.314 2.476 0.870 1.984 
7 1.000 1.737 1.258 2.638 1.344 2.638 1.258 1.737 1.000