Using MATLAB to get the fourier transform of dirac delta function

  • Thread starter luckycool
  • Start date
  • #1
3
0

Homework Statement


Dear all,

I have a problem when I using MATLAB to get the fourier transform of dirac delta function. below is my code.


Homework Equations


clear all;
clc;
close all;

% t=0:0.002:2;
t=0:0.002:4;
dt=t(2)-t(1);
u=zeros(size(t));
pos0=find(t>=1,1);
u(pos0)=1/dt;

f=linspace(-.5/dt,.5/dt,length(t));
U=fftshift(fft(u))/length(t);

figure;subplot(2,1,1);hold on;plot(t,u);
subplot(2,1,2);hold on;plot(f,abs(U));


The Attempt at a Solution



I have a doubt that why when I change the end of time to 4, the absolute value of U(f) would be the half when I set the time as 2?

Thank you very much.
 

Answers and Replies

  • #2
492
1
That part's tricky and it took me a looong time to figure it out.
What they're pretty much doing in the examples where you see them divide by L is that they're actually multiplying by the sampling rate dt. It's just that in those examples where they divide by L the time ends at 1s so 1s/length(t) = dt.
 
Last edited:
  • #3
3
0
Thanks so much.

However, if I using this way for cosine function, then it doesn't work again.
u2=1*cos(20*t);
U2=fftshift(fft(u2))*dt;

This time, when I change the time setting, the value of U2 will change.

It's so strange.
 
  • #4
492
1
You mean when you change the end time the value given changes from 0.5 to something else?

Sorry I had that problem too and I don't understand why...

I haven't been able to find an answer to this either, but I know they discuss this topic in Digital Signal Processing classes/books.
 
  • #5
3
0
Hi, thanks again :)

If I change from t(end)=2 to other value then U2(f) will change its amplitude if I use dt instead of length(t).
But it's ok, I will check it with books. Do you know in which book or which section they discuss this topic?
 
  • #6
492
1
Nope sorry, I haven't taken that class yet.
But I think it should be discussed in the same section as the sampling theorem or maybe the fourier integrals.
 

Related Threads on Using MATLAB to get the fourier transform of dirac delta function

Replies
1
Views
627
Replies
3
Views
2K
Replies
0
Views
2K
  • Last Post
Replies
13
Views
6K
Replies
1
Views
4K
  • Last Post
Replies
0
Views
2K
Replies
4
Views
2K
Replies
1
Views
870
Replies
0
Views
1K
Top