0% found this document useful (0 votes)
11 views

Pythin

The document contains Python code to generate and plot various signal waveforms including sine waves, cosine waves, discrete cosine waves, discrete sine waves, impulse functions, unit step functions, ramp functions, and quadratic functions. The code defines parameters like sample number, sampling frequency, time vector, and signal equations to generate the waveforms. Plots of the different signals are displayed for various frequencies and sample sizes.

Uploaded by

Ankita Sinha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Pythin

The document contains Python code to generate and plot various signal waveforms including sine waves, cosine waves, discrete cosine waves, discrete sine waves, impulse functions, unit step functions, ramp functions, and quadratic functions. The code defines parameters like sample number, sampling frequency, time vector, and signal equations to generate the waveforms. Plots of the different signals are displayed for various frequencies and sample sizes.

Uploaded by

Ankita Sinha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

PYTHON CODE-

1) Sine Wave

Code -

N = 1024;

fs = 200;

f = 1;

ts = 1/fs;

t = ts*(0:N-1);

x = sin(2*pi*f*t);

plot(t,x);

Output –
2) Cosine Wave

Code -

N = 1024;

fs = 200;

f = 1;

ts = 1/fs;

t = ts*(0:N-1);

x = cos(2*pi*f*t);

plot(t,x);

Output –

3) Discrete Cosine Wave

Code -

N = 1024;

fs = 200;

f = 1;

ts = 1/fs;
t = ts*(0:N-1);

x = cos(2*pi*f*t);

stem(t,x);

Output –

Code -

N = 100;

fs = 200;

f = 1;

ts = 1/fs;

t = ts*(0:N-1);

x = cos(2*pi*f*t);

stem(t,x);
Output –

4) Discrete Sine Wave

Code –

N = 1024;

fs = 200;

f = 1;

ts = 1/fs;

t = ts*(0:N-1);

x = sin(2*pi*f*t);

stem(t,x);
Output –

Code –

N = 100;

fs = 200;

f = 1;

ts = 1/fs;

t = ts*(0:N-1);

x = sin(2*pi*f*t);

stem(t,x);
Output –

5) Impulse Function

Code -

t=(-1:1:1)';

impulse=t==0;

unistep=t>=0;

ramp=t.*unistep;

quad=t.^2.*unistep;

plot(t,[impulse])
Output –

6) Unit Step Function

Code -

t=(-1:1:1)';

impulse=t==0;

unistep=t>=0;

ramp=t.*unistep;

quad=t.^2.*unistep;

stem(t,[impulse])
Output –

7) Ramp Function

Code -

t=(-1:1:1)';

impulse=t==0;

unistep=t>=0;

ramp=t.*unistep;

quad=t.^2.*unistep;

plot(t,[ramp])
Output –

8) Quadratic Function

Code –

t=(-1:01:1)';

impulse=t==0;

unistep=t>=0;

ramp=t.*unistep;

quad=t.^2.*unistep;

plot(t,[quad])
Output –

Codes in Python :-

1) Sine Wave
i) Frequency = 1Hz

Code –

N = 1024

fs = 200

f=1

ts = 1 / fs

t = ts * np.arange(0, N)

x = np.sin(2 * np.pi * f * t)

plt.plot(t, x)

plt.xlabel('Time (s)')

plt.ylabel('Amplitude')
plt.title('Sine Wave Signal')

plt.show()

Output –

ii) Frequency = 10 Hz

Code –

N = 1024

fs = 200

f = 10

ts = 1 / fs

t = ts * np.arange(0, N)

x = np.sin(2 * np.pi * f * t)

plt.plot(t, x)

plt.xlabel('Time (s)')
plt.ylabel('Amplitude')

plt.title('Sine Wave Signal')

plt.show()

Output –

iii) Frequency = 100 Hz

Code –

N = 1024

fs = 200

f = 100

ts = 1 / fs

t = ts * np.arange(0, N)

x = np.cos(2 * np.pi * f * t)

plt.plot(t, x)
plt.xlabel('Time (s)')

plt.ylabel('Amplitude')

plt.title('Sine Wave Signal')

