How to create fft Magnitude and Phase using stem Matlab?
7 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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).
0 comentarios
Respuestas (1)
EE_student
el 19 de Jun. de 2021
Editada: EE_student
el 19 de Jun. de 2021
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
0 comentarios
Ver también
Categorías
Más información sobre Fourier Analysis and Filtering 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!