MATLAB: Hello,please could anyone tell me how to graph magnitude and phase spectra for given a .mat file (fs=8 kHz)

magnitude phase spectra

(Answers Dev) Restored Question.

Best Answer

You have a few errors that are easily corrected. I suspect you were getting a ‘Vectors must be the same length’ error in your plot call.
Try this:
y = fft(x)/length(x);
m = abs(y);
p = angle(y);
f = linspace(0, 1, fix(length(y)/2)+1)*Fs/2 % ‘Fs’ Is Your Sampling Frequency
Iv = 1:length(f); % Index Vector
subplot(2,1,1)
plot(f,m(Iv)*2)
title('Magnitude')
grid
subplot(2,1,2)
plot(f,rad2deg(p(Iv)))
title('Phase')
grid
I don’t know what ‘sound.mat’ is, but remember that sound files are typically (Nx2), so bear in mind that there could be two columns, both of which would be processed together in your code. You may have to separate them in your code in that situation.
Please review the documentation for the fft (link) function, especially the code between the first (top) two plot figures.