Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > VHDL > distorted sine wave

Reply
Thread Tools

distorted sine wave

 
 
FPGA
Guest
Posts: n/a
 
      02-15-2008
I have written a process to generate sine wave. I am getting a
distorted wave and not a pure sine wave. I am not sure if this has
anything to do with the simulator.

two : process
variable phase_temp,result : real;
constant scale : real := 2.0*real(bw);
begin
phase_temp := phase_sin; --phase_sin;
l1 : for i in 1 to samples_sin loop --number_of_samples loop
result := scale*(amp_sin*(sin(frq_sin + phase_temp)));
sine_real <= (amp_sin*(sin(frq_sin + phase_temp)));
sinWave <= toSigned(result,bw);
phase_temp := phase_temp+incr_sin;
wait for 5 ns;
end loop l1;

end process two;

generic value : phase_sin : real := 0.0; samples_sin : integer :=
1000; incr_sin : real := 1.0;
frq_sin : real := 1000.0;

I dont see the frequency of the wave change if the frq_sin is changed.
Same happens when samples_sin is changed. I am not sure what is going
wrong. Please help
 
Reply With Quote
 
 
 
 
John_H
Guest
Posts: n/a
 
      02-15-2008
On Feb 15, 8:11*am, FPGA <(E-Mail Removed)> wrote:
> I have written a process to generate sine wave. I am getting a
> distorted wave and not a pure sine wave. I am not sure if this has
> anything to do with the simulator.
>
> two : process
> variable phase_temp,result : real;
> constant scale : real := 2.0*real(bw);
> begin
> * * * * phase_temp := phase_sin; --phase_sin;
> * * * * l1 : for i in 1 to samples_sin loop --number_of_samples loop
> * * * * result := scale*(amp_sin*(sin(frq_sin + phase_temp)));
> * * * * sine_real <= (amp_sin*(sin(frq_sin + phase_temp)));
> * * * * sinWave <= toSigned(result,bw);
> * * * * * * * * phase_temp := phase_temp+incr_sin;
> * * * * * * * * wait for 5 ns;
> * * * * end loop l1;
>
> end process two;
>
> generic value : * phase_sin : real := 0.0; * samples_sin : integer :=
> 1000; * incr_sin : real := 1.0;
> * frq_sin : real := 1000.0;
>
> I dont see the frequency of the wave change if the frq_sin is changed.
> Same happens when samples_sin is changed. I am not sure what is going
> wrong. Please help


Your frq_sin value is actually just a phase offset. There is no time
associated with this constant to feed the sin(). The phase_temp, on
the other hand, is effectively t*incr_sin where t is a cycle count.
To see the frequency change, change the incr_sin value instead.

In what way is your sine distorted?

- John_H
 
Reply With Quote
 
 
 
 
FPGA
Guest
Posts: n/a
 
      02-15-2008
On Feb 15, 12:45*pm, John_H <(E-Mail Removed)> wrote:
> On Feb 15, 8:11*am, FPGA <(E-Mail Removed)> wrote:
>
>
>
>
>
> > I have written a process to generate sine wave. I am getting a
> > distorted wave and not a pure sine wave. I am not sure if this has
> > anything to do with the simulator.

>
> > two : process
> > variable phase_temp,result : real;
> > constant scale : real := 2.0*real(bw);
> > begin
> > * * * * phase_temp := phase_sin; --phase_sin;
> > * * * * l1 : for i in 1 to samples_sin loop --number_of_samples loop
> > * * * * result := scale*(amp_sin*(sin(frq_sin + phase_temp)));
> > * * * * sine_real <= (amp_sin*(sin(frq_sin + phase_temp)));
> > * * * * sinWave <= toSigned(result,bw);
> > * * * * * * * * phase_temp := phase_temp+incr_sin;
> > * * * * * * * * wait for 5 ns;
> > * * * * end loop l1;

>
> > end process two;

>
> > generic value : * phase_sin : real := 0.0; * samples_sin : integer :=
> > 1000; * incr_sin : real := 1.0;
> > * frq_sin : real := 1000.0;

