Asked by Vera
on 20 May 2013

I need to plot x=e^(-t/2*tau) * sin(2*pi*f0*t) and then do the FFT, and IFFT to come back. f0=1 GHz while tau=2 micro secs While evaluating the function x, it gives me all values zero. I dont know why... I am not sure how to set the Fs (sampling frequency) and N (the length). Please help me as soon as you can. Here below some code.

T = 1/200; fs = 1 / T; %fs=150 N = 512; %t=0:T:1; t = (0:N-1) * T;

tau = 2*10^-6; %sec fo=1*10^9; % 1 GHz

x = (exp(1).^( -t./(2*tau) ) ) .* sin(2*pi*fo*t); %exp(1)=e %The DFT approximation to the CTFT is given by X_DFT = T * fft( x ); df = fs / N; f = df .* (0:(N-1)); w = 2 * pi * f; %or for a symmetric spectrum X_DFT2 = fftshift( X_DFT ); f2 = df .* ((-N/2):(N/2-1)); w2 = 2 * pi * f2; %The exact CTFT and DTFT are fa = linspace( 0 , 2 * fs , 1000 ); wa = 2 * pi * fa; fa2 = linspace( -1 * fs , 1 * fs , 1000 ); wa2 = 2 * pi * fa2; X_CTFT = 1.0 ./ ( a + 1i .* wa ); X_CTFT2 = 1.0 ./ ( a + 1i .* wa2 ); X_DTFT = T * 1.0 ./ ( 1 - exp( -1i .* wa .* T) .* exp( -a .* T ) ); X_DTFT2 = fftshift( X_DTFT );

%Plotting the asymmetric transforms

figure( 1 ); plot ( f , abs( X_DFT ) , 'r-o' ); hold on; plot( fa , abs( X_CTFT ) , 'b-' ); plot( fa , abs( X_DTFT ) , 'g-' ); xlabel( 'f (Hz)' ); ylabel( '|X(f)|' ); title( '|X(f)|' ); axis( [ 0 400 0 0.12] ); legend( 'CTFT estimated from DFT' , 'Analytic CTFT' , 'Analytic DTFT' ); hold off; print( 'ft_mag.eps' , '-depsc' );

figure(2); plot(t,x);

Thanks to all for any help you can provide to me.

Answer by Dr. Seis
on 20 May 2013

Accepted Answer

Vera
on 20 May 2013

thanks Elige.

Would you mind if you explain to me how it works in general, based on what I do define the fs.

I am not yet into FFT and IFFT, just started :|

Any clearance might be useful to me.

Dr. Seis
on 20 May 2013

Your tau is a very small number... the smaller tau is the faster your exponential function will fall to zero. The way you have it set up, your sample interval is much, much too big. Between the first and second time sample, your time function has already fallen to (pretty much) zero. So you need to make your T a lot smaller (i.e., 1/(2*10^9)). But when you do this, you will see that your tau is actually quite big for the frequency f0 of your sine wave (it takes many 100s of oscillations before you begin to notice any changes in the amplitude of the sine wave). My suggestion is to be mindful of tau (controls the amplitude falloff), T (controls the interval between time samples), and f0 (center frequency of your sine wave) because these numbers will control whether you see reasonable values (when you populate x)... or no values... or garabage values.

My suggestion is to step back and look at an example of what you are trying to accomplish with values of tau, T, and f0 that are all parameterized appropriately (in a relative sense). For example try:

T = 1/200;

fs = 1 / T;

N = 512;

t = (0:N-1) * T;

tau = .1; %sec

f0=10; % 10 Hz

x = (exp(1).^( -t./(2*tau) ) ) .* sin(2*pi*f0*t);

plot(t,x);

Vera
on 21 May 2013

thanks a lot Elige.

I will definitely step back and look more carefully at all these aspects.

:)

Sign in to comment.

Opportunities for recent engineering grads.

Apply Today
## 2 Comments

## José-Luis (view profile)

Direct link to this comment:https://de.mathworks.com/matlabcentral/answers/76406-how-to-set-the-sampling-frequency-and-the-time-vector-for-an-aperiodic-signal-while-fft-and-ifft#comment_149915

## Vera (view profile)

Direct link to this comment:https://de.mathworks.com/matlabcentral/answers/76406-how-to-set-the-sampling-frequency-and-the-time-vector-for-an-aperiodic-signal-while-fft-and-ifft#comment_149923

Sign in to comment.