i've written a small and simple script to test the
fft-function of matlab that transformates exp(i*n*pi/xmax *
x) from xmin=-xmax to xmax. that should result in a
kronecker delta with positive amplitude with value 1... but
for some reason the amplitude is negative for odd n,... why
is that?
xmin=-5;
xmax = 5;
N= 2^8;
dx = (xmax-xmin)/N;
x = linspace(xmin,xmax,N);
"h xu" <quabla123@gmx.de> wrote in message
<fv7gge$a1d$1@fred.mathworks.com>...
> i've written a small and simple script to test the
> fft-function of matlab that transformates exp
(i*n*pi/xmax *
> x) from xmin=-xmax to xmax. that should result in a
> kronecker delta with positive amplitude with value 1...
but
> for some reason the amplitude is negative for odd n,...
why
> is that?
>
> xmin=-5;
> xmax = 5;
>
> N= 2^8;
> dx = (xmax-xmin)/N;
> x = linspace(xmin,xmax,N);
>
> y= exp(3* i*pi/xmax *x);
> NFFT = 2^nextpow2(N);
> Y_ = fft(y,NFFT)*dx;
> q = [0:NFFT-1]/NFFT/dx*xmax*2;
> Y = Y_(1:NFFT)/dx/NFFT;
> plot(q,real(Y),'.b')
>
>
On Apr 30, 4:30=A0am, "David " <d...@bigcompany.com> wrote:
> "h xu" <quabla...@gmx.de> wrote in message
>
> <fv7gge$a1...@fred.mathworks.com>...
>
>
>
>
>
> > i've written a small and simple script to test the
> > fft-function of matlab that transformates exp
> (i*n*pi/xmax *
> > x) from xmin=3D-xmax to xmax. that should result in a
> > kronecker delta with positive amplitude with value 1...
> but
> > for some reason the amplitude is negative for odd n,...
> why
> > is that?
>
> > xmin=3D-5;
> > xmax =3D 5;
>
> > N=3D 2^8;
> > dx =3D (xmax-xmin)/N;
> > x =3D linspace(xmin,xmax,N);
>
> > y=3D exp(3* i*pi/xmax *x);
> > NFFT =3D 2^nextpow2(N);
> > Y_ =3D fft(y,NFFT)*dx;
> > q =3D [0:NFFT-1]/NFFT/dx*xmax*2;
> > Y =3D Y_(1:NFFT)/dx/NFFT;
> > plot(q,real(Y),'.b')
>
> try
> y=3D -1*exp(3* i*(pi/xmax) *x);- Hide quoted text -
>
> - Show quoted text -
Try:
plot(q,abs(Y),'.b')
The sign of the real component (assuming the imaginary component is
zero) is just telling you the phase.
phase=3Dangle(Y)*180/pi;
"h xu" <quabla123@gmx.de> wrote in message
<fv7gge$a1d$1@fred.mathworks.com>...
> i've written a small and simple script to test the
> fft-function of matlab that transformates exp(i*n*pi/xmax *
> x) from xmin=-xmax to xmax. that should result in a
> kronecker delta with positive amplitude with value 1... but
> for some reason the amplitude is negative for odd n,... why
> is that?
>
> xmin=-5;
> xmax = 5;
>
> N= 2^8;
> dx = (xmax-xmin)/N;
> x = linspace(xmin,xmax,N);
>
> y= exp(3* i*pi/xmax *x);
> NFFT = 2^nextpow2(N);
> Y_ = fft(y,NFFT)*dx;
> q = [0:NFFT-1]/NFFT/dx*xmax*2;
> Y = Y_(1:NFFT)/dx/NFFT;
> plot(q,real(Y),'.b')
>
>
hm but i want to transformate functions, that transformated
also have a imaginary part, so what do i need to do, to have
the sign right for every value?
"h xu" <quabla123@gmx.de> wrote in message <fv9nd5
$9oe$1@fred.mathworks.com>...
> "h xu" <quabla123@gmx.de> wrote in message
> <fv7gge$a1d$1@fred.mathworks.com>...
> > i've written a small and simple script to test the
> > fft-function of matlab that transformates exp
(i*n*pi/xmax *
> > x) from xmin=-xmax to xmax. that should result in a
> > kronecker delta with positive amplitude with value
1... but
> > for some reason the amplitude is negative for odd
n,... why
> > is that?
> >
> > xmin=-5;
> > xmax = 5;
> >
> > N= 2^8;
> > dx = (xmax-xmin)/N;
> > x = linspace(xmin,xmax,N);
> >
> > y= exp(3* i*pi/xmax *x);
> > NFFT = 2^nextpow2(N);
> > Y_ = fft(y,NFFT)*dx;
> > q = [0:NFFT-1]/NFFT/dx*xmax*2;
> > Y = Y_(1:NFFT)/dx/NFFT;
> > plot(q,real(Y),'.b')
> >
> >
>
>
> hm but i want to transformate functions, that
transformated
> also have a imaginary part, so what do i need to do, to
have
> the sign right for every value?
try:
y= -1*exp(3* i*(pi/xmax) *x);
yes, it looks the same on the surface... but it REALLY
isn't.
"David " <dave@bigcompany.com> wrote in message
<fvadt7$e6u$1@fred.mathworks.com>...
> "h xu" <quabla123@gmx.de> wrote in message <fv9nd5
> $9oe$1@fred.mathworks.com>...
> > "h xu" <quabla123@gmx.de> wrote in message
> > <fv7gge$a1d$1@fred.mathworks.com>...
> > > i've written a small and simple script to test the
> > > fft-function of matlab that transformates exp
> (i*n*pi/xmax *
> > > x) from xmin=-xmax to xmax. that should result in a
> > > kronecker delta with positive amplitude with value
> 1... but
> > > for some reason the amplitude is negative for odd
> n,... why
> > > is that?
> > >
> > > xmin=-5;
> > > xmax = 5;
> > >
> > > N= 2^8;
> > > dx = (xmax-xmin)/N;
> > > x = linspace(xmin,xmax,N);
> > >
> > > y= exp(3* i*pi/xmax *x);
> > > NFFT = 2^nextpow2(N);
> > > Y_ = fft(y,NFFT)*dx;
> > > q = [0:NFFT-1]/NFFT/dx*xmax*2;
> > > Y = Y_(1:NFFT)/dx/NFFT;
> > > plot(q,real(Y),'.b')
> > >
> > >
> >
> >
> > hm but i want to transformate functions, that
> transformated
> > also have a imaginary part, so what do i need to do, to
> have
> > the sign right for every value?
>
> try:
> y= -1*exp(3* i*(pi/xmax) *x);
>
> yes, it looks the same on the surface... but it REALLY
> isn't.
mhm, sure for y=exp(n* i*(pi/xmax) *x) with n=3 or any other
odd number, the fft of y'=-y would change the amplitude from
negative to positive, but then the sign would be wrong if I
had even n.
well the exp() thing was just to make my problem with wrong
amplitude-sign clear.
my question is what i need to do to get the sign of the
ft-amplitude right for a abritary (also complex) function.
On Apr 29, 11:57=A0am, "h xu" <quabla...@gmx.de> wrote:
> i've written a small and simple script to test the
> fft-function of matlab that transformates exp(i*n*pi/xmax *
> x) from xmin=3D-xmax to xmax. that should result in a
> kronecker delta with positive amplitude with value 1... but
> for some reason the amplitude is negative for odd n,... why
> is that?
>
> xmin=3D-5;
> xmax =3D 5;
>
> N=3D 2^8;
> dx =3D (xmax-xmin)/N;
On Apr 29, 11:57 am, "h xu" <quabla...@gmx.de> wrote:
> i've written a small and simple script to test the
> fft-function of matlab that transformates exp(i*n*pi/xmax *
> x) from xmin=-xmax to xmax. that should result in a
> kronecker delta with positive amplitude with value 1... but
> for some reason the amplitude is negative for odd n,... why
> is that?
>
> xmin=-5;
xmin~=0 makes phase interpretation difficult
> xmax = 5;
>
> N= 2^8;
Too high; Try the 10 separate trials N = 3:12
> dx = (xmax-xmin)/N;
Incorrect. See below
> x = linspace(xmin,xmax,N);
>
> y= exp(3* i*pi/xmax *x);
Weird function. Try an FFT basis function. See below
-----SNIP
close all, clear, clc, j=0
N = 8 % Instructive to look at ALL of N=3:12
xmin = -5
xmax = 5
dx = (xmax-xmin)/(N-1)
X = N*dx % FFT imposed period = 10+dx
x = linspace(xmin,xmax,N)'; % OK (just changed to column)
x = xmin + dx*(0:N-1)' % Alternate form
df = 1/X % frequency spacing
f = df*(0:N-1)';
% The FFT basis functions are exp(2*pi*i*f(n)*x)
f0 = (N/4)*df % Half of the Nyquist frequency
y = exp(2*pi*i*f0*x);
z = zeros(size(x));
j=j+1,figure(j)
subplot(2,2,1), hold on
plot(x,z,'k')
plot(x,real(y))
subplot(2,2,2), hold on
plot(x,z,'k')
plot(x,imag(y))
subplot(2,2,3), hold on
plot(x,abs(y))
axis([xmin xmax 0 2])
subplot(2,2,4), hold on
plot(x,z,'k')
plot(x,angle(y))
Y = dx*fft(y);
y0 = df*Y; % Rescaling to the size of y
j=j+1,figure(j)
subplot(2,2,1), hold on
plot(f,z,'k')
plot(f,real(y0))
subplot(2,2,2), hold on
plot(f,z,'k')
plot(f,imag(y0))
subplot(2,2,3), hold on
plot(f,abs(y0))
% axis([0 max(f) 0 1.1*max(abs(Y))])
% axis([0 max(f) 0 1.1*max(abs(Y))])
subplot(2,2,4), hold on
plot(f,z,'k')
plot(f,angle(y0))
Hope this helps.
Greg
Tags for this Thread
Add a New Tag:
Separated by commas
Ex.: root locus, bode
What are tags?
A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.
Anyone can tag a thread. Tags are public and visible to everyone.
Public Submission Policy
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for
all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content.
Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available
via MATLAB Central. Read the complete Disclaimer prior to use.