>
> > I dont see the frequency of the wave change if the frq_sin is changed.
> > Same happens when samples_sin is changed. I am not sure what is going
> > wrong. Please help

>
> Your frq_sin value is actually just a phase offset. *There is no time
> associated with this constant to feed the sin(). *The phase_temp, on
> the other hand, is effectively t*incr_sin where t is a cycle count.
> To see the frequency change, change the incr_sin value instead.
>
> In what way is your sine distorted?
>
> - John_H- Hide quoted text -
>
> - Show quoted text -

How can I pass time parameter to the sineWave? I was able to remove
the distortion by reducing the incr_sin value. Still not clear on the
frequency and time parameter that you are talking about.
 
Reply With Quote
 
none
Guest
Posts: n/a
 
      02-15-2008
John_H wrote:
> On Feb 15, 8:11 am, FPGA <(E-Mail Removed)> wrote:
>> I have written a process to generate sine wave. I am getting a
>> distorted wave and not a pure sine wave. I am not sure if this has
>> anything to do with the simulator.
>>
>> two : process
>> variable phase_temp,result : real;
>> constant scale : real := 2.0*real(bw);
>> begin
>> phase_temp := phase_sin; --phase_sin;
>> l1 : for i in 1 to samples_sin loop --number_of_samples loop
>> result := scale*(amp_sin*(sin(frq_sin + phase_temp)));
>> sine_real <= (amp_sin*(sin(frq_sin + phase_temp)));
>> sinWave <= toSigned(result,bw);
>> phase_temp := phase_temp+incr_sin;
>> wait for 5 ns;
>> end loop l1;
>>
>> end process two;
>>
>> generic value : phase_sin : real := 0.0; samples_sin : integer :=
>> 1000; incr_sin : real := 1.0;
>> frq_sin : real := 1000.0;
>>
>> I dont see the frequency of the wave change if the frq_sin is changed.
>> Same happens when samples_sin is changed. I am not sure what is going
>> wrong. Please help

>
> Your frq_sin value is actually just a phase offset. There is no time
> associated with this constant to feed the sin(). The phase_temp, on
> the other hand, is effectively t*incr_sin where t is a cycle count.
> To see the frequency change, change the incr_sin value instead.
>
> In what way is your sine distorted?
>
> - John_H

Change incr_sin to .1 and look at the difference in the waveform.
You are stepping through the sine wave in 6 steps so you will not
see what you expect. The wave will look a lot prettier with more
steps.

 
Reply With Quote
 
Dwayne Dilbeck
Guest
Posts: n/a
 
      02-15-2008
Time is being implied in your phase assignment. But you are not coding the
frequency generation correctly.

You code mathematiclly is saying the following
y=A*sin(fq+x)
x=x+c
Where fq is frq_sin, and c is incr_sin the sin wave cycle lasts from 0 to
2PI. There is no time or frequency associated with it. Your fq is just
offseting the start point not seting a period. What you want to do is the
following.
x=x+c
y=A*sin(2*PI*fq*x)
now remember that x is being incremented in time. fq is in hz. You need to
inverse fq to get your period time. which yeilds.
x=x+c;
y=A*sin(2*PI*x/tp)
where tp is the cycle length.

Your code should look like so:


