东方耀AI技术分享

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
热搜: 活动 交友 discuz
查看: 1171|回复: 1
打印 上一主题 下一主题

[Python] scipy中signal模块之IIR滤波器(低通)的使用

[复制链接]

1365

主题

1856

帖子

1万

积分

管理员

Rank: 10Rank: 10Rank: 10

积分
14439
QQ
跳转到指定楼层
楼主
发表于 2021-9-27 15:18:50 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式





scipy中signal模块之IIR滤波器(低通)的使用


  1. # -*- coding: utf-8 -*-
  2. __author__ = u'东方耀 微信:dfy_88888'
  3. __date__ = '2021/9/17 上午11:41'
  4. __product__ = 'PyCharm'
  5. __filename__ = '00_重新理解一下复信号'


  6. from scipy.fftpack import fft, ifft, fftshift
  7. import numpy as np
  8. from scipy import signal
  9. import random
  10. import matplotlib.pyplot as plt
  11. import matplotlib.ticker as mticker
  12. from matplotlib.font_manager import FontProperties

  13. font_fname = "/usr/share/fonts/wps-office/simfang.ttf"
  14. font = FontProperties(fname=font_fname)
  15. # plt.rcParams['font.sans-serif']=['simfang']#设置作图中文显示

  16. # scipy中signal模块之IIR滤波器(低通)的使用

  17. continue_time = 2e-6
  18. fs = 100e6
  19. f = [10e6, 30e6, 40e6]
  20. sample_num = int(np.ceil(continue_time * fs))
  21. print("每个子脉冲的采样点数(采样速率有关)=", sample_num)
  22. print("多个频率分量的信号=", f)
  23. x_time = np.linspace(0, continue_time, sample_num, endpoint=True)


  24. RCS = 1
  25. Rx_signal_1 = RCS * np.cos(2 * np.pi * f[0] * x_time)
  26. Rx_signal_2 = RCS * np.cos(2 * np.pi * f[1] * x_time)
  27. Rx_signal_3 = RCS * np.cos(2 * np.pi * f[2] * x_time)
  28. Rx_signal_all = Rx_signal_1 + Rx_signal_2 + Rx_signal_3


  29. Rx_y_fft_1 = fftshift(fft(Rx_signal_1))
  30. Rx_y_fft_2 = fftshift(fft(Rx_signal_2))
  31. Rx_y_fft_3 = fftshift(fft(Rx_signal_3))
  32. Rx_y_fft_all = fftshift(fft(Rx_signal_all))
  33. x_f = np.linspace(0, int(fs), sample_num, endpoint=True) - int(fs/2)

  34. # 开始滤波   何为0相位滤波器?
  35. # Wn:归一化截止频率。计算公式Wn=2*截止频率/采样频率  截止频率=35e6  20e6
  36. # b,a: IIR滤波器的分子(b)和分母(a)多项式系数向量。output='ba'
  37. b, a = signal.butter(N=7, Wn=0.7, btype="lowpass")   # N表示滤波器的阶数  7 9 11阶
  38. print("IIR滤波器的分子b:", len(b), b)
  39. print("IIR滤波器的分母a:", len(a), a)
  40. filtedData = signal.filtfilt(b, a, Rx_signal_all)  #data为要过滤的信号
  41. print("滤波之后的数据:", filtedData.shape, filtedData[:3])
  42. Rx_y_fft_filtedData = fftshift(fft(filtedData))


  43. # 画图展示
  44. plt.figure(figsize=(14, 12))
  45. plt.figure(1)
  46. plt.subplot(5, 1, 1)
  47. # plt.plot(np.arange(sample_num), Rx_signal_1, marker='o', markersize=6, markerfacecolor='r')
  48. # plt.title('信号_时域', fontproperties=font, fontsize=16)
  49. # plt.xlabel('time/sample_num')
  50. plt.plot(x_f, np.abs(Rx_y_fft_filtedData), marker='o', markersize=6, markerfacecolor='r')
  51. plt.title('滤波后_幅度谱', fontproperties=font, fontsize=16)
  52. plt.xlabel('freq')

  53. plt.subplot(5, 1, 2)
  54. plt.plot(x_f, np.abs(Rx_y_fft_1), marker='o', markersize=6, markerfacecolor='b')
  55. plt.title('信号1_幅度谱', fontproperties=font, fontsize=16)
  56. # plt.axis([0, 500, -3, 3])
  57. plt.xlabel('freq')

  58. plt.subplot(5, 1, 3)
  59. plt.plot(x_f, np.abs(Rx_y_fft_2), marker='o', markersize=6, markerfacecolor='r')
  60. plt.title('信号2_幅度谱', fontproperties=font, fontsize=16)
  61. # plt.axis([0, 500, -3, 3])
  62. plt.xlabel('freq')

  63. plt.subplot(5, 1, 4)
  64. plt.plot(x_f, np.abs(Rx_y_fft_3), marker='o', markersize=6, markerfacecolor='b')
  65. plt.title('信号3_幅度谱', fontproperties=font, fontsize=16)
  66. # plt.axis([0, 500, -3, 3])
  67. plt.xlabel('freq')

  68. plt.subplot(5, 1, 5)
  69. plt.plot(x_f, np.abs(Rx_y_fft_all), marker='o', markersize=6, markerfacecolor='r')
  70. plt.title('信号all_幅度谱', fontproperties=font, fontsize=16)
  71. # plt.axis([0, 500, -3, 3])
  72. plt.xlabel('freq')


  73. plt.show()

复制代码


python滤波器的使用.png (93.65 KB, 下载次数: 98)

python滤波器的使用.png
让天下人人学会人工智能!人工智能的前景一片大好!
回复

使用道具 举报

0

主题

98

帖子

200

积分

中级会员

Rank: 3Rank: 3

积分
200
沙发
发表于 2021-11-23 19:27:18 | 只看该作者
让天下人人学会人工智能!人工智能的前景一片大好!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|人工智能工程师的摇篮 ( 湘ICP备2020019608号-1 )

GMT+8, 2024-5-19 11:44 , Processed in 0.181329 second(s), 21 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表