linearfilter.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:zignal 作者: ronnyandersson 项目源码 文件源码
def plot_mag_phase(self, filename=None, plotpoints=10000, unwrap=False):
        """Produce a plot with magnitude and phase response in the same
        figure. The y-axis on the left side belongs to the magnitude
        response. The y-axis on the right side belongs to the phase
        response
        """
        unused_freq, mag = self.magnitude_resp(plotpoints)
        freq, pha = self.phase_resp(plotpoints, unwrap=unwrap)

        fig = plt.figure(1)
        ax_mag = fig.add_subplot(111)
        ax_pha = ax_mag.twinx()
        ax_mag.semilogx(freq, mag, label='magnitude', color='red',  linestyle='-')
        ax_pha.semilogx(freq, pha, label='phase',     color='blue', linestyle='--')
        ax_mag.grid(True)

        ax_mag.set_xlim(10, self.fs/2)
        #ax_mag.set_ylim(bottom=-80)    # FIXME: ad proper padding
        #ax_mag.margins(0.1)

        ax_mag.set_title('Frequency response')
        ax_mag.set_xlabel('Frequency [Hz]')
        ax_mag.set_ylabel('Magnitude [dB]')
        ax_pha.set_ylabel('Phase [deg]')

        handles1, labels1 = ax_mag.get_legend_handles_labels()
        handles2, labels2 = ax_pha.get_legend_handles_labels()

        plt.legend(handles1 + handles2, labels1 + labels2, loc='best')

        if filename is None:
            plt.show()
        else:
            try:
                plt.savefig(filename)
            finally:
                plt.close(1)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号