MATLAB Answers

Magnitude and phase spectrum of sine wave using FFT

조회 수: 4(최근 30일)
Cynthia Lucy
Cynthia Lucy 2021년 5월 7일
댓글: Cynthia Lucy 2021년 5월 10일
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.

답변(1개)

VBBV
VBBV 2021년 5월 7일
%f tru
subplot(2,1,2);
plot(w(1:plot_FFT_len), 20*log10(abs(fftd./Plength)).*(1:plot_FFT_len));
  댓글 수: 10
Cynthia Lucy
Cynthia Lucy 2021년 5월 10일
@VBBV yes an error came out on command window after I run the latest code saying 'error: product: nonconformant arguments (op1 is 1x1102, op2 is 1x512)'

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by