0

I'm trying to plot a simple signal in python, and when i run this it doesn't show any error only 'Restart' and a blank space

from pymatlab import*

import numpy as np

from numpy import sqrt

import matplotlib.pyplot as plt

import scipy as sp

import math

(hashtags) n, coef, freq, phase

def sinyal(N,c,f,p):

 y=np.zeros(N)

 t=np.linspace(0,2*pi,N)

 Nf=len(c)

 for i in range(Nf):

     y+=c[i]*np.sin(f[i]*t)

     return y;

 # Signal Generator

 c=[2,5,10]

 f=[50, 150, 300]

 p=[0,0]

 N=2000

 x=np.linspace(0,2.0*math.pi,N)

 y=sinyal(N,c,f,p)

 plt.plot(x[:100],y[:100])

 plt.show()    

2 Answers 2

1

The code you posted has a logical indentation error. The call to sinyal is indented one level, placing it inside the definition of sinyal itself. So although sinyal gets defined, it never gets called.

Using 4 spaces for indentation may help you avoid this error in the future.

Sign up to request clarification or add additional context in comments.

Comments

0

Your code basically works (apart from some formatting errors and other oddities). I don't have pymatlab but it isn't necessary for this.

import numpy as np
from numpy import sqrt
import matplotlib.pyplot as plt
import scipy as sp
import math

def sinyal(N,c,f,p):
    y=np.zeros(N)
    t=np.linspace(0,2*np.pi,N)
    Nf=len(c)
    for i in range(Nf):
        y+=c[i]*np.sin(f[i]*t)
    return y;

 # Signal Generator
c=[2,5,10]
f=[50, 150, 300]
p=[0,0]
N=2000
x=np.linspace(0,2.0*math.pi,N)
y=sinyal(N,c,f,p)
plt.plot(x[:100],y[:100])
plt.show()    

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.