def dh(theta, d, a, alpha): # First row of dh table A11 = np.cos(theta) A12 = -np.cos(alpha) * np.sin(theta) A13 = np.sin(alpha) * np.sin(theta) A14 = a * np.cos(theta) # second row of dh table A21 = np.sin(theta) A22 = np.cos(alpha) * np.cos(theta) A23 = -np.sin(alpha) * np.sin(theta) A24 = a * np.sin(theta) # third row of dh table A31 = 0 A32 = np.sin(alpha) A33 = np.cos(alpha) A34 = d # fourth row of dh table A41 = 0 A42 = 0 A43 = 0 A44 = 1 A = 0 A = np.array([[A11, A12, A13, A14], [A21, A22, A23, A24], [A31, A32, A33, A34], [A41, A42, A43, A44]]) return A
def encode(self): input_text = encode_c(self.encode_text.toPlainText()) if input_text == '': msgBox = QMessageBox() msgBox.setIcon(QMessageBox.Information) msgBox.setText("不能是空的") msgBox.setWindowTitle("系统警告") msgBox.setStandardButtons(QMessageBox.Ok | QMessageBox.Cancel) msgBox.buttonClicked.connect(msgButtonClick) returnValue = msgBox.exec() if returnValue == QMessageBox.Ok: return length = 35 temp = [ input_text[i:i + length] for i in range(0, len(input_text), length) ] for i in range(len(temp)): length_payload = str(format(len(temp[i]), 'b')) # 7자리 if len(length_payload) < 8: length_payload = length_payload.zfill(8) print(temp[i]) total = preamble + length_payload + temp[i] signal = ','.join(list(total)) time_signal = N * len(total) / sampling_rate t = np.arange(0, time_signal, Ts) np_signal = np.fromstring(signal, dtype='int', sep=',') sample = np.repeat(np_signal, N) if (len(t) % 10) != 0: t = t[:len(t) - 1] y = np.sin(2 * np.pi * (f + sample * 2000) * t) write('first.wav', sampling_rate, y) samplerate, data = sio.wavfile.read('first.wav') sd.play(data, samplerate) time.sleep(time_signal + 1)
def plot(): pass # log x axis plt.subplot(222) plt.semilogx(t, np.sin(2 * np.pi * t)) plt.title('semilogx') plt.grid(True)
import FitsUtils import pylab import numpy as np ordernum = 7 orders = FitsUtils.MakeXYpoints("output-8.fits") order = orders[ordernum] fx, fy, nout, jmax, prob = fasper(order.x, order.y - order.y.mean(), 6, 6) fx = 1. / fx print "maximum at ", fx[jmax] print "significance of maximum: ", prob # Make data window window_period = 2.0 window_y = np.sin(2 * np.pi / window_period * order.x) wfx, wfy, wnout, wjmax, wprob = fasper(order.x, window_y, 6, 6) wfx = 1. / wfx fig = pylab.figure(1) pylab.plot(order.x, order.y - order.y.mean()) pylab.figure(2) ax1 = pylab.subplot(211) pylab.plot(fx, fy) pylab.xlabel("Period (nm)") pylab.ylabel("L-S Power") pylab.title("Order #%i" % (ordernum + 1)) pylab.subplot(212, sharex=ax1) pylab.plot(wfx, wfy) pylab.xlabel("Period (nm)")
form_class = uic.loadUiType("gui_for_translate.ui")[0] sampling_rate = 48000 symbol_duration = 0.025 f = 4000 N = sampling_rate * symbol_duration Ts = 1 / sampling_rate FILENAME = "tmp.wav" preamble = '01010101010101010101' preamble_signal = ','.join(list(preamble)) preamble_time_signal = N * len(preamble) / sampling_rate preamble_t = np.arange(0, preamble_time_signal, Ts) preamble_np_signal = np.fromstring(preamble_signal, dtype='int', sep=',') preamble_sample = np.repeat(preamble_np_signal, N) preamble_y = np.sin(2 * np.pi * (f + preamble_sample * 2000) * preamble_t) def encode_c(s): return ''.join([bin(ord(c)).replace('0b', '') for c in s]) def decode_c(s): return ''.join([chr(i) for i in [int(b, 2) for b in s.split(' ')]]) class ThreadClass(QThread): def __init__(self): super().__init__() def run(self):
import os import asyncio import datetime import random import functools import websockets import np from http import HTTPStatus MIME_TYPES = {"html": "text/html", "js": "text/javascript", "css": "text/css"} sampling_rate = 1000 freq = 5 samples = 1000 x = np.arange(samples) y = 100 * np.sin(2 * np.pi * freq * x / sampling_rate) # print(y) async def process_request(path, request_headers): """Serves a file when doing a GET request with a valid path.""" if "Upgrade" in request_headers: return # Probably a WebSocket connection if path == '/': path = '/index.html' response_headers = [ ('Server', 'asyncio websocket server'), ('Connection', 'close'),
tol = h**2 #set number of grid points in each row/column n = int(1 / h - 1) #set x,y grid point vectors (n x 1) x = [i * h for i in range(n + 2)] y = [j * h for j in range(n + 2)] z = [k * h for k in range(n + 2)] #set empty SOR solution matrices u_SOR = np.zeros((n + 2, n + 2, n + 2)) old_SOR = np.zeros((n + 2, n + 2, n + 2)) #set optimum w for SOR w = 2 / (1 + sin(pi * h)) #initialize method finished flags and method iteration counts to 0 flag_SOR = 1 itcount_SOR = 0 #begin iterative schemes while flag_SOR: #update iteration counts if flag_SOR: itcount_SOR += 1 for k in range(1, n + 1): for j in range(1, n + 1): for i in range(1, n + 1):
def blurringkernel(shape, T, a, b): xx, yy = shape x, y = np.ogrid[(-xx / 2):(xx / 2), (-yy / 2):yy / 2] q = (np.pi * (x * a + y * b)) q[np.where(q == 0)] = T return (T / q) * np.sin(q) * np.exp(-1j * q)
def law_sines(A,B,C,a,b,c): import numpy as np from np import(sin,arcsin, radians) if solve is "side" is True: if A is None: if a and B and b is not None: A=sin((radians(a))*B)/sin(radians(b)) print("A is ",A,"B is ",B,"C is ",C,"a is ",a,"b is ",b,"c is ",c,) if a and C and c is not None: A=sin((radians(a))*C)/sin(radians(c)) print("A is ",A,"B is ",B,"C is ",C,"a is ",a,"b is ",b,"c is ",c,) if B is None: if b and A and a is not None: B=sin((radians(b))*A)/sin(radians(a)) print("A is ",A,"B is ",B,"C is ",C,"a is ",a,"b is ",b,"c is ",c,) if b and C and c is not None: B=sin((radians(b))*C)/sin(radians(c)) print("A is ",A,"B is ",B,"C is ",C,"a is ",a,"b is ",b,"c is ",c,) if C is None: if b and A and a is not None: C=sin((radians(c))*A)/sin(radians(a)) print("A is ",A,"B is ",B,"C is ",C,"a is ",a,"b is ",b,"c is ",c,) if b and C and c is not None: C=sin((radians(c))*B)/sin(radians(b)) print("A is ",A,"B is ",B,"C is ",C,"a is ",a,"b is ",b,"c is ",c,) elif solve is "angle" is True if a is None: if A and B and b is not None: a=arcsin((radians(b)*A)/B) print("A is ",A,"B is ",B,"C is ",C,"a is ",a,"b is ",b,"c is ",c,) if A and C and c is not None: a=arcsin((radians(c)*A)/C) print("A is ",A,"B is ",B,"C is ",C,"a is ",a,"b is ",b,"c is ",c,) if b is None: if B and A and a is not None: b=arcsin((radians(a)*B)/A) print("A is ",A,"B is ",B,"C is ",C,"a is ",a,"b is ",b,"c is ",c,) if B and C and c is not None: b=arcsin((radians(c)*B)/C) print("A is ",A,"B is ",B,"C is ",C,"a is ",a,"b is ",b,"c is ",c,) if c is None: if C and A and a is not None: c=arcsin((radians(a)*C)/A) print("A is ",A,"B is ",B,"C is ",C,"a is ",a,"b is ",b,"c is ",c,) if C and B and b is not None: c=arcsin((radians(b)*C)/B) print("A is ",A,"B is ",B,"C is ",C,"a is ",a,"b is ",b,"c is ",c,)
def fabrik(l1, l2, l3, x_prev, y_prev, z_prev, x_command, y_command, z_command, tol_limit, max_iterations): # Base rotation is simply based on angle made within the x-y plane q1_prev = np.arctan2(y_prev[3], x_prev[3]) q1 = np.arctan2(y_command, x_command) base_rotation = q1 - q1_prev # this is the rotation the base must make to get from initial position to the commanded position # Base rotation matrix about z R_z = np.array([[np.cos(base_rotation), -np.sin(base_rotation), 0.0], [np.sin(base_rotation), np.cos(base_rotation), 0.0], [0.0, 0.0, 1.0]]) # Rotate the location of each joint by the base rotation # This will force the FABRIK algorithim to only solve # in two dimensions, else each joint will move as if it has # a 3 DOF range of motion # print 'inside the fabrik method and x_joints is' # print x_joints p4 = np.dot(R_z, [x_prev[3], y_prev[3], z_prev[3]]) p3 = np.dot(R_z, [x_prev[2], y_prev[2], z_prev[2]]) p2 = np.dot(R_z, [x_prev[1], y_prev[1], z_prev[1]]) p1 = np.dot(R_z, [x_prev[0], y_prev[0], z_prev[0]]) # Store the (x,y,z) position of each joint p4x = p4[0] p4y = p4[1] p4z = p4[2] p3x = p3[0] p3y = p3[1] p3z = p3[2] p2x = p2[0] p2y = p2[1] p2z = p2[2] p1x = p1[0] p1y = p1[1] p1z = p1[2] # Starting point of each joint p1x_o = p1x p1y_o = p1y p1z_o = p1z iterations = 0 for j in range(1, max_iterations + 1): if np.sqrt( np.power(x_command, 2) + np.power(y_command, 2) + np.power(z_command, 2)) > (l1 + l2 + l3): print(' desired point is likely out of reach') [p3x, p3y, p3z] = project_along_vector(x_command, y_command, z_command, p3x, p3y, p3z, l3) [p2x, p2y, p2z] = project_along_vector(p3x, p3y, p3z, p2x, p2y, p2z, l2) [p1x, p1y, p1z] = project_along_vector(p2x, p2y, p2z, p1x, p1y, p1z, l1) [p2x, p2y, p2z] = project_along_vector(p1x_o, p1y_o, p1z_o, p2x, p2y, p2z, l1) [p3x, p3y, p3z] = project_along_vector(p2x, p2y, p2z, p3x, p3y, p3z, l2) [p4x, p4y, p4z] = project_along_vector(p3x, p3y, p3z, x_command, y_command, z_command, l3) # check how close FABRIK position is to command position tolx = p4x - x_command toly = p4y - y_command tolz = p4z - z_command tol = np.sqrt( np.power(tolx, 2) + np.power(toly, 2) + np.power(tolz, 2)) iterations = iterations + 1 # Check if tolerance is within the specefied limit # Re-organize points into a big matrix for plotting elsewhere p_joints = np.array([[p1x, p2x, p3x, p4x], [p1y, p2y, p3y, p4y], [p1z, p2z, p3z, p4z]]) v21 = np.array([p2x - p1x, p2y - p1y, p2z - p1z]) v32 = np.array([p3x - p2x, p3y - p2y, p3z - p2z]) v43 = np.array([p4x - p3x, p4y - p3y, p4z - p3z]) q2 = np.arctan2( (p2z - p1z), np.sqrt(np.power(p2x - p1x, 2) + np.power(p2y - p1y, 2))) q3 = -1 * angle_from_dot_product(v21, v32) q4 = -1 * angle_from_dot_product(v32, v43) q_joints = np.array([q1, q2, q3, q4]) return q_joints