    Python.    .
 


      .  ,   ,   Python     .       .

   :           .   DFT  FFT     ,  FFT  .   -  -      .      ,       .   LMS-    .        .           .

 ,    DSP  .  ,      .   ,          -.





    Python.    .





***







 . . , , 2026







    

     .   ,   .         .        ,   .                .   ,          ,              .

   ,   :      .   .    .    ,  ,   ,     ,    .

    :       ,  .                  .          ,        .    .    .

   ,  .  :  ,    .           ,    .

     

      .  ,    .        .  ,               .   ,      , ,  ,     .  .        .            YouTube.

   .  ,       .    .     .  -         -    ,    .   ,   ,   .        .

     .        ,   .      :   ?     ?           ,       .           ,     .    ,    ,    .   ?     ,   ?    ?

   , , ,      .                  .          ,       .    .    .

   

    .    :    ,      ,     ,      ,  .  ,      .

           .     .        ,   ,    -,   .     ,      ,     .

         .  ,          ,     .    -  -,          : , ,  .

         ,     .        .

         ,      ,      .

                 Python.

    .       .       ,     , .   .  ,          .        .     -  .

  

        Python  3.9  .     numpy, scipy, librosa, soundfile, matplotlib      .     ,   .

    Python.   ,   , , ,  for    if.              .  .    .

   .      .    , ,    .  .    ,   .  -          .

  .      ,   .     ,     ,  ,  ,     .         .    .

  , .  ,    .  ,        ,     .    ,    ,  ,   .        .




.     


   

     .     .     : , , , .    -,     -  :  .    ,    ?    ,        ,    ,   ?      ,         ,      ?

       .    .           ,       .       .

    ,       .       ,     .        ,    ,     .         .

    Python  :          .   ,  ,  ,  ,   .     ,     ,       .     .      .

     .  ,   ,   .       .               .

      .   .          ,    ,   .  .     . ,       ,  ,   Python     .    .

   

   ,         .           ,    .   ,           .

   ,      ,      Python.  ,   ,   .     .          .    .

   ,        ,   .         ,    .   ,  - ,     .     ,     ,  ,  .

   ,            ,                .    .   ,        .

     

      .       .    .   , ,  .  ,         .         ,    ,     .   ,    .  ,   ,             .

    .  :  ,  ,    - ,  .   ,   .    .   .             ,      ,    .     ,    ,   .

     .          ,   ,   .          ,      .              .     ,   -           .       ,      .

   

    ,          .         ,   ,     .           .      ,   ,   ,   .   , ,     .

     .          ,     .        ,       ,   .            ,    .         .    ,      .      ,   ,  ,   .       , , ,      .          ,    ,  .         ,     .      ,         .    -   ,       .

         .              ,   .      ,          .

  

         Python.     ,   .     ,        .

     Python.   ,   , , ,  for,   if.             ,     .  .

   .    .    .  ,  .                 .    .      .  ,    .  :   ,     .

   .        .    .  .  . ,  .   ,  -       ,  .       :         .

    

      .        ,  ,   .               .

        .       .    ,        ,    .       :  ,  ,  ,   .     .

         .     Python   . ,   ,          ,    .



  

      .        .       ,       .   ,    ,  ,  ,     .       ,      ,    .

            .  ,        ,      .            ,   .  ,   ,        .

         .         -,      .           .       ,   FFT   .

          .       ,          .     STFT     .

      .  ,      ,      .      :  ,  ,   .        ,      .

        ,     ,     .  ,          .      FFT       .

         ,     .   LMS-         .

       .                    pitch.

        .     :  ,  ,  ,   .      Python.

     

    .       .    ,    ,         .      .

 .    np.sin(2 * np.pi * 440 * t),  880  440.  ? ?     ,     .

  .             .     ,        .

 .   ,      .          ,   .   .

  .       ,     ,   .     .      ,    .

    .     .        ,   .     .        ,      .




   


     .  ,      ,   .  ,        ,   .  ,  ,    ,    .

      .   ,      .             , ,     .   :      ,   ,   ,    .

         ,           .     ,       .          :      .  ,   , .      ,        . , ,           ,    .

   .        .        .    .

