Skip to Main Content Skip to Search
Login
File Exchange
MATLAB Newsgroup
Link Exchange
  Blogs  
 Contest 
MathWorks.com

Thread Subject: time and frequency domain

Subject: time and frequency domain

From: beda meda

Date: 10 May, 2008 09:59:05

Message: 1 of 14

Hi,
I need to do this: I want to draw Hamming window in time and
frequency domain. In time domain it is simple, I just write
hamming(256) and plot. But I can't find function to view the
same in frequency domain. You can see what I want at:
http://www.fit.vutbr.cz/~cernocky/speech/opora/zre_opora.pdf
page 38, chapter 5.3.2, pictures on the right.
Thanks for help.

Subject: Re: time and frequency domain

From: Lars

Date: 10 May, 2008 10:38:03

Message: 2 of 14

I don't have the chzech-toolbox installed. Sorry!

Subject: Re: time and frequency domain

From: jay vaughan

Date: 10 May, 2008 16:34:02

Message: 3 of 14

"Lars " <mustermann.klaus.TO.REMOVE@gmx.de> wrote in message
<g03tua$bpi$1@fred.mathworks.com>...
> I don't have the chzech-toolbox installed. Sorry!

Try this.

f1 = zeros(1,512);
f1(128:383) = hamming(256);

f2 = zeros(1,512);
f2(128:383) = 1;

fft_f1 = fftshift(fft(f1,2048));
fft_f2 = fftshift(fft(f2,2048));

subplot(2,2,3); plot(f1);
subplot(2,2,1); plot(f2);
subplot(2,2,4); plot(abs(fft_f1)); xlim([896 1151])
subplot(2,2,2); plot(abs(fft_f2)); xlim([896 1151])

J

Subject: Re: time and frequency domain

From: beda meda

Date: 10 May, 2008 19:29:05

Message: 4 of 14

"jay vaughan" <jvaughan5.nospam@gmail.com> wrote in message
<g04ipq$nbi$1@fred.mathworks.com>...
> "Lars " <mustermann.klaus.TO.REMOVE@gmx.de> wrote in message
> <g03tua$bpi$1@fred.mathworks.com>...
> > I don't have the chzech-toolbox installed. Sorry!
>
> Try this.
>
> f1 = zeros(1,512);
> f1(128:383) = hamming(256);
>
> f2 = zeros(1,512);
> f2(128:383) = 1;
>
> fft_f1 = fftshift(fft(f1,2048));
> fft_f2 = fftshift(fft(f2,2048));
>
> subplot(2,2,3); plot(f1);
> subplot(2,2,1); plot(f2);
> subplot(2,2,4); plot(abs(fft_f1)); xlim([896 1151])
> subplot(2,2,2); plot(abs(fft_f2)); xlim([896 1151])
>
> J

Thank you SO MUCH!

Subject: Re: time and frequency domain

From: Chen Sagiv

Date: 10 May, 2008 19:58:02

Message: 5 of 14

Hi,

It is not important when you plot the abs of the FT, but
shouldn't you use instead:

> f1 = zeros(1,512);
> f1(128:383) = hamming(256);
>
> f2 = zeros(1,512);
> f2(128:383) = 1;
>
> fft_f1 = fftshift(fft(ifftshift(f1),2048));
> fft_f2 = fftshift(fft(ifftshift(f2),2048));
>
> subplot(2,2,3); plot(f1);
> subplot(2,2,1); plot(f2);
> subplot(2,2,4); plot(abs(fft_f1)); xlim([896 1151])
> subplot(2,2,2); plot(abs(fft_f2)); xlim([896 1151])


Best,

Chen
"jay vaughan" <jvaughan5.nospam@gmail.com> wrote in message
<g04ipq$nbi$1@fred.mathworks.com>...
> "Lars " <mustermann.klaus.TO.REMOVE@gmx.de> wrote in
message
> <g03tua$bpi$1@fred.mathworks.com>...
> > I don't have the chzech-toolbox installed. Sorry!
>
> Try this.
>
> f1 = zeros(1,512);
> f1(128:383) = hamming(256);
>
> f2 = zeros(1,512);
> f2(128:383) = 1;
>
> fft_f1 = fftshift(fft(f1,2048));
> fft_f2 = fftshift(fft(f2,2048));
>
> subplot(2,2,3); plot(f1);
> subplot(2,2,1); plot(f2);
> subplot(2,2,4); plot(abs(fft_f1)); xlim([896 1151])
> subplot(2,2,2); plot(abs(fft_f2)); xlim([896 1151])
>
> J

Subject: Re: time and frequency domain

