Borrar filtros
Borrar filtros

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)
    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')

Respuesta aceptada

Star Strider
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
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!

Iniciar sesión para comentar.

Más respuestas (0)

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!

Translated by