# To compute magnitude and phase spectrum

561 views (last 30 days)
Sri Srujan Gollapudi on 3 Oct 2019
Commented: Gerard MacDermott on 14 Sep 2020 at 6:55
Hello,
I have a function, for that I need to find the magnitude and phase spectrum on matlab. Can someone please help me with the code, please?
The parameters are A=2 a=4 -20<=F<=20. This is the function.

Shubham Gupta on 4 Oct 2019
Where is 'F' being used in the function? Also, what do you mean by 'magnitude of the function'?
Sri Srujan Gollapudi on 5 Oct 2019
Even I'm not sure of that. But if we leave out the limits of F, how can I find the magnitude and phase sepctra with given values of A and a for the above fucntion?

Deepak Kumar on 7 Oct 2019
Edited: Deepak Kumar on 11 Oct 2019
I'm not sure what F is referring here.
However, we can find the Magnitude and Phase spectrum of a function using FFT function in matlab. I have wrirren the below code to evalute the magnitude and phase spectrum of the given function and also plotted them.
clc
clear
close all
A=2;
a=4;
fs=1000; % Sampling frequency
t=0:1/fs:1; %Time
x=A*exp(-a.*t); %Signal
plot(t,x) %Plotting the time domain signal
xlabel('t');
ylabel('x(t)');
title('Time domain Signal')
N=length(x);
N1=2^nextpow2(N);
X=fft(x,N1);
X_mag=abs(X); %Magnitude Spectrum
X_phase=phase(X); %Phase Spectrum
f=fs*(0:N1/2-1)/N1; %Frequency axis
figure
plot(f,(X_mag/N1)); %Plotting the Magnitude Spectrum after Normalization
xlabel('Frequency (Hz)');
ylabel('Magnitude Spectrum');
title('Magnitude Spectrum vs f')
figure
plot(f,X_phase); %Plotting the frequency domain
xlabel('Frequency (Hz)');
ylabel('Phase Spectrum');
title('Phase Spectrum vs f')
Please refer the below documentation for more details about the FFT function:

WJ on 13 Aug 2020
Gerard MacDermott on 14 Sep 2020 at 6:55
Hi,
In the line 'X_phase=phase(X); %Phase Spectrum'
what is the 'phase' function? Is this a personal functions? My MATLAB doesn't recognise it? I am using MATLAB 2020.
Cheers,
Gerry