From: Greg Heath

Date: 10 May, 2008 22:47:24

Message: 6 of 14

On May 10, 3:58=A0pm, "Chen Sagiv" <chensagiv...@gmail.com> wrote:
> Hi,
>
> It is not important when you plot the abs of the FT, but
> shouldn't you use instead:
>
> > f1 =3D zeros(1,512);
> > f1(128:383) =3D hamming(256);
>
> > f2 =3D zeros(1,512);
> > f2(128:383) =3D 1;
>
> > fft_f1 =3D fftshift(fft(ifftshift(f1),2048));
> > fft_f2 =3D fftshift(fft(ifftshift(f2),2048));

Absolutely not!

Hope this helps.

Greg

Subject: Re: time and frequency domain

From: Chen Sagiv

Date: 11 May, 2008 11:00:22

Message: 7 of 14

Hi Greg,

No, it doesn't help. Can you explain your very short
response ?

Thanks,

Chen

Greg Heath <heath@alumni.brown.edu> wrote in message
<3c59d7c3-618b-44c2-816a-
b58be9319b4d@24g2000hsh.googlegroups.com>...
> On May 10, 3:58=A0pm, "Chen Sagiv"
<chensagiv...@gmail.com> wrote:
> > Hi,
> >
> > It is not important when you plot the abs of the FT, but
> > shouldn't you use instead:
> >
> > > f1 =3D zeros(1,512);
> > > f1(128:383) =3D hamming(256);
> >
> > > f2 =3D zeros(1,512);
> > > f2(128:383) =3D 1;
> >
> > > fft_f1 =3D fftshift(fft(ifftshift(f1),2048));
> > > fft_f2 =3D fftshift(fft(ifftshift(f2),2048));
>
> Absolutely not!
>
> Hope this helps.
>
> Greg

Subject: Re: time and frequency domain

From: Greg Heath

Date: 11 May, 2008 12:30:42

Message: 8 of 14

Corrected for the unforgivable sin of TOP-POSTING!

On May 11, 7:00=A0am, "Chen Sagiv" <chensagiv...@gmail.com> wrote:
> Greg Heath <he...@alumni.brown.edu> wrote in message
>
> <3c59d7c3-618b-44c2-816a-
> b58be9319...@24g2000hsh.googlegroups.com>...
>
> > On May 10, 3:58=3DA0pm, "Chen Sagiv"
> <chensagiv...@gmail.com> wrote:
> > > Hi,
>
> > > It is not important when you plot the abs of the FT, but
> > > shouldn't you use instead:
>
> > > > f1 =3D3D zeros(1,512);
> > > > f1(128:383) =3D3D hamming(256);
>
> > > > f2 =3D3D zeros(1,512);
> > > > f2(128:383) =3D3D 1;
>
> > > > fft_f1 =3D3D fftshift(fft(ifftshift(f1),2048));
> > > > fft_f2 =3D3D fftshift(fft(ifftshift(f2),2048));
>
> > Absolutely not!
>
> > Hope this helps.

> Hi Greg,
>
> No, it doesn't help. Can you explain your very short
> response ?

There is no point to using ifftshift.

When I ran your code the spectra exhibted hashy
artifacts.

Did you cut what you wrote, paste it into a command
 line, and compare the plots with the originals??

The results are obviously incorrect.

Hope this helps.

Greg

Subject: Re: time and frequency domain

From: Chen Sagiv

Date: 11 May, 2008 13:26:03

Message: 9 of 14

Dear Greg,

I refer you to a previous discussion at:

http://www.mathworks.com/matlabcentral/newsreader/view_threa
d/168642#430044

Chen

Greg Heath <heath@alumni.brown.edu> wrote in message
<97e5fc3c-ddbc-4c0c-abd9-
c52e9a3ea38c@s50g2000hsb.googlegroups.com>...
> Corrected for the unforgivable sin of TOP-POSTING!
>
> On May 11, 7:00=A0am, "Chen Sagiv"
<chensagiv...@gmail.com> wrote:
> > Greg Heath <he...@alumni.brown.edu> wrote in message
> >
> > <3c59d7c3-618b-44c2-816a-
> > b58be9319...@24g2000hsh.googlegroups.com>...
> >
> > > On May 10, 3:58=3DA0pm, "Chen Sagiv"
> > <chensagiv...@gmail.com> wrote:
> > > > Hi,
> >
> > > > It is not important when you plot the abs of the
FT, but
> > > > shouldn't you use instead:
> >
> > > > > f1 =3D3D zeros(1,512);
> > > > > f1(128:383) =3D3D hamming(256);
> >
> > > > > f2 =3D3D zeros(1,512);
> > > > > f2(128:383) =3D3D 1;
> >
> > > > > fft_f1 =3D3D fftshift(fft(ifftshift(f1),2048));
> > > > > fft_f2 =3D3D fftshift(fft(ifftshift(f2),2048));
> >
> > > Absolutely not!
> >
> > > Hope this helps.
>
> > Hi Greg,
> >
> > No, it doesn't help. Can you explain your very short
> > response ?
>
> There is no point to using ifftshift.
>
> When I ran your code the spectra exhibted hashy
> artifacts.
>
> Did you cut what you wrote, paste it into a command
> line, and compare the plots with the originals??
>
> The results are obviously incorrect.
>
> Hope this helps.
>
> Greg

