2

I was trying to make sin wave of the type

f(x) = A*sin(2*pi*f*x + phi)

Where A is amplitude, f is frequency and phi is phase angle. I know to plot simple sin curve like this :

def plot(self):
    Amplitude = 1.5
    Frequency = 0.5
    Phase = 2.6
    ax = self.figure.add_subplot(111)
    X = np.linspace(-np.pi, np.pi, 256,endpoint=True)
    S = np.sin(X)
    ax.hold(True)
    ax.plot(X, S, color="blue", linewidth=1.0, linestyle="-")
    xlim(0.0,2.0)
    xticks(np.linspace(0,2,5,endpoint=True))
    ylim(-1.5,1.5)
    yticks(np.linspace(-1.5,1.5,7,endpoint=True))
    self.canvas.draw()

I am drawing it using QtGui. Please help me find correct way to plot this sine wave.

I have an idea that I need to modify these two lines :

X = np.linspace(-np.pi, np.pi, 256,endpoint=True)
S = np.sin(X)

My Try :

def plot(self):
    Amplitude = 1.5
    Frequency = 0.5
    Phase = 2.6

    fs = 44100
    T = np.arange(-0.002, .002, 1.0/fs)

    ax = self.figure.add_subplot(111)

    X = Amplitude*np.sin(2*np.pi*Frequency*T + Phase)

    ax.hold(True)
    ax.plot(T, X, color="blue", linewidth=1.0, linestyle="-")
    xlim(0.0,2.0)
    xticks(np.linspace(0,2,5,endpoint=True))
    ylim(-1.5,1.5)
    yticks(np.linspace(-1.5,1.5,7,endpoint=True))
    self.canvas.draw()

But nothing is displayed as sine wave now . Please help me find error.

Along X axis it lie from 0 to 2 like this 0,0.5,1.0,1.5,2.0

Along Y axis it lie from -1.5 to 1.5 like this -1.5,-1.0,-0.5,0.0,0.5,1.0,1.5

mat7
  • 297
  • 3
  • 11

0 Answers0