How to plot phase and amplitude spectrum after doing fourier transform?

746 views (last 30 days)
Bilal on 12 Oct 2013
Answered: rahul jain on 6 Mar 2021
Hello, I am a new MATLAB user. I had a function which I did Fourier Transform for, and the result was: X(w)=1/(1+jw) where w is the frequency and " j " is the known imaginary number. I would like to know what code I should input in MATLAB in order to plot the phase and amplitude spectra of X(w). Thanks in advance...

Answers (4)

sixwwwwww on 12 Oct 2013
Edited: sixwwwwww on 12 Oct 2013
Dear Bilal, You can plot in the following way the amplitude and phase of X:
figure, plot(w, abs(X)), title('Amplitude plot')
figure, plot(w, angle(X)), title('Phase plot')
Good luck!

Sign in to comment.

lakshya wadhwa
lakshya wadhwa on 21 Sep 2020
syms w
X = 1 / (1 + 1j * w);
w_values = 0:100;
X_values = double(subs(X, w, w_values));
figure, plot(w_values, abs(X_values)), title('Amplitude plot'), xlabel('Frequency'), ylabel('Amplitude')
figure, plot(w_values, angle(X_values)), title('Phase plot'), xlabel('Frequency'), ylabel('Phase')

Afshin Aghayan
Afshin Aghayan on 24 Jul 2017
Edited: Afshin Aghayan on 2 Aug 2017
look at the following Matlab function, it can calculate phase spectrum as well as amplitude spectrum with a perfect accuracy:
This program calculates amplitude and phase spectra of an input signal with acceptable accuracy especially in the calculation of phase spectrum.The code does three main jobs for calculation amplitude and phase spectra. First of all, it extends the input signal to infinity; because for calculation Fourier transform(FT) (fft function in Matlab), we consider our signal is periodic with an infinite wavelength, the code creates a super_signal by putting original signal next to itself until the length of super_signal is around 1000000 samples, why did I choose 1000000 samples? Actually, it is just based on try and error!! For most signals that I have tried, a supper signal with 1000000 samples has the best output.
Second, for calculating fft in Matlab you can choose different resolutions, the Mathwork document and help use NFFT=2^nextpow2(length(signal)), it definitely isn't enough for one that wants high accuracy output. Here, I choose the resolution of NFFT=100000 that works for most signals.
Third, the code filters result of FT by thresholding, it is very important step! For calculating phase spectrum, its result is very noisy because of floating rounding off error, it causes during calculation "arctan" even small rounding off error produces significant noise in the result of phase spectrum, for suppressing this kind of noise you can define a threshold value. It means if amplitude of specific frequency is less than predefined threshold value (you must define it) it put zero instead of it.
These three steps help to improve the result of amplitude and phase spectra significantly.
Afshin Aghayan, Priyank Jaiswal, and Hamid Reza Siahkoohi (2016). "Seismic denoising using the redundant lifting scheme." GEOPHYSICS, 81(3), V249-V260.

rahul jain
rahul jain on 6 Mar 2021
hey there,
i am new to matlab and i am stuck at this code that i have to do for research in optical systems.
i have quite a bit of code already which lets me plotthe zernike polynomial and its poin spread function(individually).But what im trying to do is to find a way to plot all of the zernike polynials in a single figure, and in the next figure their PSFs. also how i do i plot the phase of a zernike wavefont.
i will attach my code below, and hopefully someone (perhaps you) knows it better that i do.
any help and recommendations would be deeply appriciated.
close all; clear variables; clc;
d=5000; %eye pupil size in um
feye=22200; %eye axial length (schematic eye model)
neye=1.33; %eye refractive index
lambda=0.55; %wavelength of light in um
%ZERNIKE COEFFICIENTS (organised according to the OSA/ANSI standard)
c1=0; %tilt(in um)
c2=0; %tip (in um)
c3=0; %oblique astigmatism (in um)
c4=0.5; %defocus (in um)
c5=0; %vertical astigmatism (in um)
c6=0; %vertical trefoil (in um)
c7=0; %vertical coma (in um)
c8=0; %horizontal coma (in um)
c9=0; %oblique trefoil (in um)
c10=0; %oblique quadrafoil (in um)
c11=0; %oblique secondary astigmatism (in um)
c12=0; %primary spherical (in um)
c13=0; %vertical secondary astigmatism (in um)
c14=0; %vertical quadrafoil (in um)
cvector=[c1 c2 c3 c4 c5 c6 c7 c8 c9 c10 c11 c12 c13 c14]
%generated rms of wavefront
for ii=1:14
rms=(cvector(ii))^2 + rms;
L1=10000; %pupil image size in um
L2=lambda*pixels*(feye/neye)/L1 %retinal image size in um
wavefront=zeros(pixels,pixels); %Zernike wavefront
pupil=zeros(pixels,pixels); %field in pupil plane with aberrations
refpupil=zeros(pixels,pixels); %reffield in pupil plane without aberrations
psf=zeros(pixels,pixels); %Intensity PSF
reconstructwavefront=zeros(pixels,pixels); %least-square wavefront reconstruction
%calculating the field in the pupil plane
for ii=1:pixels
yy=L1*(ii-pixels/2 -0.5)/pixels;
for jj=1:pixels
xx=L1*(jj-pixels/2 -0.5)/pixels;
rho=sqrt(xx^2 + yy^2);
if rho<=(d/2)
wavefront(ii,jj)=c4*sqrt(3)*(2*(rho0^2) -1)+wavefront(ii,jj);
pupil(ii,jj)=1*exp(1i*(2*pi/lambda)*wavefront(ii,jj)); %converting wavefront to phase
refpupil(ii,jj)=1; %unaberrated reference pupil
dcut=round(pixels*d/L1); %size of non-zero pupil
wf=wavefront(round((pixels-dcut)/2 +1):round((pixels+dcut)/2),round((pixels-dcut)/2 +1):round((pixels+dcut)/2)); %image cut to match pupil
figure(1), imagesc(flipud(wf)), axis square, title('Wavefront [um]'), axis off, colormap('jet'), colorbar;
sensor=rot90(fftshift(fft2(pupil)),2); %field in image sensor plane viewed head-on
intensity=(abs(sensor).^2)/max(max(abs(fftshift(fft2(refpupil)).^2))); %this is the ratio of the aberrated PSF / unaberrated PSF in the image plane
figure(2), imagesc(intensity), axis square, title(append('PSF viewed head-on',' ',mat2str(round(L2)),'x',mat2str(round(L2)),' um2')), axis off, colormap('gray'), colorbar;

Community Treasure Hunt

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

Start Hunting!