Re: A problem using IDL? [message #60079] |
Fri, 02 May 2008 09:20 |
R.G. Stockwell
Messages: 363 Registered: July 1999
|
Senior Member |
|
|
a bit better code. The top plot is the aliased signal.
The bottom shows the well sampled (not aliased) signal, which
is sampled much more finely. The thick squares show the aliased
signal from the top plot.
window,xsize=800,ysize=400
min=0
max=100
n=205
x=fltarr(n+1)
for i=0,n do x[i]=min+double(i)*(max-min)/n
;print,x
y=sin(2*3.141593*x)
!P.multi=[0,1,2]
plot,x,y,psym=-4,xr=[0,10]
x1 = x
y1 = y
n=205*8
x=fltarr(n+1)
for i=0,n do x[i]=min+double(i)*(max-min)/n
;print,x
y=sin(2*3.141593*x)
plot,x,y,psym=-4,xr=[0,10]
oplot,x1,y1,psym=6,thick=4
end
|
|
|
Re: A problem using IDL? [message #60080 is a reply to message #60079] |
Fri, 02 May 2008 09:16  |
R.G. Stockwell
Messages: 363 Registered: July 1999
|
Senior Member |
|
|
<chihuyu@sohu.com> wrote in message
news:337cf67f-424c-4bd8-8340-7ec7d0a121a5@l25g2000prd.google groups.com...
> I used idl to write the following:
>
> window,xsize=800,ysize=400
> min=0
> max=100
> n=200
> x=fltarr(n+1)
> for i=0,n do x[i]=min+double(i)*(max-min)/n
> print,x
> y=sin(2*3.141593*x)
> plot,x,y
>
> When n=100 or n=200,the graph is wrong. When n >=300,it's OK.Can
> someone tell me why?
You are aliased. Definitely read up on it if you are not familiar with
aliasing, as it is quite important in spectral analysis. Also read up on
nyquist frequency.
you can write a sinusoid as
y = sin(2*!Pi*f/length*x)
to explicitly have your frequency in there.
Also, check out this code which explicitly shows the
aliasing.
window,xsize=800,ysize=400
min=0
max=100
n=100
x=fltarr(n+1)
for i=0,n do x[i]=min+double(i)*(max-min)/n
;print,x
y=sin(2*3.141593*x)
!P.multi=[0,1,2]
plot,x,y,psym=-4,xr=[0,10]
x1 = x
y1 = y
n=500
x=fltarr(n+1)
for i=0,n do x[i]=min+double(i)*(max-min)/n
;print,x
y=sin(2*3.141593*x)
plot,x,y,psym=-4,xr=[0,10]
oplot,x1,y1,psym=6,thick=4
|
|
|
Re: A problem using IDL? [message #60099 is a reply to message #60080] |
Thu, 01 May 2008 08:41  |
Vince Hradil
Messages: 574 Registered: December 1999
|
Senior Member |
|
|
On May 1, 9:49 am, pgri...@gmail.com wrote:
> If you want a meaningful plot of a sinusoidal function,
> you should make sure that you have enough data
> points (say, at least 10) in each cycle (period) of the function.
> If this condition is not fulfilled, the plot will look strange.
>
> Cheers,
> Paolochih...@sohu.com wrote:
>> I used idl to write the following:
>
>> window,xsize=800,ysize=400
>> min=0
>> max=100
>> n=200
>> x=fltarr(n+1)
>> for i=0,n do x[i]=min+double(i)*(max-min)/n
>> print,x
>> y=sin(2*3.141593*x)
>> plot,x,y
>
>> When n=100 or n=200,the graph is wrong. When n >=300,it's OK.Can
>> someone tell me why?
Also, combined with: http://www.dfanning.com/math_tips/sky_is_falling.html
|
|
|
Re: A problem using IDL? [message #60100 is a reply to message #60099] |
Thu, 01 May 2008 07:49  |
pgrigis
Messages: 436 Registered: September 2007
|
Senior Member |
|
|
If you want a meaningful plot of a sinusoidal function,
you should make sure that you have enough data
points (say, at least 10) in each cycle (period) of the function.
If this condition is not fulfilled, the plot will look strange.
Cheers,
Paolo
chih...@sohu.com wrote:
> I used idl to write the following:
>
> window,xsize=800,ysize=400
> min=0
> max=100
> n=200
> x=fltarr(n+1)
> for i=0,n do x[i]=min+double(i)*(max-min)/n
> print,x
> y=sin(2*3.141593*x)
> plot,x,y
>
> When n=100 or n=200,the graph is wrong. When n >=300,it's OK.Can
> someone tell me why?
|
|
|