.




 1.   : ,   ,   


  ,   ,     ,   

   

          .    ,   ,   Python     .  ,      ,      .  ,     ,  .     :  , ,  ?   ,    ,    , ,     ,      ?   , ,      ,  ?          ?

      .     :       ,             .      ,     :   .  ,     -  44 100 ,      8 000 .    -      ,    ,        .      ,  ,     ,    .

     .    ,        ,      .            ,     ,     .               ,    ,            .

  

    ,  ,   .     .   ,    .     ,      .         ,       .      ,    .            ,         ,     .

  .       ,      .      :        .       ,      ,    .       : ,  ,        .

      .   .   ,          .     :   ,   .   .      .    :     ,   .     ().       .        20  (  )  20 000  (  ).             15 000-16 000 .    .          .            ,      ,   .

        .   ,      ,     .   ,             ,   ,   .   ,  -  .            ,       .

:   

       .    .        .   ,              .    .         ,       .

       .   44 100  ,      44 100   .   44 100,    40 000  50 000?   ,      .  :       ,          ,       .

      20 000 . ,   ,   ,      40 000 .  -  44 100    ,  40 000,   .   44 100,   44 000?    ,       ,     ,      .     25   ,   44 100     .     ,      .

      .      8 000 ,   ,   ,   4 000 .       8 000    ,   ,    ,   .       22 050     CD-.         ,     .

    .                  .

python

import numpy as np

import soundfile as sf

import matplotlib.pyplot as plt

#  

duration = 1.0        #  

freq = 440.0          #  ""  

#        

#   ""   

sr_continuous = 441000  #  10  ,  CD

t_continuous = np.linspace(0, duration, int(sr_continuous * duration), endpoint=False)

y_continuous = np.sin(2 * np.pi * freq * t_continuous)

print(f" : {len(y_continuous)} ")

print(f" : {freq} ")

#      

sample_rates = [8000, 11025, 22050, 44100]

for sr in sample_rates:

#   n-    

step = sr_continuous // sr

y_sampled = y_continuous[::step]

t_sampled = t_continuous[::step]

print(f"\n : {sr} ")

print(f"   : {len(y_sampled)}")

print(f"       {sr / freq:.1f} ")

#   

sf.write(f'sine_{freq}hz_{sr}.wav', y_sampled, sr)

      440       ,  .      ,           CD.     :       n- ,       .    : 8 000  ( ), 11 025  ( CD), 22 050  ( CD)  44 100  ( CD-).

     .    44 100    ,  .   22 050     ,     .   11 025     ,   .   8 000      ,    .  ,        8 000     18 ,   44 100    100.     ,       .

   

       .  :       F,       2F.  ,      ,     ?     ,      .

     .   ,            ,    .    .     24   .      24   ,      ,     .    ,    .            .

    .       ,          .  -   .

python

import numpy as np

import soundfile as sf

def demonstrate_aliasing(signal_freq, sample_rate, duration=1.0):

"""

  .

signal_freq -   

sample_rate -  

"""

nyquist = sample_rate / 2

print(f" : {signal_freq} ")

print(f" : {nyquist} ")

if signal_freq <= nyquist:

print("    <=  .  .")

else:

#   

alias_freq = abs(signal_freq - sample_rate * round(signal_freq / sample_rate))

print(f"    >  !  .")

print(f"    (): {alias_freq:.1f} ")

#     

sr_high = 441000

t = np.linspace(0, duration, int(sr_high * duration), endpoint=False)

y = np.sin(2 * np.pi * signal_freq * t)

# 

step = sr_high // sample_rate

y_sampled = y[::step]

# 

sf.write(f'alias_{signal_freq}hz_at_{sample_rate}.wav', y_sampled, sample_rate)

print(f"   : alias_{signal_freq}hz_at_{sample_rate}.wav\n")

#    

demonstrate_aliasing(signal_freq=5000, sample_rate=44100)   #   

demonstrate_aliasing(signal_freq=25000, sample_rate=44100)  # !

demonstrate_aliasing(signal_freq=40000, sample_rate=44100)  #  

,    .  demonstrate_aliasing      .        .        ,   .        : abs(signal_freq - sample_rate * round(signal_freq / sample_rate)).   ,      .

 :  5 000 ,  44 100 .    22 050 .  ,  .  :  25 000     .     .       19 100 .        25 000 ,     19 100     !  :  40 000 .     4 100       .

    .     ,   .     ,      .     ,      40 000 .    .

  :  

   ?  :           .         .         ,  .      ,       .           ,          .

       ,  ,   .        ,       scipy.

python

from scipy.signal import butter, sosfilt

def anti_alias_filter(y, sr, cutoff=None):

"""

   (  ).

cutoff -  .   =   * 0.9

"""

nyquist = sr / 2

if cutoff is None:

cutoff = nyquist * 0.9  #  

#    8- 

sos = butter(8, cutoff / nyquist, btype='lowpass', output='sos')

y_filtered = sosfilt(sos, y)

return y_filtered

#   