Subject: Re: time and frequency domain

From: Chen Sagiv

Date: 11 May, 2008 13:30:22

Message: 10 of 14

Greg Heath <heath@alumni.brown.edu> wrote in message
<97e5fc3c-ddbc-4c0c-abd9-
c52e9a3ea38c@s50g2000hsb.googlegroups.com>...
> Corrected for the unforgivable sin of TOP-POSTING!
>
> On May 11, 7:00=A0am, "Chen Sagiv"
<chensagiv...@gmail.com> wrote:
> > Greg Heath <he...@alumni.brown.edu> wrote in message
> >
> > <3c59d7c3-618b-44c2-816a-
> > b58be9319...@24g2000hsh.googlegroups.com>...
> >
> > > On May 10, 3:58=3DA0pm, "Chen Sagiv"
> > <chensagiv...@gmail.com> wrote:
> > > > Hi,
> >
> > > > It is not important when you plot the abs of the
FT, but
> > > > shouldn't you use instead:
> >
> > > > > f1 =3D3D zeros(1,512);
> > > > > f1(128:383) =3D3D hamming(256);
> >
> > > > > f2 =3D3D zeros(1,512);
> > > > > f2(128:383) =3D3D 1;
> >
> > > > > fft_f1 =3D3D fftshift(fft(ifftshift(f1),2048));
> > > > > fft_f2 =3D3D fftshift(fft(ifftshift(f2),2048));
> >
> > > Absolutely not!
> >
> > > Hope this helps.
>
> > Hi Greg,
> >
> > No, it doesn't help. Can you explain your very short
> > response ?
>
> There is no point to using ifftshift.
>
> When I ran your code the spectra exhibted hashy
> artifacts.
>
> Did you cut what you wrote, paste it into a command
> line, and compare the plots with the originals??
>
> The results are obviously incorrect.
>
> Hope this helps.
>
> Greg

Hi again,

As a new member to the newsgroup, I just realized what you
meant by top-posting. I do hope this will be the worst sin
in my life, but I will try to avoid it from now on.

Best,

Chen

Subject: Re: time and frequency domain

From: Greg Heath

Date: 11 May, 2008 20:47:07

Message: 11 of 14

On May 11, 9:26=A0am, "Chen Sagiv" <chensagiv...@gmail.com> wrote:
> Greg Heath <he...@alumni.brown.edu> wrote in message
>
> <97e5fc3c-ddbc-4c0c-abd9-
> c52e9a3ea...@s50g2000hsb.googlegroups.com>...
>
> > Corrected for the unforgivable sin of TOP-POSTING!
>
> > On May 11, 7:00=3DA0am, "Chen Sagiv"
> <chensagiv...@gmail.com> wrote:
> > > Greg Heath <he...@alumni.brown.edu> wrote in message
>
> > > <3c59d7c3-618b-44c2-816a-
> > > b58be9319...@24g2000hsh.googlegroups.com>...
>
> > > > On May 10, 3:58=3D3DA0pm, "Chen Sagiv"
> > > <chensagiv...@gmail.com> wrote:
> > > > > Hi,
>
> > > > > It is not important when you plot the abs of the
> FT, but
> > > > > shouldn't you use instead:
>
> > > > > > f1 =3D3D3D zeros(1,512);
> > > > > > f1(128:383) =3D3D3D hamming(256);
>
> > > > > > f2 =3D3D3D zeros(1,512);
> > > > > > f2(128:383) =3D3D3D 1;
>
> > > > > > fft_f1 =3D3D3D fftshift(fft(ifftshift(f1),2048));
> > > > > > fft_f2 =3D3D3D fftshift(fft(ifftshift(f2),2048));
>
> > > > Absolutely not!
>
> > > > Hope this helps.
>
> > > Hi Greg,
>
> > > No, it doesn't help. Can you explain your very short
> > > response ?
>
> > There is no point to using ifftshift.
>
> > When I ran your code the spectra exhibted hashy
> > artifacts.
>
> > Did you cut what you wrote, =A0paste it into a command
> > =A0line, and compare the plots with the originals??
>
> > The results are obviously incorrect.

