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
P_w
be a vector of complex amplitudes instead of frequencies? How do you buildPn
before applying the formula? For now it's quite hard to answer as this isn't a minimal reproducible example – BillBokeeyP_w
is the frequency domain signal obtained using the first formula. That is the signal that needs to be transformed into time domain, yielding an impulse response. – NCC_MLPn
before applying your formula? This is crucial.. – BillBokeeyP_w
should be a vector whose first value is real and representing the average of your time domain signal, while the rest should be of the form[P1 P2 .... Pm 'Optionnal Nyquist term' conj(Pm) .... conj(P2) conj(P1)]
in order for the IFFT to work – BillBokeeyf
should depend on the FFt size, And it should've negative values (see previous comment) – BillBokeey