How to create fft Magnitude and Phase using stem Matlab?

조회 수: 8 (최근 30일)
sejong sin
sejong sin 2020년 6월 14일
편집: EE_student 2021년 6월 19일
With the function
cos(w0t)
, first create your own time domain data and second, conduct
the FT (Fourier transform). When you solve the problem, use the MATLAB codes with
two “for ~ end” loops without using already built-in functions except for the fundamental
ones such as “linspace” and “cos”. Then draw the result of the FT in frequency domain in
terms of “Magnitude vs. freq.” and “Phase vs. freq.” by using “stem” instead of “plot”.
Here, let’s set w0=2pi/T and T = 1(sec).

답변 (1개)

EE_student
EE_student 2021년 6월 19일
편집: EE_student 2021년 6월 19일
This is the amplitude spectrum for cos(2*pi*1*t) for a 2 second long signal length. I will leave the phase spectrum up to you.
clear
clc
clearAllMemoizedCaches
clear
sampleR= 1000; % sample rate in Hz
t= 0:1/sampleR:2; % time vector
N= length(t); % number of samples
signal= cos(2*pi*1*t); % defining signal
% random dc offset,amplitude and frequency
t_hat= (0:N-1)/N ; % normalised time vector
harmonics= zeros(size(signal)); % empty vector that stores the computed Harmonics
plot(t,signal)
grid on
title('Signal(t)')
xlabel('Time')
ylabel('Amplitude')
for delta_f=1:N
e= exp(-1j*2*pi*(delta_f-1)*t_hat);
harmonics(delta_f)= (sum(signal.*e))/N;
end
freq= linspace(0,sampleR/2,floor(N/2)+1); % scaling frequency
amp= abs(harmonics); % extracting amplitudes and scaling them
amp(2:length(freq)) = 2*amp(2:length(freq)); % double only the ac harmonics
stem(freq,amp(1:length(freq))) % making the vectos same in length
xlim([0 10]) % limits must be included
title('DFT of Signal(t)')
xlabel('Freq/Hz')
ylabel('Amplitude')
grid on

카테고리

Help CenterFile Exchange에서 Fourier Analysis and Filtering에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by