<jupyter_start><jupyter_text>Demonstartion of Encoding Audio into Quantum State Using Different Encoding Methods<jupyter_code>import numpy as np
import matplotlib.pyplot as plot
import librosa<jupyter_output><empty_output><jupyter_text>Get The Sample Sound Signal and Resample<jupyter_code># Get x values of the sine wave

time        = np.arange(0, 10, 0.1);
# Amplitude of the sine wave is sine of a variable like time
amplitude   = np.sin(time)
# Plot a sine wave using time and amplitude obtained for the sine wave

plot.plot(time, amplitude)
# Give a title for the sine wave plot

plot.title('Sine wave')
# Give x axis label for the sine wave plot

plot.xlabel('Time')
# Give y axis label for the sine wave plot

plot.ylabel('Amplitude = sin(time)')
plot.grid(True, which='both')
plot.axhline(y=0, color='k')

import matplotlib.pyplot as plt
import numpy as np
from scipy import signal

Fs = 44100
f = 440
sample = 200
x = np.arange(sample)
y = np.sin(2 * np.pi * f * x / Fs)
xnew = np.linspace(0, 200, 8, endpoint=False)
#xnew = np.arange(0,200,20)
fnew = signal.resample(y, 8)
fig, ax=plt.subplots()
plt.xlabel('Sample(n)')
plt.ylabel('Amplitude')
plt.plot(x, y, '-',xnew, fnew,'r*')
plt.legend(['440Hz wave', 'Resampled'], loc='best')
plt.show()
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['bottom'].set_visible(False)

ax.spines['left'].set_linewidth(2)
import matplotlib.pyplot as plt
import numpy as np


Fs = 44100
f = 440
sample = 200
x = np.arange(sample)
y = np.sin(2 * np.pi * f * x / Fs)+1
xnew = np.linspace(0, 200, 8, endpoint=False)
#xnew = np.arange(0,200,20)
fnew = signal.resample(y, 8)
plt.xlabel('Sample(n)')
plt.ylabel('Amplitude')
plt.plot(x, y, '-',xnew, fnew,'r*')
plt.legend(['440Hz wave', 'Resampled'], loc='best')
plt.show()<jupyter_output><empty_output><jupyter_text>QRDA<jupyter_code>import matplotlib.pyplot as plt
import numpy as np

fig, ax=plt.subplots()
Fs = 44100
f = 440
sample = 200
x = np.arange(sample)
y = np.sin(2 * np.pi * f * x / Fs)+1
xnew = np.linspace(0, 200, 8, endpoint=False)
fnew = signal.resample(y, 8)

plt.grid(linestyle='-.')
plt.plot(xnew, fnew,'bo')
ax.plot([xnew[0],xnew[0]], [fnew[0],-0.333], color='r', linewidth=1, alpha=0.6)
ax.plot([xnew[1],xnew[1]], [fnew[1],-0.333], color='r', linewidth=1, alpha=0.6)
ax.plot([xnew[2],xnew[2]], [fnew[2],-0.333], color='r', linewidth=1, alpha=0.6)
ax.plot([xnew[3],xnew[3]], [fnew[3],-0.333], color='r', linewidth=1, alpha=0.6)
ax.plot([xnew[4],xnew[4]], [fnew[4],-0.333], color='r', linewidth=1, alpha=0.6)
ax.plot([xnew[5],xnew[5]], [fnew[5],-0.333], color='r', linewidth=1, alpha=0.6)
ax.plot([xnew[6],xnew[6]], [fnew[6],-0.333], color='r', linewidth=1, alpha=0.6)
ax.plot([xnew[7],xnew[7]], [fnew[7],-0.333], color='r', linewidth=1, alpha=0.6)
newx_ticks = np.linspace(0, 200, 9)
plt.xticks(newx_ticks)
newy_ticks = np.linspace(0, 2, 7)
plt.yticks(newy_ticks)
plt.ylim(0,2.2)
plt.yticks([-0.333,0,0.333, 0.667, 1, 1.333, 1.667,2],['$000$', '$001$', '$010$', '$011$', '$100$', '$101$', '$110$', '$111$'])
plt.xticks([0, 25, 50, 75, 100,125,150,175],['$000$', '$001$', '$010$', '$011$', '$100$', '$101$', '$110$', '$111$'])
plt.legend(['QRDA'], loc='best')
plt.xlabel('Time')
plt.ylabel('Amplitude')
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['bottom'].set_linewidth(2)
ax.spines['left'].set_linewidth(2)
plt.show()<jupyter_output><empty_output><jupyter_text>FRQA<jupyter_code>import matplotlib.pyplot as plt
import numpy as np