> Dear Greg,
>
> I refer you to a previous discussion at:
>
> http://www.mathworks.com/matlabcentral/newsreader/view_threa
> d/168642#430044

Let me repeat

When I ran your code the spectra exhibted hashy
artifacts. Did you actually run it??

I read the reference thread. What is your point?

Greg

P.S. You may want to take a look at

fftshift([0 1 2 3 4 5 6 7])
ifftshift([0 1 2 3 4 5 6 7])
fftshift([0 1 2 3 4 5 6 7 8])
ifftshift([0 1 2 3 4 5 6 7 8])

Subject: Re: time and frequency domain

From: Chen Sagiv

Date: 12 May, 2008 08:13:03

Message: 12 of 14

Greg Heath <heath@alumni.brown.edu> wrote in message
<0d25ec05-ce98-47fa-868e-
d33bb49dfec8@f36g2000hsa.googlegroups.com>...
> On May 11, 9:26=A0am, "Chen Sagiv"
<chensagiv...@gmail.com> wrote:
> > Greg Heath <he...@alumni.brown.edu> wrote in message
> >
> > <97e5fc3c-ddbc-4c0c-abd9-
> > c52e9a3ea...@s50g2000hsb.googlegroups.com>...
> >
> > > Corrected for the unforgivable sin of TOP-POSTING!
> >
> > > On May 11, 7:00=3DA0am, "Chen Sagiv"
> > <chensagiv...@gmail.com> wrote:
> > > > Greg Heath <he...@alumni.brown.edu> wrote in message
> >
> > > > <3c59d7c3-618b-44c2-816a-
> > > > b58be9319...@24g2000hsh.googlegroups.com>...
> >
> > > > > On May 10, 3:58=3D3DA0pm, "Chen Sagiv"
> > > > <chensagiv...@gmail.com> wrote:
> > > > > > Hi,
> >
> > > > > > It is not important when you plot the abs of the
> > FT, but
> > > > > > shouldn't you use instead:
> >
> > > > > > > f1 =3D3D3D zeros(1,512);
> > > > > > > f1(128:383) =3D3D3D hamming(256);
> >
> > > > > > > f2 =3D3D3D zeros(1,512);
> > > > > > > f2(128:383) =3D3D3D 1;
> >
> > > > > > > fft_f1 =3D3D3D fftshift(fft(ifftshift
(f1),2048));
> > > > > > > fft_f2 =3D3D3D fftshift(fft(ifftshift
(f2),2048));
> >
> > > > > Absolutely not!
> >
> > > > > Hope this helps.
> >
> > > > Hi Greg,
> >
> > > > No, it doesn't help. Can you explain your very short
> > > > response ?
> >
> > > There is no point to using ifftshift.
> >
> > > When I ran your code the spectra exhibted hashy
> > > artifacts.
> >
> > > Did you cut what you wrote, =A0paste it into a command
> > > =A0line, and compare the plots with the originals??
> >
> > > The results are obviously incorrect.
>
> > Dear Greg,
> >
> > I refer you to a previous discussion at:
> >
> >
http://www.mathworks.com/matlabcentral/newsreader/view_threa
> > d/168642#430044
>
> Let me repeat
>
> When I ran your code the spectra exhibted hashy
> artifacts. Did you actually run it??
>
> I read the reference thread. What is your point?
>
> Greg
>
> P.S. You may want to take a look at
>
> fftshift([0 1 2 3 4 5 6 7])
> ifftshift([0 1 2 3 4 5 6 7])
> fftshift([0 1 2 3 4 5 6 7 8])
> ifftshift([0 1 2 3 4 5 6 7 8])

Hi Greg,

I ran the code, and indeed it looks nasty.
My point is however very simple.

If you take the code suggested in the beginning of this all
discussion and display the imaginary rather the abs value
you will get a phase, which you should be aware of if you
account for the real and imaginary values of the FT
separately. This is my point !

Try out:

f1 = zeros(1,512);
f1(128:383) = hamming(256);

f2 = zeros(1,512);
f2(128:383) = 1;

fft_f1 = fftshift(fft(f1,2048));
fft_f2 = fftshift(fft(f2,2048));

subplot(2,2,3); plot(f1);
subplot(2,2,1); plot(f2);
subplot(2,2,4); plot(imag(fft_f1)); xlim([896 1151])
subplot(2,2,2); plot(imag(fft_f2)); xlim([896 1151])

