# how to convert pressure versus time to pressure versus frequency using fft function

8 views (last 30 days)
zein on 23 Apr 2020
Edited: Mehmed Saad on 23 Apr 2020
I have tried to convert pressure versus time data to pressure versus frequency using FFT function
This is the pressure versus time signal
after using fft
deltaT=2.5e-6;
fs=1/deltaT;
pxx0 = fft(p);
n = length(p); % number of samples
f = (0:n-1)*(fs/n); % frequency range
mag=abs(pxx0);
figure(1)
semilogx(f,mag)
ylabel ('magnitude');
xlabel ('frequency');
This is the output of FFT function
How to convert the magnitude of FFT to corresponding pressure value like this graph ? in form of pressure versus frequency
##### 2 CommentsShowHide 1 older comment
zein on 23 Apr 2020
I do not understand your answer?in my case if i got the results as magnitude domain, how can i convert it to pressure?

Mehmed Saad on 23 Apr 2020
Edited: Mehmed Saad on 23 Apr 2020
• set xlim between 30 and 1e6
• set you xtick as [30 300 3e3 3e4 3e5]
• turn off xMinorTick
• turn off xMinorGrid
• turn on grid
• change linewidth to 1.5
Although it looks like window is also applied on the pressure data and fft size is also greater than the size of signal (next2pow is used)
Mehmed Saad on 23 Apr 2020
Edited: Mehmed Saad on 23 Apr 2020
fs = 1000;
t = 0:1/fs:1-1/fs;
s = exp(2j*pi*10*t);
L = length(s);
n = 2^nextpow2(L);
Y = fft(s,n);
Pp = abs(Y)/L;
figure,plot(Pp)
s = real(s);
Y = fft(s,n);
Pp = abs(Y)/L;
figure,plot(Pp)
Pp = abs(Y)/L*2; % because we take fft of real componnet only
figure,plot(Pp)