hello,please could anyone tell me how to graph magnitude and phase spectra for given a .mat file (fs=8 kHz)
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
mehmet baki
el 15 de En. de 2017
Editada: mehmet baki
el 20 de En. de 2017
clc clear all close all load a_sound.mat a x=a; y = fft(x); m = abs(y); p = angle(y); f = (0:length(y)-1)*50/length(y); subplot(2,1,1) plot(f,m) title('Magnitude') subplot(2,1,2) plot(f,rad2deg(p)) title('Phase')
1 comentario
Respuesta aceptada
Star Strider
el 15 de En. de 2017
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.
4 comentarios
Star Strider
el 15 de En. de 2017
You do not need to change anything with my code.
If my Answer solves your problem, please Accept it!
Más respuestas (0)
Ver también
Categorías
Más información sobre Spectral Measurements en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!