sr_high = 441000

t = np.linspace(0, 1.0, int(sr_high * 1.0), endpoint=False)

#     5000  25000  

y_mixed = np.sin(2 * np.pi * 5000 * t) + 0.5 * np.sin(2 * np.pi * 25000 * t)

#   

step = sr_high // 44100

y_bad = y_mixed[::step]

#   ,  

y_filtered = anti_alias_filter(y_mixed, sr_high, cutoff=20000)

y_good = y_filtered[::step]

sf.write('aliasing_bad.wav', y_bad, 44100)

sf.write('aliasing_good.wav', y_good, 44100)

print(" .  aliasing_bad.wav  aliasing_good.wav")

print("      ~19100    25000 ")

print("    25000     ")

     : 5 000  ()  25 000  (,     44 100 ).         25 000     19 100 .    25 000    ,       5 000 .      .



:     

   :  ,    .     .       ,    .             .               .          .

,     .    175 ,   175,384927... .     .    .        ,       .

  ,       .  8     2  8-  = 256  .  16   65 536 .  24    16  .   ,                    .

     ,   .  16        -96    .  8    .      .

python

def quantize(y, bits):

"""

     .

bits -   (, 8  16)

"""

levels = 2 ** bits

#   -1  1   levels 

y_normalized = y / np.max(np.abs(y))  #    -1..1

y_quantized = np.round(y_normalized * (levels / 2 - 1)) / (levels / 2 - 1)

return y_quantized

#   

import librosa

y, sr = librosa.load('voice_sample.wav', sr=44100)

#    

for bits in [16, 12, 8, 6, 4]:

y_q = quantize(y, bits)

sf.write(f'voice_{bits}bit.wav', y_q, sr)

#   

noise = y - y_q[:len(y)]

noise_power = np.mean(noise ** 2)

signal_power = np.mean(y ** 2)

snr = 10 * np.log10(signal_power / noise_power) if noise_power > 0 else float('inf')

print(f"{bits} :  / = {snr:.1f} ")

print(" .    .")

 . 16        CD-. 12     . 8     ,   . 6     ,  . 4      ,   ,    .

 :  /       :  6    . 16  ? 6 = 96        CD. 24  ? 6 = 144     ,     .   24-       :       ,     ,            .

   

    .  ,       .  ,       .      .

   WAV   44 100 , 16 ,   44 100   ,     2  (16  = 2 ).       5 .    300 .     ,  .   24   16     .

  ,   MP3,   ,        .   ,       ,         .   .   MP3       WAV,     .         ,     MP3   .

 :    

   ,   ,       .       ,       .

python

def resample_audio(y, orig_sr, target_sr):

"""    ."""

duration = len(y) / orig_sr

new_length = int(duration * target_sr)

t_old = np.linspace(0, duration, len(y), endpoint=False)

t_new = np.linspace(0, duration, new_length, endpoint=False)

y_new = np.interp(t_new, t_old, y)

return y_new, target_sr

#   

y, sr = librosa.load('voice_sample.wav', sr=44100)

print(f" : {sr} , {len(y) / sr:.1f} ")

#  

configs = [

{'label': 'CD ', 'target_sr': 44100, 'bits': 16},

{'label': '', 'target_sr': 22050, 'bits': 16},

{'label': '', 'target_sr': 8000, 'bits': 8},

{'label': '', 'target_sr': 8000, 'bits': 4},

{'label': ' ( )', 'target_sr': 8000, 'bits': 16, 'no_filter': True},

]

for cfg in configs:

y_resampled, new_sr = resample_audio(y, sr, cfg['target_sr'])

#        

if not cfg.get('no_filter'):

y_resampled = anti_alias_filter(y_resampled, new_sr)

y_quantized = quantize(y_resampled, cfg['bits'])

filename = f"experiment_{cfg['label'].replace(' ', '_')}.wav"

sf.write(filename, y_quantized, new_sr)

print(f": {cfg['label']} -> {filename}")

print("\n     :")

print("-       ")

print("-      ")

print("-     ")

         .    , CD-.    ,   ,  16 .    , 8 000   8 .    , 8 000    4 .     :      .            .

 :   

     Bell Labs  1920- .          ,              ,      .   1928  Certain Topics in Telegraph Transmission Theory      .

 ,    Bell Labs,  1948     A Mathematical Theory of Communication,        .     -.     ,        ,     ,  .           .

