DSPRelated.com
Forums

spectrum of symmetric real valued vector

Started by hyee...@yahoo.com.cn March 5, 2009
Help. Where it go wrong?

Get A N length even symmetric real valued vector ,Fourier transform it and result a spectrum vector with the same length N,which the imaginary part must be zero.
In contrast to that, A N length odd symmetric vector should result that the real part of spectrum is zero.

But I test and perform it and attain a wrong result. Where it go wrong?

Here is matlab script to illustrate it.

N = 64;
x = randn(N,1);
y = [x;flipud(x)];
z = [x;-flipud(x)];

Y t(y);
Z t(z);
[Y,Z]

Cheers
HyeeWang
The game is not so easy.
Which is the bandwidth of the signal that you are sampling?
Are you respecting the Nyquist theorem?
Using a gaussian noise you can not say anythings about.
Use a normal function or if you want visit
http://www.mathworks.com/matlabcentral/fileexchange/5654
where you can find that the rules that you cite are respected.
Bye
Daniele

On Wed, Mar 4, 2009 at 8:50 AM, wrote:
> Help. Where it go wrong?
>
> Get A N length even symmetric real valued vector ,Fourier transform it and
> result a spectrum vector with the same length N,which the imaginary part
> must be zero.
> In contrast to that, A N length odd symmetric vector should result that the
> real part of spectrum is zero.
>
> But I test and perform it and attain a wrong result. Where it go wrong?
>
> Here is matlab script to illustrate it.
>
> N = 64;
> x = randn(N,1);
> y = [x;flipud(x)];
> z = [x;-flipud(x)];
>
> Y t(y);
> Z t(z);
> [Y,Z]
>
> Cheers
> HyeeWang
Actually here, I don't think you need to worry about the Nyquist theorem and
using Gaussian noise doesn't hurt you.

The question is very simple. If X is a real even symmetric vector, then the
DFT should be real and it doesn't really matter what the contents of X is
(so you could generate X using a randn() command).

I think whats happening in h...@yahoo.com.cn 's code are the following:
a) the vector y and z are of length 128 and the way he's formed them, they
don't conform to the even (or odd) vector definition. e.g. if y = [0.234
0.234], it is not even. I think you need vectors of odd length to be called
even (or odd).
thus y = [0.234 0 0.234] is an even vector as the indices of y are -1, 0 and
1 and y(-k) = y(k)

b) Secondly, what is happening is that Matlab defines the FFT as the sum
from 0 to (N-1) { ... }. If the definition is such that the indices are
-(N-1)/2 to (N-1)/2 { ... } then you shall see the symmetry properties that
you expect.

Here's a simple code snippet for a very short vector that should show this
-- I am implementing the DFT but not using Matlab's built in FFT. Here the
final answer is indeed real as expected.
-----
N = 1;
x = randn(N,1);
y = [x; randn(); flipud(x)]; % y is even. Indices are -1, 0 and 1

% Implement DFT by writing out the DFT matrix with indices -1, 0 and 1
% Note Default FFT would have matrices, 1, 2, 3

[exp(-j*2*pi*-1*(0:2)/3).' exp(-j*2*pi*0*(0:2)/3).'
exp(-j*2*pi*1*(0:2)/3).']*y

On Thu, Mar 5, 2009 at 6:43 AM, arkkimede wrote:

> The game is not so easy.
> Which is the bandwidth of the signal that you are sampling?
> Are you respecting the Nyquist theorem?
> Using a gaussian noise you can not say anythings about.
> Use a normal function or if you want visit
> http://www.mathworks.com/matlabcentral/fileexchange/5654
> where you can find that the rules that you cite are respected.
> Bye
> Daniele
>
> On Wed, Mar 4, 2009 at 8:50 AM, wrote:
> > Help. Where it go wrong?
> >
> > Get A N length even symmetric real valued vector ,Fourier transform it
> and
> > result a spectrum vector with the same length N,which the imaginary part
> > must be zero.
> > In contrast to that, A N length odd symmetric vector should result that
> the
> > real part of spectrum is zero.
> >
> > But I test and perform it and attain a wrong result. Where it go wrong?
> >
> > Here is matlab script to illustrate it.
> >
> > N = 64;
> > x = randn(N,1);
> > y = [x;flipud(x)];
> > z = [x;-flipud(x)];
> >
> > Y t(y);
> > Z t(z);
> > [Y,Z]
> >
> > Cheers
> > HyeeWang
I have to think about.
In any case, if the signal is well defined, the result is correct in
any case (with even or odd number of point).
Try the code reported using
1)
t=-T/2:dt:T/2-dt
f=-Fmax:df:Fmax-df;

