Search code examples
matlabplotsignal-processingfftfrequency-domain

How to plot the magnitude and phase of a frequency?


I was reading Practical Introduction to Frequency Domain Analysis. It shows how to observe the frequency content of a signal using this code:

Fs = 44100;
y = audioread('guitartune.wav');

NFFT = length(y);
Y = fft(y,NFFT);
F = ((0:1/NFFT:1-1/NFFT)*Fs).';

magnitudeY = abs(Y);        % Magnitude of the FFT
phaseY = unwrap(angle(Y));  % Phase of the FFT

helperFrequencyAnalysisPlot1(F,magnitudeY,phaseY,NFFT)

The function that plots is the helperFrequencyAnalysisPlot1. I need to know how the function does the plotting but the article never shows how. How is it actually done?


Solution

  • These are Matlab built-in examples so you have to type in the Command Window

    edit('helperFrequencyAnalysisPlot1.m')
    

    A new Matlab editor tab will pop up, showing you the function (both its definition and the code).