所以,在我最后两个问题之后,我来谈谈我的实际问题。也许有人在我的理论程序中发现了错误,或者我在编程上做了些错事。在

我使用scipy.signal(使用firwin函数)在Python中实现带通滤波器。我的原始信号包括两个频率(w_1=600Hz,w_2=800Hz)。可能会有更多的频率所以我需要一个带通滤波器。在

在这个例子中,我想过滤掉大约600hz的频带,所以我取了600+/-20Hz作为截止频率。当我实现滤波器并使用lfilter在时域中再现信号时,正确的频率被过滤了。在

为了消除相移,我用scipy.signal.freqz绘制了频率响应图,返回值为firwin的h作为分子,1作为预定义的denumerator。

如freqz文档中所述,我还绘制了相位(=doc中的角度),并且能够查看频率响应图,以获得滤波信号频率600hz的相移。在

所以相位延迟t

tΒp=—(Tetha(w))/(w)

不幸的是,当我把这个相位延迟加到滤波信号的时间数据中时,它并没有得到与原始600hz信号相同的相位。在

我加了密码。奇怪的是,在消除部分代码以保持最小值之前,过滤后的信号以正确的振幅开始-现在情况更糟了。在################################################################################

#

# Filtering test

#

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

#

from math import *

import numpy as np

from scipy import signal

from scipy.signal import firwin, lfilter, lti

from scipy.signal import freqz

import matplotlib.pyplot as plt

import matplotlib.colors as colors

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

# Nb of frequencies in the original signal

nfrq = 2

F = [60,80]

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

# Sampling:

nitper = 16

nper = 50.

fmin = np.min(F)

fmax = np.max(F)

T0 = 1./fmin

dt = 1./fmax/nitper

#sampling frequency

fs = 1./dt

nyq_rate= fs/2

nitpermin = nitper*fmax/fmin

Nit = int(nper*nitpermin+1)

tps = np.linspace(0.,nper*T0,Nit)

dtf = fs/Nit

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

# Build analytic signal

# s = completeSignal(F,Nit,tps)

scomplete = np.zeros((Nit))

omg1 = 2.*pi*F[0]

omg2 = 2.*pi*F[1]

scomplete=scomplete+np.sin(omg1*tps)+np.sin(omg2*tps)

#ssingle = singleSignals(nfrq,F,Nit,tps)

ssingle=np.zeros((nfrq,Nit))

ssingle[0,:]=ssingle[0,:]+np.sin(omg1*tps)

ssingle[1,:]=ssingle[0,:]+np.sin(omg2*tps)

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

## Construction of the desired bandpass filter

lowcut = (60-2) # desired cutoff frequencies

highcut = (60+2)

ntaps = 451 # the higher and closer the signal frequencies, the more taps for the filter are required

taps_hamming = firwin(ntaps,[lowcut/nyq_rate, highcut/nyq_rate], pass_zero=False)

# Use lfilter to get the filtered signal

filtered_signal = lfilter(taps_hamming, 1, scomplete)

# The phase delay of the filtered signal

delay = ((ntaps-1)/2)/fs

plt.figure(1, figsize=(12, 9))

# Plot the signals

plt.plot(tps, scomplete,label="Original signal with %s freq" % nfrq)

plt.plot(tps-delay, filtered_signal,label="Filtered signal %s freq " % F[0])

plt.plot(tps, ssingle[0,:],label="original signal %s Hz" % F[0])

plt.grid(True)

plt.legend()

plt.xlim(0,1)

plt.xlabel('Time (s)')

plt.ylabel('Amplitude')

# Plot the frequency responses of the filter.

plt.figure(2, figsize=(12, 9))

plt.clf()

# First plot the desired ideal response as a green(ish) rectangle.

rect = plt.Rectangle((lowcut, 0), highcut - lowcut, 5.0,facecolor="#60ff60", alpha=0.2,label="ideal filter")

plt.gca().add_patch(rect)

# actual filter

w, h = freqz(taps_hamming, 1, worN=1000)

plt.plot((fs * 0.5 / np.pi) * w, abs(h), label="designed rectangular window filter")

plt.xlim(0,2*F[1])

plt.ylim(0, 1)

plt.grid(True)

plt.legend()

plt.xlabel('Frequency (Hz)')

plt.ylabel('Gain')

plt.title('Frequency response of FIR filter, %d taps' % ntaps)

plt.show()'