and
2)
t=-T/2:dt:T/2-dt
f=-Fmax:df:Fmax-df;

But I do not have all clear in my mind.
I spent a lot of time with fft and every day a meet a new problem
Bye Daniele

Bx = 10;
A = sqrt(log(2))/(2*pi*Bx);
fs = 500;
dt = 1/fs;
T=1;
%%%%%%%%%%%%%%%%%%%%
t = -T/2:dt:T/2-dt;
%%%%%%%%%%%%%%%%%%%%
length(t)
df = 1/T;
Fmax = 1/2/dt;
%%%%%%%%%%%%%%%%%%%%
f=-Fmax:df:Fmax-df;
%%%%%%%%%%%%%%%%%%%%
taun = 0.055;
%-------------------------------

%-------------------------------
% Numerical evaluations
%-------------------------------
x = exp(-t.^2/2/A^2);
X = dt * fftshift(fft(fftshift(x)));
On Fri, Mar 6, 2009 at 12:11 AM, Nandan Das wrote:
> Actually here, I don't think you need to worry about the Nyquist theorem and
> using Gaussian noise doesn't hurt you.
>
> The question is very simple. If X is a real even symmetric vector, then the
> DFT should be real and it doesn't really matter what the contents of X is
> (so you could generate X using a randn() command).
>
> I think whats happening in h...@yahoo.com.cn 's code are the following:
> a) the vector y and z are of length 128 and the way he's formed them, they
> don't conform to the even (or odd) vector definition. e.g. if y = [0.234
> 0.234], it is not even. I think you need vectors of odd length to be called
> even (or odd).
> thus y = [0.234 0 0.234] is an even vector as the indices of y are -1, 0 and
> 1 and y(-k) = y(k)
>
> b) Secondly, what is happening is that Matlab defines the FFT as the sum
> from 0 to (N-1) { ... }. If the definition is such that the indices are
> -(N-1)/2 to (N-1)/2 { ... } then you shall see the symmetry properties that
> you expect.
>
> Here's a simple code snippet for a very short vector that should show this
> -- I am implementing the DFT but not using Matlab's built in FFT. Here the
> final answer is indeed real as expected.
> -----
> N = 1;
> x = randn(N,1);
> y = [x; randn(); flipud(x)]; % y is even. Indices are -1, 0 and 1
>
> % Implement DFT by writing out the DFT matrix with indices -1, 0 and 1
> % Note Default FFT would have matrices, 1, 2, 3
>
> [exp(-j*2*pi*-1*(0:2)/3).' exp(-j*2*pi*0*(0:2)/3).'
> exp(-j*2*pi*1*(0:2)/3).']*y
>
> On Thu, Mar 5, 2009 at 6:43 AM, arkkimede wrote:
>>
>> The game is not so easy.
>> Which is the bandwidth of the signal that you are sampling?
>> Are you respecting the Nyquist theorem?
>> Using a gaussian noise you can not say anythings about.
>> Use a normal function or if you want visit
>> http://www.mathworks.com/matlabcentral/fileexchange/5654
>> where you can find that the rules that you cite are respected.
>> Bye
>> Daniele
>>
>> On Wed, Mar 4, 2009 at 8:50 AM, wrote:
>> > Help. Where it go wrong?
>> >
>> > Get A N length even symmetric real valued vector ,Fourier transform it
>> > and
>> > result a spectrum vector with the same length N,which the imaginary part
>> > must be zero.
>> > In contrast to that, A N length odd symmetric vector should result that
>> > the
>> > real part of spectrum is zero.
>> >
>> > But I test and perform it and attain a wrong result. Where it go wrong?
>> >
>> > Here is matlab script to illustrate it.
>> >
>> > N = 64;
>> > x = randn(N,1);
>> > y = [x;flipud(x)];
>> > z = [x;-flipud(x)];
>> >
>> > Y t(y);
>> > Z t(z);
>> > [Y,Z]
>> >
>> > Cheers
>> > HyeeWang
>> >
>> >
I think here's a way to look at it. For an even symmetric signal we need
X[n] = X[-n] for all n

In discrete time, if you have an even length signal, you cannot maintain
this property. e.g, if X = [0.234 0.234],
then either X[0] = X[1] or X[1] = X[2] or X[-1] = X[0] depending on whether
you consider your first index to be index 0 or 1 or -1. In no case is X[n]
= X[-n].

If, however, X = [0.234 0.5 0.234], then if you assume your first index is
-1, then indeed X[-1] = X[1] and X[0] = X[0] and thus X[n] = X[-n] for all
n.

A similar argument can be made for odd symmetric signal.

Hence, in discrete time, an even symmetric signal or an odd symmetric signal
only makes sense if the signal vector has an odd number of elements in it.

cheers,
Nandan

On Fri, Mar 6, 2009 at 12:20 AM, arkkimede wrote:

> I have to think about.
> In any case, if the signal is well defined, the result is correct in
> any case (with even or odd number of point).
> Try the code reported using
> 1)
> t=-T/2:dt:T/2-dt
> f=-Fmax:df:Fmax-df;
>
> and
> 2)
> t=-T/2:dt:T/2-dt
> f=-Fmax:df:Fmax-df;
>
> But I do not have all clear in my mind.
> I spent a lot of time with fft and every day a meet a new problem
> Bye Daniele
>
> Bx = 10;
> A = sqrt(log(2))/(2*pi*Bx);
> fs = 500;
> dt = 1/fs;
> T=1;
> %%%%%%%%%%%%%%%%%%%%
> t = -T/2:dt:T/2-dt;
> %%%%%%%%%%%%%%%%%%%%
> length(t)
> df = 1/T;
> Fmax = 1/2/dt;
> %%%%%%%%%%%%%%%%%%%%
> f=-Fmax:df:Fmax-df;
> %%%%%%%%%%%%%%%%%%%%
> taun = 0.055;
> %-------------------------------
>
> %-------------------------------
> % Numerical evaluations
> %-------------------------------
> x = exp(-t.^2/2/A^2);
> X = dt * fftshift(fft(fftshift(x)));
> On Fri, Mar 6, 2009 at 12:11 AM, Nandan Das wrote:
> > Actually here, I don't think you need to worry about the Nyquist theorem
> and
> > using Gaussian noise doesn't hurt you.
> >
> > The question is very simple. If X is a real even symmetric vector, then
> the
> > DFT should be real and it doesn't really matter what the contents of X is
> > (so you could generate X using a randn() command).
> >
> > I think whats happening in h...@yahoo.com.cn 's code are the
> following:
> > a) the vector y and z are of length 128 and the way he's formed them,
> they
> > don't conform to the even (or odd) vector definition. e.g. if y = [0.234
> > 0.234], it is not even. I think you need vectors of odd length to be
> called
> > even (or odd).
> > thus y = [0.234 0 0.234] is an even vector as the indices of y are -1, 0
> and
> > 1 and y(-k) = y(k)
> >
> > b) Secondly, what is happening is that Matlab defines the FFT as the sum
> > from 0 to (N-1) { ... }. If the definition is such that the indices are
> > -(N-1)/2 to (N-1)/2 { ... } then you shall see the symmetry properties
> that
> > you expect.
> >
> > Here's a simple code snippet for a very short vector that should show
> this
> > -- I am implementing the DFT but not using Matlab's built in FFT. Here
> the
> > final answer is indeed real as expected.
> > -----
> > N = 1;
> > x = randn(N,1);
> > y = [x; randn(); flipud(x)]; % y is even. Indices are -1, 0 and 1
> >
> > % Implement DFT by writing out the DFT matrix with indices -1, 0 and 1
> > % Note Default FFT would have matrices, 1, 2, 3
> >
> > [exp(-j*2*pi*-1*(0:2)/3).' exp(-j*2*pi*0*(0:2)/3).'
> > exp(-j*2*pi*1*(0:2)/3).']*y
> >
> >
> >
> > On Thu, Mar 5, 2009 at 6:43 AM, arkkimede wrote:
> >>
> >> The game is not so easy.
> >> Which is the bandwidth of the signal that you are sampling?
> >> Are you respecting the Nyquist theorem?
> >> Using a gaussian noise you can not say anythings about.
> >> Use a normal function or if you want visit
> >> http://www.mathworks.com/matlabcentral/fileexchange/5654
> >> where you can find that the rules that you cite are respected.
> >> Bye
> >> Daniele
> >>
> >> On Wed, Mar 4, 2009 at 8:50 AM, wrote:
> >> > Help. Where it go wrong?
> >> >
> >> > Get A N length even symmetric real valued vector ,Fourier transform it
> >> > and
> >> > result a spectrum vector with the same length N,which the imaginary
> part
> >> > must be zero.
> >> > In contrast to that, A N length odd symmetric vector should result
> that
> >> > the
> >> > real part of spectrum is zero.
> >> >
> >> > But I test and perform it and attain a wrong result. Where it go
> wrong?
> >> >
> >> > Here is matlab script to illustrate it.
> >> >
> >> > N = 64;
> >> > x = randn(N,1);
> >> > y = [x;flipud(x)];
> >> > z = [x;-flipud(x)];
> >> >
> >> > Y t(y);
> >> > Z t(z);
> >> > [Y,Z]
> >> >
> >> > Cheers
> >> > HyeeWang
> >> >