Fourier Transform of a Signal

1 次查看(过去 30 天)
Inspired by the codes written by Sulaymon Eshkabilov, I created such a code block. But I can't get an output like below, where could the error be?
clear all
close all
clc
t = 0 : 0.001 : 2;
x = exp(-t).*(cos(10*t) + cos(30*t)).*unit(t);
L = numel(x);
Y = fft(x);
M2 = abs(Y/L);
M1 = M2(1:L/2+1);
M1(2:end-1) = 2*M1(2:end-1);
dt=.001;
Fs = 1/dt;
f = Fs*(0:(L/2))/L;
subplot(2,1,1)
plot(t,x)
grid
title({'2exp(-4t)sin(10t)heaviside(t)'})
xlabel('Time (sec)')
ylabel('(x)t')
subplot(212)
plot(f, abs(M1))
xlim([0, 50])
ylim([0, 0.4])
grid on
title({'Amplitude Spectrum'})
xlabel('Frequency (rad/sec)')
ylabel('|X(w)|')
function y = unit(x)
y = zeros(size(x));
y(x>=0) = 1;
end
Desired output;

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Spectral Measurements 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by