for i in 1 to samples_sin loop
result:= scale*(amp_sin*(sin(2.0*PI*frq_sin*phase_temp);
sine_real<=(amp_sin*(sin(2.0*MATH_PI*frq_sin*phase _temp);
sineWave<=toSigned(result,bw)
phase_temp:= phase_temp+incr_sin;
wait for 5 ns; ---Note: This 5ns is not setting the actual frequncy result
with this code
end loop;

--to see a full sine wave cycle set the following:
phase_sin=0.0;
frq_sin=1000; --(1khz)
samples_sin=1000;
incr_sin=0.000001--(1ms/1000 samples)


With this code the "5ns" doesn't do anything constructive. But you could
change the code to make it useful

If you want the time display of the code to match the values that are given
in my comments use "wait for 1us"

Just looking at the time display based on the above code would apear to have
a 200MHZ
sign wave. (1us/5ns)=200, 200*(1 khz)=200Mhz













"FPGA" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
On Feb 15, 12:45 pm, John_H <(E-Mail Removed)> wrote:
> On Feb 15, 8:11 am, FPGA <(E-Mail Removed)> wrote:
>
>
>
>
>
> > I have written a process to generate sine wave. I am getting a
> > distorted wave and not a pure sine wave. I am not sure if this has
> > anything to do with the simulator.

>
> > two : process
> > variable phase_temp,result : real;
> > constant scale : real := 2.0*real(bw);
> > begin
> > phase_temp := phase_sin; --phase_sin;
> > l1 : for i in 1 to samples_sin loop --number_of_samples loop
> > result := scale*(amp_sin*(sin(frq_sin + phase_temp)));
> > sine_real <= (amp_sin*(sin(frq_sin + phase_temp)));
> > sinWave <= toSigned(result,bw);
> > phase_temp := phase_temp+incr_sin;
> > wait for 5 ns;
> > end loop l1;

>
> > end process two;

>
> > generic value : phase_sin : real := 0.0; samples_sin : integer :=
> > 1000; incr_sin : real := 1.0;
> > frq_sin : real := 1000.0;

>
> > I dont see the frequency of the wave change if the frq_sin is changed.
> > Same happens when samples_sin is changed. I am not sure what is going
> > wrong. Please help

>
> Your frq_sin value is actually just a phase offset. There is no time
> associated with this constant to feed the sin(). The phase_temp, on
> the other hand, is effectively t*incr_sin where t is a cycle count.
> To see the frequency change, change the incr_sin value instead.
>
> In what way is your sine distorted?
>
> - John_H- Hide quoted text -
>
> - Show quoted text -

How can I pass time parameter to the sineWave? I was able to remove
the distortion by reducing the incr_sin value. Still not clear on the
frequency and time parameter that you are talking about.


 
Reply With Quote
 
John_H
Guest
Posts: n/a
 
      02-15-2008
On Feb 15, 10:53*am, FPGA <(E-Mail Removed)> wrote:
> On Feb 15, 12:45*pm, John_H <(E-Mail Removed)> wrote:
>
>
>
> > On Feb 15, 8:11*am, FPGA <(E-Mail Removed)> wrote:

>
> > > I have written a process to generate sine wave. I am getting a
> > > distorted wave and not a pure sine wave. I am not sure if this has
> > > anything to do with the simulator.

>
> > > two : process
> > > variable phase_temp,result : real;
> > > constant scale : real := 2.0*real(bw);
> > > begin
> > > * * * * phase_temp := phase_sin; --phase_sin;
> > > * * * * l1 : for i in 1 to samples_sin loop --number_of_samples loop
> > > * * * * result := scale*(amp_sin*(sin(frq_sin + phase_temp)));
> > > * * * * sine_real <= (amp_sin*(sin(frq_sin + phase_temp)));
> > > * * * * sinWave <= toSigned(result,bw);
> > > * * * * * * * * phase_temp := phase_temp+incr_sin;
> > > * * * * * * * * wait for 5 ns;
> > > * * * * end loop l1;

>
> > > end process two;

>
> > > generic value : * phase_sin : real := 0.0; * samples_sin : integer :=
> > > 1000; * incr_sin : real := 1.0;
> > > * frq_sin : real := 1000.0;

>
> > > I dont see the frequency of the wave change if the frq_sin is changed.
> > > Same happens when samples_sin is changed. I am not sure what is going
> > > wrong. Please help

>
> > Your frq_sin value is actually just a phase offset. *There is no time
> > associated with this constant to feed the sin(). *The phase_temp, on
> > the other hand, is effectively t*incr_sin where t is a cycle count.
> > To see the frequency change, change the incr_sin value instead.

>
> > In what way is your sine distorted?

>
> > - John_H- Hide quoted text -

>
> > - Show quoted text -

>
> How can I pass time parameter to the sineWave? I was able to remove
> the distortion by reducing the incr_sin value. Still not clear on the
> frequency and time parameter that you are talking about.- Hide quoted text -
>
> - Show quoted text -


Phase accumulators are used to mark the prograssion of time. You want
sin(f*T) which is sin(f*n*deltaT) where deltaT is your clock period.
f*n*deltaT is the same as sum from 1 to n of f*deltaT, this last item
being a constant.

That's what you're doing with the incr_sin, isn't it? If you have an
increment of 1/100 of a sinusoidal period, the sum of 100 increments
will be one sinusoidal period bringing you right back to the
beginning.

You *are* doing this for simulation only, aren't you?

- John_H
 
Reply With Quote
 
FPGA
Guest
Posts: n/a
 
      02-17-2008
On Feb 15, 3:21*pm, John_H <(E-Mail Removed)> wrote:
> On Feb 15, 10:53*am, FPGA <(E-Mail Removed)> wrote:
>
>
>
>
>
> > On Feb 15, 12:45*pm, John_H <(E-Mail Removed)> wrote:

>
> > > On Feb 15, 8:11*am, FPGA <(E-Mail Removed)> wrote:

>
> > > > I have written a process to generate sine wave. I am getting a
> > > > distorted wave and not a pure sine wave. I am not sure if this has
> > > > anything to do with the simulator.

>
> > > > two : process
> > > > variable phase_temp,result : real;
> > > > constant scale : real := 2.0*real(bw);
> > > > begin
> > > > * * * * phase_temp := phase_sin; --phase_sin;
> > > > * * * * l1 : for i in 1 to samples_sin loop --number_of_samples loop
> > > > * * * * result := scale*(amp_sin*(sin(frq_sin + phase_temp)));
> > > > * * * * sine_real <= (amp_sin*(sin(frq_sin + phase_temp)));
> > > > * * * * sinWave <= toSigned(result,bw);
> > > > * * * * * * * * phase_temp := phase_temp+incr_sin;
> > > > * * * * * * * * wait for 5 ns;
> > > > * * * * end loop l1;

>
> > > > end process two;

>
> > > > generic value : * phase_sin : real := 0.0; * samples_sin : integer :=
> > > > 1000; * incr_sin : real := 1.0;
> > > > * frq_sin : real := 1000.0;

>
> > > > I dont see the frequency of the wave change if the frq_sin is changed.
> > > > Same happens when samples_sin is changed. I am not sure what is going
> > > > wrong. Please help

>
> > > Your frq_sin value is actually just a phase offset. *There is no time
> > > associated with this constant to feed the sin(). *The phase_temp, on
> > > the other hand, is effectively t*incr_sin where t is a cycle count.
> > > To see the frequency change, change the incr_sin value instead.

>
> > > In what way is your sine distorted?

>
> > > - John_H- Hide quoted text -

>
> > > - Show quoted text -

>
> > How can I pass time parameter to the sineWave? I was able to remove
> > the distortion by reducing the incr_sin value. Still not clear on the
> > frequency and time parameter that you are talking about.- Hide quoted text -

>
> > - Show quoted text -

>
> Phase accumulators are used to mark the prograssion of time. *You want
> sin(f*T) which is sin(f*n*deltaT) where deltaT is your clock period.
> f*n*deltaT is the same as sum from 1 to n of f*deltaT, this last item
> being a constant.
>
> That's what you're doing with the incr_sin, isn't it? *If you have an
> increment of 1/100 of a sinusoidal period, the sum of 100 increments
> will be one sinusoidal period bringing you right back to the
> beginning.
>
> You *are* doing this for simulation only, aren't you?
>
> - John_H- Hide quoted text -
>
> - Show quoted text -


This is for simulation only. Thanks for all your comments. I will make
the suggested changes and let you guys know how it went.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DAC5672 distorted sine out FPGA_guru VHDL 0 12-10-2012 06:44 AM
superposition of a square wave over a sine wave Shiva VHDL 2 02-02-2009 02:49 PM
superposition of a square wave over a sine wave rara10 VHDL 0 01-30-2009 08:21 PM
square wave / sine wave generator red floyd C++ 5 06-21-2007 09:30 PM
Best way to generate a sine wave? dhbrewer@gmail.com VHDL 1 11-28-2005 04:51 PM



Advertisments