python产生fir滤波器_Python中使用FIR滤波器firwin后信号的相移相关推荐

  1. python算法和数据结构_Python中的数据结构和算法

    python算法和数据结构 To 至 Leonardo da Vinci 达芬奇(Leonardo da Vinci) 介绍 (Introduction) The purpose of this ar ...

  2. python兼职平台信号处理_Python 中 FIR 数字滤波器设计与时序信号处理——信号与系统大作业...

    概要 FIR 即有限脉冲响应(finite impulse response),它对应着无限脉冲响应.一般在现实生活中,由于数字方法处理信号时,不可能对无限长的信号进行测量和运算,而是取其有限的时间片 ...

  3. python决策树 多分类_Python中的决策树分类:您需要了解的一切

    python决策树 多分类 什么是决策树? (What is Decision Tree?) A decision tree is a decision support tool that uses ...

  4. python基础知识测试题_Python中的单元测试—基础知识

    python基础知识测试题 Unit testing is the number one skill which separates people who just finished their de ...

  5. python数据库模糊查询_python中数据库like模糊查询方式

    python中数据库like模糊查询方式 在Python中%是一个格式化字符,所以如果需要使用%则需要写成%%. 将在Python中执行的sql语句改为: sql = "SELECT * F ...

  6. python redis 消息队列_python中利用redis构建任务队列(queue)

    Python中的使用标准queue模块就可以建立多进程使用的队列,但是使用redis和redis-queue(rq)模块使这一操作更加简单. Part 1. 比如首先我们使用队列来简单的储存数据:我们 ...

  7. python数据结构包括什么_Python中的数据结构详解

    概述 在深入研究数据科学和模型构建之前,Python中的数据结构是一个需要学习的关键内容 了解Python提供的不同数据结构,包括列表.元组等 介绍 数据结构听起来是一个非常直截了当的话题,但许多数据 ...

  8. python基本算法语句_Python中基本且又常用的算法

    这篇文章主要学习Python常用算法,Python常用排序算法,具有一定的参考价值,感兴趣的小伙伴们可以参考一下 本节内容 算法定义 时间复杂度 空间复杂度 常用算法实例 1.算法定义 算法(Algo ...

  9. python怎么清理垃圾_Python 中的“垃圾”是怎么回收的?

    前言 对于python来说,一切皆为对象,所有的变量赋值都遵循着对象引用机制.程序在运行的时候,需要在内存中开辟出一块空间,用于存放运行时产生的临时变量:计算完成后,再将结果输出到永久性存储器中.如果 ...

最新文章

  1. 区块链开发: 2019年及以后数字货币的前景如何?
  2. 调制优缺点_复合铝基润滑脂和普通润滑脂的区别,复合铝基脂有什么优缺点
  3. Mysql 百万级数据优化资料
  4. 从 ThinkPHP 开发规范 看 PHP 的命名规范和开发建议
  5. 程序员python工作_程序员如何在工作中进步
  6. 信息学奥赛一本通 1942:【08NOIP普及组】ISBN号码 | OpenJudge NOI 1.7 29:ISBN号码 | 洛谷 P1055 [NOIP2008 普及组] ISBN 号码
  7. ajax传输文件大小有没有限制_巧改文件扩展名,1秒解除微信传输文件大小限制!...
  8. RHEL6.3 ftp服务器参数的戏说——不看白不看,看了不白看
  9. Mysql学习总结(64)——Mysql配置文件my.cnf各项参数解读
  10. 红帽企业linux 6.4 64位上实现mysql 5.6主从复制_红帽企业Linux 6.4 64位上实现MySQL 5.6主从复制...
  11. 保山一中2021高考成绩查询,云南省保山第一中学
  12. Matlab中CIC滤波器的应用
  13. BMP图像位图法隐藏信息
  14. LabVIEW32位和64位的兼容性
  15. Docker、CentOS 8遭弃用,GPT-3、M1芯片撼动技术圈,盘点2020影响开发者的十大事件!...
  16. 21秋期末考试工程项目管理10324k2 (2)
  17. 520表白神器-教你用微信每天给TA说晚安
  18. sql查询涵盖的时段_涵盖的主题
  19. Android 颜色值转换
  20. 一图了解App跳转微信小程序关注公众号,推送消息

热门文章

  1. ABAP:List中回写CheckBox的值到内表
  2. 晓庄学院计算机科学分数,2016南京晓庄学院艺术类专业录取分数线
  3. oracle数据库视图存放位置,oracle数据库审计
  4. cli2弃用了吗 vue_vue-cli 3 和 vue-cli 2的区别
  5. Hadoop,Yarn,Zookeeper,kafka数据仓库集群命令集合
  6. BUUCTF(pwn)picoctf_2018_are you root
  7. Python推荐算法讲解
  8. Python教程:lambda,filter,map的运用
  9. Python中的format()函数
  10. Python数据库添加时间