Python Forum
Thread Rating:
  • 2 Vote(s) - 3.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Convolution with numpy
#4
(Mar-06-2017, 03:38 PM)zivoni Wrote: Neither I am an expert about signal processing, but out of curiosity I tried it and np.convolve convoluted happily.

import numpy as np
from scipy.signal import gaussian
import matplotlib.pyplot as plt

def convoluplot(signal, kernel):
    fig, (ax1, ax2, ax3) = plt.subplots(3, 1, sharex=True)
    ax1.plot(signal)
    ax1.set_title('Signal')
    ax2.plot(kernel)
    ax2.set_title('Filter')
    filtered = np.convolve(signal, kernel, "same") / sum(kernel)
    ax3.plot(filtered)
    ax3.set_title("Convolution")
    fig.show()

signal = np.zeros(500)
signal[100:150] = 1
signal[250:400] = np.linspace(0,1,150)
kernel = gaussian(100, 10)

convoluplot(signal, kernel)
Spoiled  image of output:

When kernel was "padded" with zeros, it "zeroed" part of input signal. Perhaps try shorter filtering window or sparkz's advice to use full mode to avoid cutting?
Thank you very much ! I will!

(Mar-06-2017, 02:25 PM)sparkz_alot Wrote: I am in no way an expert about any of this, but what type of output do you get if you use mode "full" instead of "same"?

unfortunately I get the same thing. But thank you very much for your reply !
Reply


Messages In This Thread
Convolution with numpy - by Tina - Mar-06-2017, 12:24 PM
RE: Convolution with numpy - by sparkz_alot - Mar-06-2017, 02:25 PM
RE: Convolution with numpy - by zivoni - Mar-06-2017, 03:38 PM
RE: Convolution with numpy - by Tina - Mar-07-2017, 03:16 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [Numpy] How to store different data type in one numpy array? water 7 298 Mar-26-2024, 02:18 PM
Last Post: snippsat
  Numpy returns "TypeError: unsupported operand type(s) for *: 'numpy.ufunc' and 'int'" kalle 2 2,530 Jul-19-2022, 06:31 AM
Last Post: paul18fr
  Convolution "same" in Python doesn't work as Matlab claw91 4 3,686 Oct-01-2020, 08:59 AM
Last Post: claw91
  "erlarge" a numpy-matrix to numpy-array PhysChem 2 2,932 Apr-09-2019, 04:54 PM
Last Post: PhysChem
  Numpy or Scipy Variance Convolution TimWebPhoenix 0 3,317 Jul-11-2017, 12:41 PM
Last Post: TimWebPhoenix

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020