How to plot ifft for a frequency signal?

I've a .dat file (attaching the .mat file of that .dat file after converting, since this platform doesn't allow to upload .dat file while asking question) which represent the frequency spectrum of a vibration signal from a bearing having a sampling frequency of (fs=32768). How to convert the frequency signal to time domain signal. Please help.

3 Comments

Have you tried just passing your frequency-domain data into the ifft function and then plotting the time-domain output of the function?
that is what i'm unable to do so.
Have you tried? Please post the code you've attempted so far.

Sign in to comment.

 Accepted Answer

Yazan
Yazan on 6 Aug 2021
Edited: Yazan on 6 Aug 2021
clc, close all
fs = 32768;
fidx = z.Date23122013;
specOneSide = z.Time100351;
[fidx, idx] = unique(fidx);
specOneSide = specOneSide(idx);
fOneSide = (fidx./fidx(end))*fs/2;
subplot(1,2,1)
plot(fOneSide, specOneSide), xlabel('Frequency - Hz'), ylabel('Magnitude spectrum');
axis tight, title('One-sided spectrum');
specTwoSide = [flip(specOneSide(1:end)); specOneSide(2:end-1)];
N = length(specTwoSide);
f = -fs/2:fs/N:fs/2-fs/N;
subplot(1,2,2)
plot(f, specTwoSide), xlabel('Frequency - Hz'), ylabel('Magnitude spectrum');
axis tight, title('Two-sided spectrum');
sig = ifft(fftshift(specTwoSide));
figure,
t = (0:N-1)./fs;
plot(t, sig), axis tight, title('Signal');
xlabel('Time - sec'), ylabel('Amplitude');

5 Comments

@Yazan. Thanks for providing this code. Very instructive. I'm wondering though, the one-sided frequency spectrum plot goes from 0 to about 2.5 x 10^8 Hz or 250 MHz:
But, the sampling rate was only about 32 kHz. Given this, the frequency spectrum should top out at half that, or about 16 kHz. Is that right, or am I missing something here?
My bad. The vector fOneSide was defined incorrectly. I corrected the code. Thank you Scott!
OK, good. Frequency spectrum looks fine now:
Thank You soo much. But i think there is something wrong with the data generated. Anyways, thank you once again.
Notice that the values of the Date23122013 (or your frequency axis points) are not unique. Also, for one value of Date23122013, you have sometimes multiple values of Time100351. My code uses the first appearing value of Time100351 for a given Date23122013 automatically, which is sometimes zero, but you might prefer otherwise. It is always a good idea to clean your data first.

Sign in to comment.

More Answers (0)

Products

Release

R2021a

Asked:

on 5 Aug 2021

Commented:

on 6 Aug 2021

Community Treasure Hunt

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

Start Hunting!