Using MATLAB to get the fourier transform of dirac delta function

AI Thread Summary
The discussion revolves around using MATLAB to compute the Fourier transform of the Dirac delta function and the effects of changing the time duration in the code. Users express confusion over why the amplitude of the Fourier transform changes when the time range is adjusted, particularly noting that the absolute value of U(f) halves when the time is extended from 2 to 4 seconds. It is clarified that this behavior is linked to the sampling rate and the relationship between time duration and the resulting amplitude in the Fourier transform. Additionally, a similar issue arises when applying the same method to a cosine function, leading to further questions about the underlying principles. Participants suggest that these topics are likely covered in Digital Signal Processing textbooks, particularly in sections related to the sampling theorem and Fourier integrals.
luckycool
Messages
3
Reaction score
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.
 
Physics news on Phys.org
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:
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.
 
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.
 
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?
 
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.
 
Back
Top