Best,

Chen

Subject: Re: time and frequency domain

From: Greg Heath

Date: 13 May, 2008 00:09:18

Message: 13 of 14

On May 12, 4:13 am, "Chen Sagiv" <chensagiv...@gmail.com> wrote:
> -----SNIP
> If you take the code suggested in the beginning of this all
> discussion and display the imaginary rather the abs value
> you will get a phase, which you should be aware of if you
> account for the real and imaginary values of the FT
> separately. This is my point !

There are two impotant points:

1. The difference between the fft of x1(t) and
   x2(t) = x(t-t0) is a complex multiplier linear
   phase shift exp(-2*pi*f*t0). Therefore, if
   X1 = fft(x1) is real, X2 = fft(x2) will be
   complex.
2. The fft of a zero padded version of x will also
   be complex.

close all, clear all, clc, k=0

x0 = ones(1,16);
x1 = [ones(1,16) zeros(1,16)];
x2 = [zeros(1,8) ones(1,16) zeros(1,8)];
x3 = [zeros(1,16) ones(1,16)];

k=k+1,figure(k)

subplot(2,2,1); plot(x0); axis([-5 35 -0.1 1.1])
subplot(2,2,2); plot(x1); axis([-5 35 -0.1 1.1])
subplot(2,2,3); plot(x2); axis([-5 35 -0.1 1.1])
subplot(2,2,4); plot(x3); axis([-5 35 -0.1 1.1])

X0 = fftshift(fft(x0));
X1 = fftshift(fft(x1));
X2 = fftshift(fft(x2));
X3 = fftshift(fft(x3));

k=k+1,figure(k)
subplot(2,2,1); plot(imag(X0)); axis([-5 35 -11 11])
subplot(2,2,2); plot(imag(X1)); axis([-5 35 -11 11])
subplot(2,2,3); plot(imag(X2)); axis([-5 35 -11 11])
subplot(2,2,4); plot(imag(X3)); axis([-5 35 -11 11])

Hope this helps,

Greg

Subject: Re: time and frequency domain

From: Chen Sagiv

Date: 14 May, 2008 06:27:02

Message: 14 of 14

Greg Heath <heath@alumni.brown.edu> wrote in message
<08b54431-1628-4ae0-9506-
1ed9fe6469c3@f36g2000hsa.googlegroups.com>...
> On May 12, 4:13 am, "Chen Sagiv" <chensagiv...@gmail.com>
wrote:
> > -----SNIP
> > If you take the code suggested in the beginning of this
all
> > discussion and display the imaginary rather the abs
value
> > you will get a phase, which you should be aware of if
you
> > account for the real and imaginary values of the FT
> > separately. This is my point !
>
> There are two impotant points:
>
> 1. The difference between the fft of x1(t) and
> x2(t) = x(t-t0) is a complex multiplier linear
> phase shift exp(-2*pi*f*t0). Therefore, if
> X1 = fft(x1) is real, X2 = fft(x2) will be
> complex.
> 2. The fft of a zero padded version of x will also
> be complex.
>
> close all, clear all, clc, k=0
>
> x0 = ones(1,16);
> x1 = [ones(1,16) zeros(1,16)];
> x2 = [zeros(1,8) ones(1,16) zeros(1,8)];
> x3 = [zeros(1,16) ones(1,16)];
>
> k=k+1,figure(k)
>
> subplot(2,2,1); plot(x0); axis([-5 35 -0.1 1.1])
> subplot(2,2,2); plot(x1); axis([-5 35 -0.1 1.1])
> subplot(2,2,3); plot(x2); axis([-5 35 -0.1 1.1])
> subplot(2,2,4); plot(x3); axis([-5 35 -0.1 1.1])
>
> X0 = fftshift(fft(x0));
> X1 = fftshift(fft(x1));
> X2 = fftshift(fft(x2));
> X3 = fftshift(fft(x3));
>
> k=k+1,figure(k)
> subplot(2,2,1); plot(imag(X0)); axis([-5 35 -11 11])
> subplot(2,2,2); plot(imag(X1)); axis([-5 35 -11 11])
> subplot(2,2,3); plot(imag(X2)); axis([-5 35 -11 11])
> subplot(2,2,4); plot(imag(X3)); axis([-5 35 -11 11])
>
> Hope this helps,
>
> Greg
>

Hi Greg,

Thanks for the example.

Chen

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.

rssFeed for this Thread

envelope graphic E-mail this page to a colleague

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.
Related Topics