Magnitude and phase spectrum of sine wave using FFT

15 views (last 30 days)
I want to display the magnitude and phase spectrum of a signal data using the code below.
load("sec2Harmonics.mat")
Length = numel(x) % The number of elements
fs = 44100;
amp = 1000; % Amplitude (coefficient)
Plength = Length;
plot(x(1:Plength)); % Plot graph
FFT_len = 1024; % 1024 points;
plot_FFT_len = FFT_len/2;
d_proc1 = x(1:FFT_len);
win = ?????
d_proc2 = ?????;
fftd = fft(d_proc2);
delta_f = fs/FFT_len;
n = 0:1:FFT_len-1;
w = delta_f*n;
plot(w(1:plot_FFT_len), 20*log10(abs(?????))(1:plot_FFT_len));
Ive tried to replace the '?????' as below but when I run the code it only display the sine wave. Theres no error on the command window I dont know what is wrong and what should be fixed. Please help me.
Length = numel(x) % The number of elements
fs = 44100;
amp = 1000; % Amplitude (coefficient)
Plength = Length;
subplot(2,1,1);
plot(x(1:Plength)); % Plot graph
FFT_len = 512; % 512 points;
plot_FFT_len = FFT_len/2;
d_proc1 = x(1:FFT_len);
win = 0.5 - 0.5*cos(2*pi*linspace(0, 1, n));
win = (Plength);
d_proc2 = x.*win;
fftd = fft(d_proc2);
delta_f = fs/FFT_len;
n = 0:1:FFT_len-1;
w = delta_f*n;
subplot(2,1,2);
plot(w(1:plot_FFT_len), 20*log10(abs(fft/Plength))(1:plot_FFT_len));
This is the display result that I got.

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!