Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7586505
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T19:26:44+00:00 2026-05-30T19:26:44+00:00

I would like to perform the operation of convolution of sinus signal and rectangular

  • 0

I would like to perform the operation of convolution of sinus signal and
rectangular pulse in scipy. I convolved sinus signal with cosinus signal
and plotted that on the graph,
but I would like to know how to create array with rectangular pulse,
something similar to this matlab expression

y = rectpulse(x,nsamp)

so I can convolve them. I use this to create my
sinus and cosinus signal

x=r_[0:50] (my array)
y01=sin(2*pi*x/49)
y02=cos(2*pi*x/49)

So i tried to create a nu.zeros(50), and manually changing the zeros from
position 15-25 from 0.0. to 0.9 so it looks like rectangle but convolution
on sinus array and this ‘rectangle’ array is weird,
It is supposed to be zero when there is no intersection but i get sinus
signal in return, here is the code:

from scipy import *
from pylab import *

x = r_[0:50]
y1 = sin(2*pi*x/49)
#y2 = cos(2*pi*x/49)
y2 = np.zeros(50)
for i in range(15,25):
    y2[i] = 0.9
#print len(y1),len(y2)
y3 = convolve(y2,y1,mode="same")
subplot(2,2,1)
plot(x,y1)
hold(True)
plot(x,y2)
hold(True)
subplot(2,2,2)
print len(x),len(y3)
plot(x,y3)
hold(True)
show()

I apologize in advance, i feel like this is the easiest thing but I could
not find any reference on how to create a rectangular pulse.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T19:26:45+00:00Added an answer on May 30, 2026 at 7:26 pm

    You’ve done very well plotting the convolution and then analyzing it to see that it is not what you expect, +1! However, I think the concern you have is related to the convolve function. Since you passed it the parameter mode="same" it chops off the part of the convolution that equals zero and leaves you with the “interesting” part. You have constructed the rect() function just fine, although I agree with you there should be an alternate way built in to scipy somewhere. When I allow the entire convolution to be plotted, I get:

    Convolution

    From this code:

    from scipy import *
    from pylab import *
    
    x = r_[0:50]
    y1 = sin(2*pi*x/49)
    #y2 = cos(2*pi*x/49)
    y2 = np.zeros((y1.shape))
    for i in range(15,25):
        y2[i] = 0.9
    #print len(y1),len(y2)
    #y3 = convolve(y2,y1,mode="same")
    y3 = convolve(y2,y1)
    subplot(2,2,1)
    plot(x,y1)
    hold(True)
    plot(x,y2)
    hold(True)
    subplot(2,2,2)
    print len(x),len(y3)
    xx = r_[0:len(y3)]
    print len(xx),len(y3)
    plot(xx,y3)
    hold(True)
    show()
    

    Which is what I would expect given the documentation for this function. Let me know if there is something else I missed!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to perform a simple operation in R that is easily done
I would like to perform a small operation on all entities of a specific
I would like to perform a measurement and plot a graph while the measurement
I would like to perform the same operation on several arrays, something like: #include<vector>
I would like to perform an Except operation on set of items. Code is
I would like to perform an operation on an argument based on the fact
I would like to perform the operation stated above. void myFunc() { ... //
I would like to have a trigger to perform following operation for inserted records:
I would like to perform an operation on two generics argument of the same
I would like to perform a certain operation every time a user adds a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.