Plotting amplitude spectrum of a signal

24 次查看(过去 30 天)
i got this sygnal
tmax=0.5;
t=0:0.001:tmax;
fs=1000;
tsamp=0:1/fs:tmax;
f1 = 18;
f2 = 321.37;
y = sin(2*pi*f1*tsamp) + sin(2*pi*f2*tsamp);
figure();
plot(t, y);
grid on;
how do I plot it's amplitude spectrum?

采纳的回答

Star Strider
Star Strider 2023-1-8
Try something like this —
tmax=0.5;
t=0:0.001:tmax;
fs=1000;
tsamp=0:1/fs:tmax;
f1 = 18;
f2 = 321.37;
y = sin(2*pi*f1*tsamp) + sin(2*pi*f2*tsamp);
figure();
plot(t, y);
grid on;
L = numel(t);
Fn = fs/2;
NFFT = 2^nextpow2(L);
FTy = fft(y,NFFT)/L;
Fv = linspace(0, 1, NFFT/2+1)*Fn;
Iv = 1:numel(Fv);
figure
plot(Fv, abs(FTy(Iv))*2)
grid on
xlabel('Frequency')
ylabel('Magnitude')
FTyw = fft(y(:).*hann(L),NFFT)/L;
figure
plot(Fv, abs(FTy(Iv))*2)
grid on
xlabel('Frequency')
ylabel('Magnitude')
title('Windowed')
.
  4 个评论
Artyom
Artyom 2023-1-8
it gives me an error in
FTyw = fft(y(:).*hann(L),NFFT)/L;
says "Undefined function 'hann' for input arguments of type 'double'."
could "hann" be replaced somehow?
Star Strider
Star Strider 2023-1-8
The hann function is part of the Signal Processing Toolbox. Just delete that part of my code, and note that it will still be here if you need it for future reference. (My intent was to demonstrate doing a power-of-2 fft and using a window function.)

请先登录,再进行评论。

更多回答(1 个)

Sulaymon Eshkabilov
编辑:Sulaymon Eshkabilov 2023-1-8
tmax=0.5;
t=0:0.001:tmax;
fs=1000;
tsamp=0:1/fs:tmax;
f1 = 18;
f2 = 321.37;
y = sin(2*pi*f1*tsamp) + sin(2*pi*f2*tsamp);
figure();
plot(t, y);
grid on;
Y =movmedian(y, 5); % Amplitude
figure
plot(t,Y)
grid on
xlabel('x')
ylabel('|y(x)|')

类别

Help CenterFile Exchange 中查找有关 Multirate Signal Processing 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by