Bottom Page

Thread Rating:
  • 2 Vote(s) - 3.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Convolution with numpy
#1
Hello everyone, 

I am trying to convolute 2 signals in the time-domain:

the first when is a gaussien function and the second one is a zero array but has an impulse at x1 and an increasing ramp between x2 and x3. Both peaks of the impulse and the increasing ramp have maximum 1. 

when I try to convolute both with 
 np.convolve(gaussian, signal, 'same')
 I only get a non-zero signal for the increasing ramp. Python seams to ignore the convolution with the impulse. but when I set the ramp to zero and redo the convolution python convolves with the impulse and I get the result. 

So separately, means : Convolution with impulse --> works
                                 Convolution with increasing ramp till 1 --> works
                                 Convolution with a signal containing both  : Impulse AND ramp --> does not work, shows just result of convolution with ramp.

Can anyone help?
Thank you in advance
Quote
#2
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"?
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Quote
#3
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?
snippsat likes this post
Quote
#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 !
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  numpy.copy / numpy.delete paul18fr 3 363 Jul-26-2019, 01:51 PM
Last Post: paul18fr
  "erlarge" a numpy-matrix to numpy-array PhysChem 2 491 Apr-09-2019, 04:54 PM
Last Post: PhysChem
  Numpy or Scipy Variance Convolution TimWebPhoenix 0 1,504 Jul-11-2017, 12:41 PM
Last Post: TimWebPhoenix

Forum Jump:


Users browsing this thread: 1 Guest(s)