I need help with fourier transform

I need help, I was wondering if matlab can do Fourier transforms?
I am trying to transform the following functions:
f(t)=K*t.*(u(t+a/2)-u(t-a/2));
f(t)=A*cos(pi*t/2).*(u(t+2)-u(t-2));
f(t)=A*exp(-2*(t-1)).*u(t-1);
Anything would help. Thank you.

 Accepted Answer

Youssef  Khmou
Youssef Khmou on 12 Apr 2013
Edited: Youssef Khmou on 12 Apr 2013
hi, John,
You can compute theirs spectrums , the only thing you need is the sample rate , here is an example :
1) Functions :
% Constants
K=2.33;
A=1.45;
Fs=20;
t=0:1/Fs:10;
a=0.45;
% Anonymous function
u=@(t) cos(t)
f1=K*t.*(u(t+a/2)-u(t-a/2));
f2=A*cos(pi*t/2).*(u(t+2)-u(t-2));
f3=A*exp(-2*(t-1)).*u(t-1);
figure, plot(t,f1,t,f2,'r',t,f3,'g'), legend('f1','f2','f3');
grid on,
2) Spectrums :
n=length(f1); % they all have the same length ..
N=ceil(log2(n));
F1=fft(f1,2^N);
F2=fft(f2,2^N);
F3=fft(f3,2^N);
Freq=(Fs/2^N)*(0:2^(N-1)-1);
figure,
plot(Freq,abs(F1(1:end/2))), xlabel(' Frequ in Hz'), title(' F1');
figure,
plot(Freq,abs(F2(1:end/2))), xlabel(' Frequ in Hz'), title(' F2');
figure,
plot(Freq,abs(F3(1:end/2))), xlabel(' Frequ in Hz'), title(' F3');

More Answers (1)

Categories

Find more on Fourier Analysis and Filtering in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!