,       ,    .         .    . ,      ,             .

 

    ,   .           .       .                .

     .   .     .      16 .     8-   ,      ,     ,     .

       .   . ,   8-   16-   .  soundfile    WAV   ,      ,     .

            .      : 8 000, 11 025, 16 000, 22 050, 44 100, 48 000, 96 000 .       ,      .   .

    .           ,    lo-fi .         .        ,     ,    .

 

     44 100   16 .      : 22 050 , 16 ; 8 000 , 16 ; 8 000 , 8 .   ,          .   ,           .

  .               .       1  5.         .       ?        .

   ,    1 000  30 000 .     44 100      .  ,    ,  ,    ,     .    ,     .





            .  ,         ,     .             ,   .  ,  ,        ,            .




 2. ,    


   

      ,    .  ,        ,  -         ,   .        :      ?      ,      , ,    ?      ,      ?

      .   ,      ,             .   ,    .     . , ,   .    :             .                  , , , ,  ,    .

       : ,              .            .  ,    ,      ,         .           DFT   ,   Python.    ,   .  ,  ,        ,       .

:    

  ,    ,    .  .   . ,       .            .

  ?      .     .      ,    -.      .       .     ,   -   .     .      .   ,   ,      ,     .

     .   .      ,   .  ,       .    440       ,  .    220     ,  .    880     ,  .        :          ,   ,     .

   .   ,    .    .          -1  1,  -1  1       .       ,              .         .

   .        .      ,    ,     .       ,         ,     ,   .  ,     :       ,    .

        .  ,    .

python

import numpy as np

import soundfile as sf

# 

duration = 2.0          #  

sample_rate = 44100     # CD-

freq = 440.0            #  ""

#    

t = np.linspace(0, duration, int(sample_rate * duration), endpoint=False)

#  

y = np.sin(2 * np.pi * freq * t)

#   

sf.write('sine_440.wav', y, sample_rate)

print(f" :  {freq} ,  {duration} ")

print(f" : {len(y)}")

print(f" :  {np.min(y):.4f}  {np.max(y):.4f}")

         .   ,  .    ,     .    ,       ,   .

 :    

      .        -    .    .    :         .           XIX ,      .

     ,   .  ,      ,  ,        ,   .     ,        .       ,         .     ,    .

     .         . ,  .

python

import numpy as np

import soundfile as sf

duration = 2.0

sample_rate = 44100

t = np.linspace(0, duration, int(sample_rate * duration), endpoint=False)

#    220  ( ""  )

f0 = 220.0

#     

fundamental = np.sin(2 * np.pi * f0 * t)                #  

harmonic_2 = 0.5 * np.sin(2 * np.pi * f0 * 2 * t)      #   ( )

harmonic_3 = 0.33 * np.sin(2 * np.pi * f0 * 3 * t)     #   ( )

harmonic_4 = 0.25 * np.sin(2 * np.pi * f0 * 4 * t)     #  

harmonic_5 = 0.2 * np.sin(2 * np.pi * f0 * 5 * t)      #  

#   

y_complex = fundamental + harmonic_2 + harmonic_3 + harmonic_4 + harmonic_5

#        

sf.write('fundamental_220.wav', fundamental, sample_rate)

sf.write('complex_tone_220.wav', y_complex, sample_rate)

print(" : fundamental_220.wav  complex_tone_220.wav")

print(" .      .")

print("   ,  ,     .")

  .    , , sterile.       , ,  .      .   :     .   ,       .      ,       .

:     

              ,   ,     .   ,     ,     .      ,    ,        .       .

   ,  ,      .       ,      .    440        440    .   ,     ,       220, 440, 660, 880  1100 ,   .

      .    .    ,       50  (  ),     ( ),   ( ,    ).   ,                 .   ,   ,      .

      ?      .        .

  :  

  ,  DFT,   ,     N ,    ,     N  ,    .           :      -   - .

 DFT  ?     . ,    ,      100 .      100 ,        .     100 ,     ,        .  100          ,    ,   ,       .      ,        .

 DFT  .    k  :

X[k] =   n  0  N-1  x[n]   e    j   2?   k   n,   N.

   .           .  ,         .

 :  

  DFT    j  .   ,     .       - .        .

    .      .      ,   .     ,  .      :   .         .      .       . ,      ,   .

       e    j   2?   k   n,   N,    .         .     k.  k=0    .  k=1       N .  k=2   .   .      ,  ,        .       ,    ,   ,      .      ,      .




  .


   .

   ,     (https://www.litres.ru/book/aleksandr-ivanov-339/cifrovaya-obrabotka-signalov-na-python-ot-inzhenera-k-74004728/)  .

      Visa, MasterCard, Maestro,    ,   ,     ,  PayPal, WebMoney, ., QIWI ,       .


