Pythin
Pythin
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 –
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 –
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 –
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.show()
Output –
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.show()
Output –
2) Cosine Wave
i) Frequency = 1Hz
Code –
import numpy as np
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.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.show()
Output –
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.show()
Output –
3) Discrete Cosine Wave
Code –
import numpy as np
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.show()
Output –
Code –
import numpy as np
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.show()
Output –
Code –
import numpy as np
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.show()
Output –
Code –
import numpy as np
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.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
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.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 –