Application of ifft function

3 次查看(过去 30 天)
Martina Gardoni
Martina Gardoni 2016-12-12
I'm trying to apply the inverse FFT function on a wave. I directly gave the velocity recorded signal ('v4b') as input in MATLAB and also its corresponding time vector ('t'). I have applied a filter and the FFT function to the original signal, then I need to come back to the time domain with the ifft function for obtaining the signal without noise. I have a problem in obtaining the inverse FFT because the length of the signal obtained is different from the length of time vector. Someone can help me? Thank you in advance!
Fs = 200;
b = fir1(8800, 1.3/(Fs/2));
load 't.txt';
load 'v4b.txt';
figure(1)
subplot(1,2,1);
plot(t,v4b);
axis([0 2 0 5]);
title('4 blocks, pos.1, setup2:Istantaneous velocity');
xlabel('Time [s]');
ylabel('Velocity [m/s]');
x = filter(b, 1, v4b);
l = length(x);
N = length(v4b);
X = fft(x);
X = X(1:N/2+1);
psdx = (1/(Fs*N))*abs(X).^2;
psdx(2:end-1) = 2*psdx(2:end-1);
freq = 0:Fs/l:Fs/2;
subplot(1,2,2);
loglog (freq,psdx);
title('4 blocks_pos.1_setup2: Power Spectral Density of the Signal');
xlabel('Frequency [Hz]');
ylabel('Power/Frequency [m^2/(Hz*s^2)]');
figure(2)
Y=ifft(X);
plot(t,Y);
After running the warning is: 'Error using plot. Vectors must be the same length.'

回答(1 个)

Kushagr Gupta
Kushagr Gupta 2016-12-19
The error being received is expected as the lengths of variable 't' and 'Y' do not match.
After the line:
>> X = X(1:N/2+1)
is executed, length of 'X' becomes half of length of variables 'x' or 't' and when ifft is performed on 'X', the result 'Y' has same length as 'X' which is half of 't' and thus the error.
There are various ways to avoid this error and as the question asks for accessing the time domain values without noise, one way to do this would be taking the ifft of the vector 'x' instead of 'X'.

标签

Community Treasure Hunt

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

Start Hunting!

Translated by