Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Complex Sine Wave File Generation

Status
Not open for further replies.

levnu

Full Member level 2
Full Member level 2
Joined
Oct 29, 2010
Messages
149
Helped
0
Reputation
0
Reaction score
1
Trophy points
1,298
Location
Israel
Activity points
2,501
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,
 

Hi,

320M / 5M = 64
thus you have 64 points of sine in a full wave.

You may use excel to generate the values. 64 lines, just calculate the sine in 360°/64 increments.

Btw:
you did not mention what resolution and format you want the sine values.

Klaus

added:
and yes, I guess there are online tools. Just do an internet search.
Just out of curiosity I did a search: "sine table generator online"
--> 2.7 million hits. I´m a bit speechless, tbh.
 

You of course don't need that large a table, one with just 90 degrees in it
and appropriate logic/adder can minimize amount of memory needed.
Or DMA with logic for address control to implement the 4 quadrants.

Then there is always CORDIC approach. Although I think that would be too slow
to meet 320 MSPS.


Then there is the resonator approach using two stage IIR approach -

1646921215626.png




Regards, Dana.
 
Last edited:

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,
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:

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
This is fixed-point with word size 16-bits and fractional part 10-bits.

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 ---

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:

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
This is fixed-point with word size 16-bits and fractional part 10-bits.

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
BTW: for running Python scripts I am usinhg "Jupyter notebook" or "PyScripter" (on Windows10 OS).
 

Attachments

  • PyScripter01.png
    PyScripter01.png
    184.5 KB · Views: 170
Last edited:

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:

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
This is fixed-point with word size 16-bits and fractional part 10-bits.

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).
You sure these techniques would meet the 320,000,000 SPS spec user needs ?

Regards, Dana.
 

Hello,

see the signal def. : sinus = 2*np.sin(2 * np.pi * n * frequency / fs) where fs is sampling frequency

2 is amplitude and frequency=5Mhz/320MHz signal hence be: 2*sin*(2*PI*n*(5e6/320e6)
2*sin*(2*PI*n*0.015625)

Here is sample file for n=64 (64 samples) - generated as double (Float64):
Code:
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

with such python script:

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

# 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()

There is very simple to do changing output format as Float32, Integer64/32 or fixed-point binary or hex values.

This is just simple math, not magic ;)

Best Regards
--- Updated ---

BTW: see this link related to calculating FFT on audio signal (my link on other forum). I don't know if it is allowed to place post from different forums - if not let administrator take proper action>

https://www.eevblog.com/forum/fpga/xilinx-fft-ip-core-window-filtering-function-is-not-implemented/

Best Regards
 
Last edited:

Hi,

yes: VB, VBscript, C, and many other ways...

you say amplitude is 2 but the values show an amplitude of 10.

Klaus
 

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:

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
This is fixed-point with word size 16-bits and fractional part 10-bits.

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).

wow thank you for your answer
my FPGA guy gave me these instructions:
Hex data format:

1. File per channel

2. Each line - 4 bytes

3. Please ignore the header, we will add header

4. Each line we have 4 bytes


0x01020304

0x05060708

0x090A0B0C

......
Data Record Frame Format
CPU Address HexMem Address HexMem Address DecSectionFunctionIndex RecordByte 3Byte 2Byte 1Byte 0
bit 3bit 2bit 1bit 0bit 7bit 6bit 5bit 4bit 3bit 2bit 1bit 0bit 7bit 6bit 5bit 4bit 3bit 2bit 1bit 0bit 7bit 6bit 5bit 4bit 3bit 2bit 1bit 0bit 7bit 6bit 5bit 4bit 3bit 2bit 1bit 0
35343332313029282726252423222120191817161514131211109876543210
000Data HeaderHeader 0Text Data File Injector Name - 24 Chars
111Header 1
222Header 2
333Header 3
444Header 4
555Header 5
666Header 6Data 0 (first in file to Tx)Data 1 Second in file to Tx)
777Header 7Data 2Data 3
888Index 0Data 4Data 5
999Index 1…...…...
AA10Index 2…...…...
 

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
 

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
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);
 
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);
Hello @levnu,
thanks for clarification.

Best Regards
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top