Hello,Hi,
i would like to create a .hex file or .bin file that will include sine 5MHz wave sample with 320Msps, and i would inject it into FPGA Tx Serdes,
i guess it means 320M samples per second,
does it mean that i need to take a 5MHz signal and sample it each (1/320M) second? for e.g. qty of 5000 samples in a file, how can i do it?
is there a simple generator for this ?
Thanks,
def main():
pass
if __name__ == '__main__':
main()
import numpy as np
import scipy.signal as sig
from scipy.io import wavfile
import matplotlib.pyplot as plt
from fxpmath import Fxp
# sampling frequency
fs = 30000
n = np.arange(8192) #2**13
sinus = 2*np.sin(2 * np.pi * n * 50 / fs)+3*np.sin(2 * np.pi * n * 200 / fs+1.5707)+1.8*np.sin(2 * np.pi * n * 1000 / fs)+0.9*np.sin(2 * np.pi * n * 6500 / fs+0.7853)+2.4*np.sin(2 * np.pi * n * 10000 / fs)+3.7*np.sin(2 * np.pi * n * 12400 / fs)+2*np.sin(2 * np.pi * n * 14800 / fs)
plt.plot(n, sinus)
plt.xlabel('czas [s]')
plt.ylabel('amplituda')
plt.title('Przebieg sygnału sinusoidalnego')
plt.show()
sinus2=sinus.reshape((1,8192)) #trzeba zmienic shape, aby zapis w pliku byl mozliwy
n2=n.reshape((1,8192))
# printing the array and checking datatype
print('Array:', sinus2.shape)
print('Datatype:', sinus2.dtype)
sinus2I=sinus2.astype(np.int64)
print('Array:', sinus2I.shape)
print('Datatype:', sinus2I.dtype)
file = open("C:\\Rob\\AudioSignal.txt", "w")
for x in range(0, 8191):
z = Fxp(sinus2[0][x], signed=True, n_word=16, n_frac=10)
file.write(z.bin()+"\n")
#print(z.hex()) # hex repr
#print(z.val) # raw val (decimal of binary stored)
file.close()
memory_initialization_radix=2;
memory_initialization_vector=
0000111010001011
0010000011100111
1111011110101011
0001110010011011
0000110000100111
0001010100111101
0001010001111001
0001000111011110
0001001101001010
0000100011001100
0010010110010010
0000011111001011
0000010010101001
0010010000000101
1111010010001000
0010000001001000
0000000011110100
0000001110010111
BTW: for running Python scripts I am usinhg "Jupyter notebook" or "PyScripter" (on Windows10 OS).Hello,
I am doing such things with Python script and Numpy library (from Anaconda).:
Python:def main(): pass if __name__ == '__main__': main() import numpy as np import scipy.signal as sig from scipy.io import wavfile import matplotlib.pyplot as plt from fxpmath import Fxp # sampling frequency fs = 30000 n = np.arange(8192) #2**13 sinus = 2*np.sin(2 * np.pi * n * 50 / fs)+3*np.sin(2 * np.pi * n * 200 / fs+1.5707)+1.8*np.sin(2 * np.pi * n * 1000 / fs)+0.9*np.sin(2 * np.pi * n * 6500 / fs+0.7853)+2.4*np.sin(2 * np.pi * n * 10000 / fs)+3.7*np.sin(2 * np.pi * n * 12400 / fs)+2*np.sin(2 * np.pi * n * 14800 / fs) plt.plot(n, sinus) plt.xlabel('czas [s]') plt.ylabel('amplituda') plt.title('Przebieg sygnału sinusoidalnego') plt.show() sinus2=sinus.reshape((1,8192)) #trzeba zmienic shape, aby zapis w pliku byl mozliwy n2=n.reshape((1,8192)) # printing the array and checking datatype print('Array:', sinus2.shape) print('Datatype:', sinus2.dtype) sinus2I=sinus2.astype(np.int64) print('Array:', sinus2I.shape) print('Datatype:', sinus2I.dtype) file = open("C:\\Rob\\AudioSignal.txt", "w") for x in range(0, 8191): z = Fxp(sinus2[0][x], signed=True, n_word=16, n_frac=10) file.write(z.bin()+"\n") #print(z.hex()) # hex repr #print(z.val) # raw val (decimal of binary stored) file.close()
In this example the signal consist from few sinusoid: first have frequency 50 Hz and amplitude 2, second frequency 200Hz and amplitude 3 and so on ..
In what format you would like to have results:
1) as float numbers
2) as integer
3) fixed point numbers
For example I have been genereting from signal described above .coe file in order to make ROM memory in Xilinx FPGA - such file looks like:
This is fixed-point with word size 16-bits and fractional part 10-bits.Code:memory_initialization_radix=2; memory_initialization_vector= 0000111010001011 0010000011100111 1111011110101011 0001110010011011 0000110000100111 0001010100111101 0001010001111001 0001000111011110 0001001101001010 0000100011001100 0010010110010010 0000011111001011 0000010010101001 0010010000000101 1111010010001000 0010000001001000 0000000011110100 0000001110010111
Give your sampling frequency, ampiltude and frequency of sine signal for which you have sample generated , and give number of samples for 2PI angle. Also declare which format for sample you want (float64,float32,integer,fixed-point) and I can generate file with samples from this Python script for you.
If you want experiment with Python code then you have to install Anaconda with Python interpreter and needed libraries.
Best Regards
You sure these techniques would meet the 320,000,000 SPS spec user needs ?Hello,
I am doing such things with Python script and Numpy library (from Anaconda).:
Python:def main(): pass if __name__ == '__main__': main() import numpy as np import scipy.signal as sig from scipy.io import wavfile import matplotlib.pyplot as plt from fxpmath import Fxp # sampling frequency fs = 30000 n = np.arange(8192) #2**13 sinus = 2*np.sin(2 * np.pi * n * 50 / fs)+3*np.sin(2 * np.pi * n * 200 / fs+1.5707)+1.8*np.sin(2 * np.pi * n * 1000 / fs)+0.9*np.sin(2 * np.pi * n * 6500 / fs+0.7853)+2.4*np.sin(2 * np.pi * n * 10000 / fs)+3.7*np.sin(2 * np.pi * n * 12400 / fs)+2*np.sin(2 * np.pi * n * 14800 / fs) plt.plot(n, sinus) plt.xlabel('czas [s]') plt.ylabel('amplituda') plt.title('Przebieg sygnału sinusoidalnego') plt.show() sinus2=sinus.reshape((1,8192)) #trzeba zmienic shape, aby zapis w pliku byl mozliwy n2=n.reshape((1,8192)) # printing the array and checking datatype print('Array:', sinus2.shape) print('Datatype:', sinus2.dtype) sinus2I=sinus2.astype(np.int64) print('Array:', sinus2I.shape) print('Datatype:', sinus2I.dtype) file = open("C:\\Rob\\AudioSignal.txt", "w") for x in range(0, 8191): z = Fxp(sinus2[0][x], signed=True, n_word=16, n_frac=10) file.write(z.bin()+"\n") #print(z.hex()) # hex repr #print(z.val) # raw val (decimal of binary stored) file.close()
In this example the signal consist from few sinusoid: first have frequency 50 Hz and amplitude 2, second frequency 200Hz and amplitude 3 and so on ..
In what format you would like to have results:
1) as float numbers
2) as integer
3) fixed point numbers
For example I have been genereting from signal described above .coe file in order to make ROM memory in Xilinx FPGA - such file looks like:
This is fixed-point with word size 16-bits and fractional part 10-bits.Code:memory_initialization_radix=2; memory_initialization_vector= 0000111010001011 0010000011100111 1111011110101011 0001110010011011 0000110000100111 0001010100111101 0001010001111001 0001000111011110 0001001101001010 0000100011001100 0010010110010010 0000011111001011 0000010010101001 0010010000000101 1111010010001000 0010000001001000 0000000011110100 0000001110010111
Give your sampling frequency, ampiltude and frequency of sine signal for which you have sample generated , and give number of samples for 2PI angle. Also declare which format for sample you want (float64,float32,integer,fixed-point) and I can generate file with samples from this Python script for you.
If you want experiment with Python code then you have to install Anaconda with Python interpreter and needed libraries.
Best Regards
--- Updated ---
BTW: for running Python scripts I am usinhg "Jupyter notebook" or "PyScripter" (on Windows10 OS).
0.000000000000000000e+00
9.801714032956060363e-01
1.950903220161282370e+00
2.902846772544623200e+00
3.826834323650897929e+00
4.713967368259975643e+00
5.555702330196021776e+00
6.343932841636455322e+00
7.071067811865474617e+00
7.730104533627369712e+00
8.314696123025450802e+00
8.819212643483549385e+00
9.238795325112867829e+00
9.569403357322089576e+00
9.807852804032304306e+00
9.951847266721967955e+00
1.000000000000000000e+01
9.951847266721969731e+00
9.807852804032304306e+00
9.569403357322089576e+00
9.238795325112867829e+00
8.819212643483551162e+00
8.314696123025454355e+00
7.730104533627370600e+00
7.071067811865475505e+00
6.343932841636455322e+00
5.555702330196021776e+00
4.713967368259978308e+00
3.826834323650898817e+00
2.902846772544624088e+00
1.950903220161286145e+00
9.801714032956082567e-01
1.224646799147353256e-15
-9.801714032956059253e-01
-1.950903220161283702e+00
-2.902846772544620979e+00
-3.826834323650896597e+00
-4.713967368259976531e+00
-5.555702330196014671e+00
-6.343932841636449105e+00
-7.071067811865471064e+00
-7.730104533627367047e+00
-8.314696123025452579e+00
-8.819212643483549385e+00
-9.238795325112864276e+00
-9.569403357322087800e+00
-9.807852804032302529e+00
-9.951847266721969731e+00
-1.000000000000000000e+01
-9.951847266721969731e+00
-9.807852804032304306e+00
-9.569403357322089576e+00
-9.238795325112866053e+00
-8.819212643483551162e+00
-8.314696123025454355e+00
-7.730104533627368824e+00
-7.071067811865477282e+00
-6.343932841636458875e+00
-5.555702330196021776e+00
-4.713967368259979196e+00
-3.826834323650904146e+00
-2.902846772544624976e+00
-1.950903220161287255e+00
-9.801714032956050371e-01
def main():
pass
if __name__ == '__main__':
main()
import numpy as np
import scipy.signal as sig
from scipy.io import wavfile
import matplotlib.pyplot as plt
from fxpmath import Fxp
# częstotliwość próbkowania
fs = 320e6
n = np.arange(64) #2**13
sinus = 10*np.sin(2 * np.pi * n * 5e6 / fs)
plt.plot(n, sinus)
plt.xlabel('czas [s]')
plt.ylabel('amplituda')
plt.title('Przebieg sygnału sinusoidalnego')
plt.show()
sinus2=sinus.reshape((1,64)) #trzeba zmienic shape, aby zapis w pliku byl mozliwy
# printing the array and checking datatype
print('Array:', sinus2.shape)
print('Datatype:', sinus2.dtype)
file = open("C:\\Rob\\Sine5MHzSignal.txt", "w")
for row in sinus2:
np.savetxt(file,row)
file.close()
sinus = 10*np.sin(2 * np.pi * n * 5e6 / fs)
Hello,
I am doing such things with Python script and Numpy library (from Anaconda).:
Python:def main(): pass if __name__ == '__main__': main() import numpy as np import scipy.signal as sig from scipy.io import wavfile import matplotlib.pyplot as plt from fxpmath import Fxp # sampling frequency fs = 30000 n = np.arange(8192) #2**13 sinus = 2*np.sin(2 * np.pi * n * 50 / fs)+3*np.sin(2 * np.pi * n * 200 / fs+1.5707)+1.8*np.sin(2 * np.pi * n * 1000 / fs)+0.9*np.sin(2 * np.pi * n * 6500 / fs+0.7853)+2.4*np.sin(2 * np.pi * n * 10000 / fs)+3.7*np.sin(2 * np.pi * n * 12400 / fs)+2*np.sin(2 * np.pi * n * 14800 / fs) plt.plot(n, sinus) plt.xlabel('czas [s]') plt.ylabel('amplituda') plt.title('Przebieg sygnału sinusoidalnego') plt.show() sinus2=sinus.reshape((1,8192)) #trzeba zmienic shape, aby zapis w pliku byl mozliwy n2=n.reshape((1,8192)) # printing the array and checking datatype print('Array:', sinus2.shape) print('Datatype:', sinus2.dtype) sinus2I=sinus2.astype(np.int64) print('Array:', sinus2I.shape) print('Datatype:', sinus2I.dtype) file = open("C:\\Rob\\AudioSignal.txt", "w") for x in range(0, 8191): z = Fxp(sinus2[0][x], signed=True, n_word=16, n_frac=10) file.write(z.bin()+"\n") #print(z.hex()) # hex repr #print(z.val) # raw val (decimal of binary stored) file.close()
In this example the signal consist from few sinusoid: first have frequency 50 Hz and amplitude 2, second frequency 200Hz and amplitude 3 and so on ..
In what format you would like to have results:
1) as float numbers
2) as integer
3) fixed point numbers
For example I have been genereting from signal described above .coe file in order to make ROM memory in Xilinx FPGA - such file looks like:
This is fixed-point with word size 16-bits and fractional part 10-bits.Code:memory_initialization_radix=2; memory_initialization_vector= 0000111010001011 0010000011100111 1111011110101011 0001110010011011 0000110000100111 0001010100111101 0001010001111001 0001000111011110 0001001101001010 0000100011001100 0010010110010010 0000011111001011 0000010010101001 0010010000000101 1111010010001000 0010000001001000 0000000011110100 0000001110010111
Give your sampling frequency, ampiltude and frequency of sine signal for which you have sample generated , and give number of samples for 2PI angle. Also declare which format for sample you want (float64,float32,integer,fixed-point) and I can generate file with samples from this Python script for you.
If you want experiment with Python code then you have to install Anaconda with Python interpreter and needed libraries.
Best Regards
--- Updated ---
BTW: for running Python scripts I am usinhg "Jupyter notebook" or "PyScripter" (on Windows10 OS).
Data Record Frame Format | |||||||||||||||||||||||||||||||||||
CPU Address Hex | Mem Address Hex | Mem Address Dec | Section | Function | Index Record | Byte 3 | Byte 2 | Byte 1 | Byte 0 | ||||||||||||||||||||||||||
bit 3 | bit 2 | bit 1 | bit 0 | bit 7 | bit 6 | bit 5 | bit 4 | bit 3 | bit 2 | bit 1 | bit 0 | bit 7 | bit 6 | bit 5 | bit 4 | bit 3 | bit 2 | bit 1 | bit 0 | bit 7 | bit 6 | bit 5 | bit 4 | bit 3 | bit 2 | bit 1 | bit 0 | bit 7 | bit 6 | bit 5 | bit 4 | bit 3 | bit 2 | bit 1 | bit 0 |
35 | 34 | 33 | 32 | 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
0 | 0 | 0 | Data Header | Header 0 | Text Data File Injector Name - 24 Chars | ||||||||||||||||||||||||||||||
1 | 1 | 1 | Header 1 | ||||||||||||||||||||||||||||||||
2 | 2 | 2 | Header 2 | ||||||||||||||||||||||||||||||||
3 | 3 | 3 | Header 3 | ||||||||||||||||||||||||||||||||
4 | 4 | 4 | Header 4 | ||||||||||||||||||||||||||||||||
5 | 5 | 5 | Header 5 | ||||||||||||||||||||||||||||||||
6 | 6 | 6 | Header 6 | Data 0 (first in file to Tx) | Data 1 Second in file to Tx) | ||||||||||||||||||||||||||||||
7 | 7 | 7 | Header 7 | Data 2 | Data 3 | ||||||||||||||||||||||||||||||
8 | 8 | 8 | Index 0 | Data 4 | Data 5 | ||||||||||||||||||||||||||||||
9 | 9 | 9 | Index 1 | …... | …... | ||||||||||||||||||||||||||||||
A | A | 10 | Index 2 | …... | …... |
No, sorry i think you miss understood, i answered to the person that asked me in what format im looking to represent it, btw currently i did next function that migh be good:Hi,
are you asking for some one else to modify / write the code for you?
This is not how a forum is meant to work.
You get help for free here, but you should not expect that others do your job.
Klaus
Hello @levnu,No, sorry i think you miss understood, i answered to the person that asked me in what format im looking to represent it, btw currently i did next function that migh be good:
fs = 320e6; % Sampling frequency (samples per second)
dt = 1/fs; % seconds per sample
StopTime = 0.000010; % seconds
t = (0:dt:StopTime-dt)'; % seconds
F = 10e6; % Sine wave frequency (hertz)
data_I = cos(2*pi*F*t);
data_Q = sin(2*pi*F*t);
plot(data_I(2:end,1))
xlabel('Time index n');
ylabel('Amplitude');
title('Sine Wave');
grid on
hold on
plot(data_Q(2:end,1))
% HEX_I=num2hex(data_I);
% HEX_Q=num2hex(data_Q);
HEX_16_I=dec2hex(typecast(data_I,'uint32'),8);
HEX_16_Q=dec2hex(typecast(data_Q,'uint32'),8);
BTW it's working, when I tried to reconstruct I didn't get sine wave again
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?