Skip to content

Commit 6ab887f

Browse files
committed
minor code cleanup
1 parent 1d70013 commit 6ab887f

151 files changed

Lines changed: 605 additions & 559 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Ch. 10 - Distortion, Saturation, and Clipping/arctanDistortion.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@
1111

1212
import numpy as np
1313

14+
1415
def arctanDistortion(x, alpha):
1516
N = len(x)
1617
y = np.zeros([N, 1])
1718

1819
for n in range(N):
1920
y[n] = (2/np.pi) * np.arctan(x[n] * alpha)
2021

21-
return y
22+
return y

Ch. 10 - Distortion, Saturation, and Clipping/asymmetrical.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@
1010

1111
import numpy as np
1212

13+
1314
def asymmetrical(x, dc):
1415
N = len(x)
15-
xOffset = x + dc # introduce DC offset
16+
xOffset = x + dc # introduce DC offset
1617
yOffset = np.zeros([N, 1])
1718

1819
for n in range(N):
@@ -23,6 +24,6 @@ def asymmetrical(x, dc):
2324
# Nonlinear distortion function
2425
yOffset[n] = xOffset[n] - (1/5) * pow(xOffset[n], 5)
2526

26-
y = yOffset - dc # remove DC offset
27+
y = yOffset - dc # remove DC offset
2728

28-
return y
29+
return y

Ch. 10 - Distortion, Saturation, and Clipping/bitReduction.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
import numpy as np
1414

15+
1516
def bitReduction(x, nBits):
1617
# Determine the desired number of possible amplitude values
1718
ampValues = pow(2, nBits)
@@ -32,4 +33,4 @@ def bitReduction(x, nBits):
3233
# Fit in full-scale range
3334
y = 2 * prepOut - 1
3435

35-
return y
36+
return y

Ch. 10 - Distortion, Saturation, and Clipping/cubicDistortion.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@
1111

1212
import numpy as np
1313

14+
1415
def cubicDistortion(x, a):
1516
N = len(x)
1617
y = np.zeros([N, 1])
1718

1819
for n in range(N):
1920
y[n] = x[n] - (a * (1/3) * pow(x[n], 3))
2021

21-
return y
22+
return y

Ch. 10 - Distortion, Saturation, and Clipping/diode.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,17 @@
66

77
import numpy as np
88

9+
910
def diode(x):
1011
# Diode Characteristics
11-
Vt = 0.0253 # thermal voltage
12-
eta = 1.68 # emission coefficient
13-
Is = 0.105 # saturation current
12+
Vt = 0.0253 # thermal voltage
13+
eta = 1.68 # emission coefficient
14+
Is = 0.105 # saturation current
1415

1516
N = len(x)
1617
y = np.zeros([N, 1])
1718

1819
for n in range(N):
1920
y[n] = Is * (np.exp(0.1 * x[n]/(eta * Vt)) - 1)
2021

21-
return y
22+
return y

Ch. 10 - Distortion, Saturation, and Clipping/distortionExample.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
f = 2
2424
t = np.arange(0, Fs * 1) * Ts
2525

26-
x = np.sin(2 * np.pi * f * t) # used as input signal for each distortion
26+
x = np.sin(2 * np.pi * f * t) # used as input signal for each distortion
2727

2828
# # Infinite clipping
2929
# y = infiniteClip(x)
@@ -74,18 +74,18 @@
7474

7575
# Plotting
7676
plt.figure(1)
77-
plt.subplot(1,2,1) # Waveform
77+
plt.subplot(1, 2, 1) # Waveform
7878
plt.plot(t, x, t, y)
7979
plt.axis([0, 1, -1.1, 1.1])
8080
plt.xlabel('Time (sec.)')
8181
plt.ylabel('Amplitude')
8282
plt.title('Waveform')
8383

84-
plt.subplot(1,2,2) # Characteristic Curve
84+
plt.subplot(1, 2, 2) # Characteristic Curve
8585
plt.plot(x, x, x, y)
8686
plt.axis([-1, 1, -1.1, 1.1])
8787
plt.xlabel('Input Amplitude')
8888
plt.ylabel('Output Amplitude')
8989
plt.legend(['Legend', 'Distortion'])
9090
plt.title('Characteristic Curve')
91-
plt.show()
91+
plt.show()

Ch. 10 - Distortion, Saturation, and Clipping/exponential.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@
1111

1212
import numpy as np
1313

14+
1415
def exponential(x, drive):
1516
N = len(x)
1617
y = np.zeros([N, 1])
1718

1819
for n in range(N):
1920
y[n] = np.sign(x[n]) * (1 - np.exp(-np.abs(drive * x[n])))
20-
return y
21+
22+
return y

Ch. 10 - Distortion, Saturation, and Clipping/fullWaveRectification.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import numpy as np
99

10+
1011
def fullWaveRectification(x):
1112
N = len(x)
1213
y = np.zeros([N, 1])
@@ -20,4 +21,4 @@ def fullWaveRectification(x):
2021
# If negative, flip input
2122
y[n] = (-1) * x[n]
2223

23-
return y
24+
return y

Ch. 10 - Distortion, Saturation, and Clipping/halfWaveRectification.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import numpy as np
88

9+
910
def halfWaveRectification(x):
1011
N = len(x)
1112
y = np.zeros([N, 1])
@@ -19,4 +20,4 @@ def halfWaveRectification(x):
1920
# If negative, set output to zero
2021
y[n] = 0
2122

22-
return y
23+
return y

Ch. 10 - Distortion, Saturation, and Clipping/hardClipping.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import numpy as np
1212

13+
1314
def hardClipping(x, thresh):
1415
N = len(x)
1516
y = np.zeros([N, 1])
@@ -26,4 +27,4 @@ def hardClipping(x, thresh):
2627
else:
2728
y[n] = x[n]
2829

29-
return y
30+
return y

0 commit comments

Comments
 (0)