0

I'm trying to obtain the time domain signal from an analytic formula in frequency domain, specifically, the formula is:

Formula implemented

The problem arises when implementing an IFFT, since the following impulse response is obtained:

Impulse response

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
Cris Luengo
  • 55,762
  • 10
  • 62
  • 120
NCC_ML
  • 1
  • 1
  • Shouldn't `P_w` be a vector of complex amplitudes instead of frequencies? How do you build `Pn` before applying the formula? For now it's quite hard to answer as this isn't a [mcve] – BillBokeey Jan 03 '17 at 08:45
  • In fact it is. I meant that `P_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_ML Jan 03 '17 at 12:42
  • Right, I'd suggest you change "frequency vector" to "frequency domain vector" in your question to avoid misunderstanding. Now how do you build `Pn` before applying your formula? This is crucial.. – BillBokeey Jan 03 '17 at 12:54
  • For example, `P_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 – BillBokeey Jan 03 '17 at 12:56
  • Also, the upper bound of your frequency vector `f` should depend on the FFt size, And it should've negative values (see previous comment) – BillBokeey Jan 03 '17 at 13:01
  • You mean `P_w = [P_w , conj(fliplr(P_w))]` with a frequency vector defined as `f = 0:df:Fs/2` used to calculate P_w up to Nyquist Frequency? Then the vector df will be `df = (Fs/2)/Nfft` with `Nfft` the size of the FFT? Thanks for your help in advance. – NCC_ML Jan 04 '17 at 14:52
  • Or just calculate the response using `f = -Fs/2:df:Fs/2` with `df = Fs/Nfft` – NCC_ML Jan 04 '17 at 14:54

1 Answers1

0

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];

KKS
  • 1,389
  • 1
  • 14
  • 33
  • I've made a mistake in the frequency vector, actually I get the same 'error' starting from 0Hz. Anyway, thank you very much! – NCC_ML Jan 03 '17 at 02:15