plt.show()

Output –

2) Cosine Wave
i) Frequency = 1Hz

Code –

import numpy as np

import matplotlib.pyplot as plt

N = 1024

fs = 200

f=1
ts = 1 / fs

t = ts * np.arange(0, N)

x = np.cos(2 * np.pi * f * t)

plt.plot(t, x)

plt.xlabel('Time (s)')

plt.ylabel('Amplitude')

plt.title('Cosine Wave Signal')

plt.show()

Output –

ii) Frequency = 10 Hz

Code –

N = 1024

fs = 200
f = 10

ts = 1 / fs

t = ts * np.arange(0, N)

x = np.cos(2 * np.pi * f * t)

plt.plot(t, x)

plt.xlabel('Time (s)')

plt.ylabel('Amplitude')

plt.title('Cosine Wave Signal')

plt.show()

Output –

iii) Frequency = 100 Hz

Code –
N = 100

fs = 200

f = 100

ts = 1 / fs

t = ts * np.arange(0, N)

x = np.cos(2 * np.pi * f * t)

plt.plot(t, x)

plt.xlabel('Time (s)')

plt.ylabel('Amplitude')

plt.title('Cosine Wave Signal')

plt.show()

Output –
3) Discrete Cosine Wave

Code –

import numpy as np

import matplotlib.pyplot as plt

N = 1024

fs = 200

f=1

ts = 1 / fs

t = ts * np.arange(0, N)

x = np.cos(2 * np.pi * f * t)

plt.stem(t, x, use_line_collection=True)

plt.xlabel('Time (s)')

plt.ylabel('Amplitude')

plt.title('Discrete Cosine Wave Signal')

plt.show()
Output –

Code –

import numpy as np

import matplotlib.pyplot as plt

N = 1024

fs = 200

f=1

ts = 1 / fs

t = ts * np.arange(0, N)

x = np.cos(2 * np.pi * f * t)

plt.stem(t, x, use_line_collection=True)

plt.xlabel('Time (s)')
plt.ylabel('Amplitude')

plt.title('Discrete Cosine Wave Signal')

plt.show()

Output –

4) Discrete Sine Wave

Code –

import numpy as np

import matplotlib.pyplot as plt

N = 1024

fs = 200

f=1

ts = 1 / fs

t = ts * np.arange(0, N)
x = np.sin(2 * np.pi * f * t)

plt.stem(t, x, use_line_collection=True)

plt.xlabel('Time (s)')

plt.ylabel('Amplitude')

plt.title('Discrete Sine Wave Signal')

plt.show()

Output –

Code –

import numpy as np

import matplotlib.pyplot as plt

N = 1024

fs = 200
f=1

ts = 1 / fs

t = ts * np.arange(0, N)

x = np.sin(2 * np.pi * f * t)

plt.stem(t, x, use_line_collection=True)

plt.xlabel('Time (s)')

plt.ylabel('Amplitude')

plt.title('Discrete Sine Wave Signal')

plt.show()

Output –

5) Impulse Function, Unit Step Signal, Ramp Signal and Quadratic Function

Code –

import numpy as np
import matplotlib.pyplot as plt

t = np.arange(-1, 2, 1)

impulse = t == 0

unistep = t >= 0

ramp = t * unistep

quad = t**2 * unistep

plt.figure(figsize=(10, 6))

plt.subplot(2, 2, 1)

plt.plot(t, impulse)

plt.xlabel('Time')

plt.ylabel('Amplitude')

plt.title('Impulse Signal')

plt.subplot(2, 2, 2)

plt.plot(t, unistep)

plt.xlabel('Time')

plt.ylabel('Amplitude')

plt.title('Unit Step Signal')

plt.subplot(2, 2, 3)

plt.plot(t, ramp)

plt.xlabel('Time')
plt.ylabel('Amplitude')

plt.title('Ramp Signal')

plt.subplot(2, 2, 4)

plt.plot(t, quad)

plt.xlabel('Time')

plt.ylabel('Amplitude')

plt.title('Quadratic Signal')

plt.tight_layout()

plt.show()

Output –

You might also like