Fs = 44100
f = 440
sample = 200
fig, ax=plt.subplots()
x = np.arange(sample)
y = np.sin(2 * np.pi * f * x / Fs)
xnew = np.linspace(0, 200, 8, endpoint=False)
fnew = signal.resample(y, 8)
plt.grid(linestyle='-.')
plt.plot(xnew, fnew,'bo')
ax.plot([xnew[1],xnew[1]], [fnew[1],0], color='r', linewidth=1, alpha=0.6)
ax.plot([xnew[3],xnew[3]], [fnew[3],0], color='r', linewidth=1, alpha=0.6)
ax.plot([xnew[5],xnew[5]], [fnew[5],0], color='r', linewidth=1, alpha=0.6)
ax.plot([xnew[7],xnew[7]], [fnew[7],0], color='r', linewidth=1, alpha=0.6)
newx_ticks = np.linspace(0, 200, 9)
plt.xticks(newx_ticks)
plt.yticks([-1.330, -0.997, -0.664, -0.331, 0.001,0.334,0.667,1.000],['$100$', '$101$', '$110$', '$111$', '$000$', '$001$', '$010$', '$011$'])
newy_ticks = np.linspace(-1.33, 1, 8)
plt.yticks(newy_ticks)
plt.xticks([0, 25, 50, 75, 100,125,150,175],['$000$', '$001$', '$010$', '$011$', '$100$', '$101$', '$110$', '$111$'])
plt.legend(['FRQA'], loc='best')
plt.xlabel('Time')
plt.ylabel('Amplitude')
plot.axhline(y=0, color='k')
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['bottom'].set_visible(False)
ax.spines['bottom'].set_visible(False)
ax.spines['left'].set_linewidth(2)

plt.show()<jupyter_output><empty_output><jupyter_text>QRMA<jupyter_code>Fs = 44100
f = 440
sample = 200


fig, (ax1, ax2) = plt.subplots(1, 2,figsize=(10,6))
ax1.spines['top'].set_visible(False)
ax1.spines['right'].set_visible(False)
ax1.spines['bottom'].set_visible(False)
ax1.spines['bottom'].set_visible(False)
ax1.spines['left'].set_linewidth(2)

x = np.arange(sample)
y = np.sin(2 * np.pi * f * x / Fs)
xnew = np.linspace(0, 200, 8, endpoint=False)
fnew = signal.resample(y, 8)
ax1.plot([xnew[1],xnew[1]], [fnew[1],0], color='r', linewidth=1, alpha=0.6)
ax1.plot([xnew[3],xnew[3]], [fnew[3],0], color='r', linewidth=1, alpha=0.6)
ax1.plot([xnew[5],xnew[5]], [fnew[5],0], color='r', linewidth=1, alpha=0.6)
ax1.plot([xnew[7],xnew[7]], [fnew[7],0], color='r', linewidth=1, alpha=0.6)
ax1.grid(linestyle='-.')
ax1.plot(xnew, fnew,'bo')
newx_ticks = np.linspace(0, 200, 9)
ax1.set_xticks(newx_ticks)
ax1.set_yticks([-1.330, -0.997, -0.664, -0.331, 0.001,0.334,0.667,1.000])
ax1.set_yticklabels(['$100$', '$101$', '$110$', '$111$', '$000$', '$001$', '$010$', '$011$'])
newy_ticks = np.linspace(-1.33, 1, 8)
ax1.set_yticks(newy_ticks)
ax1.set_xticks([0, 25, 50, 75, 100,125,150,175])
ax1.set_xticklabels(['$000$', '$001$', '$010$', '$011$', '$100$', '$101$', '$110$', '$111$'])
ax1.legend(['QRMA'], loc='best')
ax1.set_xlabel('Time')
ax1.set_ylabel('Amplitude')
ax1.axhline(y=0, color='k')
ax1.set_title("Channel 1")

ax2.spines['top'].set_visible(False)
ax2.spines['right'].set_visible(False)
ax2.spines['bottom'].set_visible(False)
ax2.spines['bottom'].set_visible(False)
ax2.spines['left'].set_linewidth(2)

x = np.arange(sample)
y = np.sin(2 * np.pi * f * x / Fs)
xnew = np.linspace(0, 200, 8, endpoint=False)
fnew = signal.resample(y, 8)
ax2.plot([xnew[1],xnew[1]], [fnew[1],0], color='r', linewidth=1, alpha=0.6)
ax2.plot([xnew[3],xnew[3]], [fnew[3],0], color='r', linewidth=1, alpha=0.6)
ax2.plot([xnew[5],xnew[5]], [fnew[5],0], color='r', linewidth=1, alpha=0.6)
ax2.plot([xnew[7],xnew[7]], [fnew[7],0], color='r', linewidth=1, alpha=0.6)
ax2.grid(linestyle='-.')
ax2.plot(xnew, fnew,'bo')
newx_ticks = np.linspace(0, 200, 9)
ax2.set_xticks(newx_ticks)
ax2.set_yticks([-1.330, -0.997, -0.664, -0.331, 0.001,0.334,0.667,1.000])
ax2.set_yticklabels(['$100$', '$101$', '$110$', '$111$', '$000$', '$001$', '$010$', '$011$'])
newy_ticks = np.linspace(-1.33, 1, 8)
ax2.set_yticks(newy_ticks)
ax2.set_xticks([0, 25, 50, 75, 100,125,150,175])
ax2.set_xticklabels(['$000$', '$001$', '$010$', '$011$', '$100$', '$101$', '$110$', '$111$'])
ax2.legend(['QRMA'], loc='best')
ax2.set_xlabel('Time')
ax2.set_ylabel('Amplitude')
ax2.axhline(y=0, color='k')
ax2.set_title("Channel 2")

