I'm trying to obtain the time domain signal from an analytic formula in frequency domain, specifically, the formula is:
The problem arises when implementing an IFFT, since the following impulse response is obtained:
It is clear that the first part seems to be ok, however, there is a high level of noise and an increasing 'slope' as the signal comes to an end.
Now, when starting in frequency domain, I'm defining a frequency vector, with frequency resolution based on the size of the FFT.
%% Sampling Frequency + Size FFt
Fs = 512; %Sampling Frequency
Nfft = 2^12; %FFT Size
df = Fs/Nfft; %Frequency Resolution
f = 0:df:180; %Frequency Vector
Then the formula is applied and a frequency vector is obtained. Later an IFFT of size NFFT is applied:
%%Obtain impulse response
x = ifft(P_w,Nfft); %P_w is obtained by formula (1)
t = (0:(length(x)-1))/Fs; %Time Vector
As soon as I plot the real part of x
, the result obtained in image 2 is seen.
Is there any advice on how to overcome this?
I mean, I shouldn't be getting that last 'noisy' portion of the signal or am I omitting an error in the code?
EDIT:
I've made a mistake in the frequency vector, actually, it starts from 0:
f = 0:df:180; %Frequency Vector
In my guess, you missed zero-pad on low frequency range under 5Hz, if your P_w is started from 5Hz.
Supposing my guess is right, plz, put 40 zeros in front of P_w before ifft.
40 zeros correspond to 0Hz~4.875Hz range, since df=0.125.
If P_w is column vector :
P_w=[zeros(40,1);P_w];
If P_w is row vector :
P_w=[zeros(1,40) P_w];