The next day scientific computing -----

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/qq_37083038/article/details/102763917

import scipy.signal as signal
import pylab as pl
import numpy as np

B, A = signal.iirdesign ([0.2,0.5], [0.1,0.6], 2,40)
W, H = signal.freqz (B, A)
Power * = 20 is np.log10 (np.clip (NP. abs (h), 1e-8,1e100 )) # h clipping the amplitude is almost 0 dB measured using
pl.plot (w / np.pi * 4000, power)

t = np.arange (0,2,1 / 8000.0) # 2s clock, sampling time array 8KHz sampling time
sweep = signal.chirp (t, f0 = 0, t1 = 2, f1 = 4000.0) # scan waveform
pl .figure (2)
pl.plot (T, * 20 is np.log10 (Sweep))

out = signal.lfilter (b, a, sweep) from the result of the scanning frequency bandpass filter #
out = 20 * np.log10 (np.abs ( out)) # is converted to dB
# obtain an output waveform envelope
# find all energy is greater than two sampling points (local maximum point) before and after a small scale, out you must be an array
index = np.where (np.logical_and (out [ 1: -1]> out [: - 2], out [ . 1: -1]> OUT [2:])) [0] + 1'd
pl.figure (. 3)
pl.plot (T [index] /2.0*4000,out [index]) # converts a frequency corresponding to time , drawing all the local maximum point of energy value

'' '
Passband of the filter is to 0.2f0 0.5f0, 0.1f0 stopband less than and greater than 0.6f0, bandpass maximum gain attenuation 2dB, stop-band
minimum gain is 40dB attenuation
F0 is half the sampling frequency of the signal
b iir filter coefficients molecular
denominator coefficients of a filter iir, a [0] is a constant

freqz (b, a) values calculated by the filter frequency response
w is the frequency of the original array, corresponding to the actual frequency F0 * w / PI, F0 = FS / 2
H point corresponding frequency response w, h is a complex, which represents the magnitude of the gain characteristic, phase angle indicates the phase characteristic of the filter

function clip, the second parameter is a minimum value, the third parameter is the maximum value of
elements in the array were read minimum value less than the minimum, to a maximum value were greater than the maximum.

chirp function, the first parameter is the sampling time, the second parameter is the frequency sweep start frequency f0 wave, the fourth parameter is the
end frequency f1, the third parameter is the time of f1 to f0.
Note: You need to learn chirp signal

lfilter function calculation result of the waveform by the filter
'' '

Guess you like

Origin blog.csdn.net/qq_37083038/article/details/102763917