plt.show()<jupyter_output><empty_output><jupyter_text>Method Proposed in This Paper<jupyter_code>Fs = 44100
f = 440
sample = 200
fig, ax=plt.subplots()
x = np.arange(sample)
y = np.sin(2 * np.pi * f * x / Fs)
xnew = np.linspace(0, 200, 8, endpoint=False)
fnew = signal.resample(y, 8)
plt.grid(linestyle='-.')
plt.plot(xnew, fnew,'bo')
ax.plot([xnew[1],xnew[1]], [fnew[1],0], color='r', linewidth=1, alpha=0.6)
ax.plot([xnew[3],xnew[3]], [fnew[3],0], color='r', linewidth=1, alpha=0.6)
ax.plot([xnew[5],xnew[5]], [fnew[5],0], color='r', linewidth=1, alpha=0.6)
ax.plot([xnew[7],xnew[7]], [fnew[7],0], color='r', linewidth=1, alpha=0.6)
newx_ticks = np.linspace(0, 200, 9)
plt.xticks(newx_ticks)
plt.yticks([-1.330, -0.997, -0.664, -0.331, 0.001,0.334,0.667,1.000],['$100$', '$101$', '$110$', '$111$', '$000$', '$001$', '$010$', '$011$'])
newy_ticks = np.linspace(-1.33, 1, 8)
plt.yticks(newy_ticks)
plt.xticks([0, 25, 50, 75, 100,125,150,175],['$1$', '$2$', '$3$', '$4$', '$5$', '$6$', '$7$', '$8$'])
plt.legend(['New Method'], loc='best')
plt.xlabel('Sample(n)')
plt.ylabel('Amplitude')
plot.axhline(y=0, color='k',linewidth=2)
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['bottom'].set_visible(False)
ax.spines['left'].set_linewidth(2)

plt.show()<jupyter_output><empty_output><jupyter_text>Amplitude Encoding<jupyter_code>import matplotlib.pyplot as plt
import numpy as np


Fs = 44100
f = 440
sample = 200
x = np.arange(sample)
fig, ax=plt.subplots()
y = np.sin(2 * np.pi * f * x / Fs)
xnew = np.linspace(0, 200, 8, endpoint=False)
fnew = signal.resample(y, 8)
ampls = fnew / np.linalg.norm(fnew)
print(ampls)
plt.grid(linestyle='-.')
plt.plot(xnew, ampls,'bo')
newx_ticks = np.linspace(0, 200, 9)
plt.xticks(newx_ticks)
newy_ticks = np.linspace(-1, 1, 9)
plt.yticks(newy_ticks)
plt.xticks([0, 25, 50, 75, 100,125,150,175],['$000$', '$001$', '$010$', '$011$', '$100$', '$101$', '$110$', '$111$'])
plt.legend(['Amplitude Encoding'], loc='best')
plt.xlabel('Time')
plt.ylabel('Amplitude')
plot.axhline(y=0, color='k',linewidth=2)
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['bottom'].set_visible(False)
ax.spines['left'].set_linewidth(2)
ax.plot([xnew[1],xnew[1]], [ampls[1],0], color='r', linewidth=1, alpha=0.6)
ax.plot([xnew[3],xnew[3]], [ampls[3],0], color='r', linewidth=1, alpha=0.6)
ax.plot([xnew[5],xnew[5]], [ampls[5],0], color='r', linewidth=1, alpha=0.6)
ax.plot([xnew[7],xnew[7]], [ampls[7],0], color='r', linewidth=1, alpha=0.6)

plt.show()<jupyter_output>[-0.00676419  0.50082044  0.00292219 -0.49915859 -0.00708379  0.49904385
  0.01137444 -0.50074043]
{'fraction_non_alphanumeric': 0.2525121878420058, 'fraction_numerical': 0.10854641329220974, 'mean_word_length': 6.518324607329843, 'pattern_counts': {'":': 0, '<': 28, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '342253', 'license': 'CC0-1.0', 'n_tokens_mistral': 5223, 'n_tokens_neox': 4597, 'n_words': 798, 'path': 'Encoding demonstration.ipynb', 'repo_name': 'sitong1011/github', 'size': '10051'}