how can i plot the amplitude spectrum of these signals
조회 수: 24 (최근 30일)
이전 댓글 표시
i need to plot the amplitude spectrum of this signals
and
g(t)=
the first fourier transform is:
and the second one is :
댓글 수: 0
답변 (2개)
Sulaymon Eshkabilov
2021년 7월 12일
Fs = ... % Sampling freq
t = ... % Time
F = 0.25+cos(2*pi*50*t);
L = length(F);
N = 2^nextpow2(L);
Y = fft(F, N);
P2 = abs(Y/L);
P1 = P2(1:L/2+1);
P1(2:end-1) = 2*P1(2:end-1);
f = Fs*(0:(L/2))/L;
plot(f,P1)
title('Single-Sided Amplitude Spectrum of S(t)')
xlabel('f (Hz)')
ylabel('|P1(f)|')
댓글 수: 0
Scott MacKenzie
2021년 7월 12일
편집: Scott MacKenzie
2021년 7월 12일
Do you want the FFT of the combination of the 20 Hz and 50 Hz signals? If so, then this might be the sort of plot you are after:
duration = 1; % seconds
sRate = 8192; % default
sInterval = 1/sRate;
% vector for values of t at each sample point
t = 0:sInterval:duration;
n = length(t); % number of samples
% build the first wave vector, as per question (20 Hz)
y1 = 0.25 + sin(2*pi * 20 * t);
% build the second wave vector, as per question (50 Hz)
y2 = cos(2*pi * 50 * t);
% combine waveforms
y = y1 + y2;
% constrain samples to +/- 1
y = rescale(y, -1, 1);
% perform fast fourier transform
Y = fft(y);
% get amplitude vs. frequency spectrum
P2 = abs(Y/n);
P1 = P2(1:n/2+1);
P1(2:end-1) = 2*P1(2:end-1);
tiledlayout('flow');
% plot signals
nexttile;
plot(y);
set(gca,'ylim', [-1.2 1.2]);
title('Signal');
% plot fft of signals (up to 200 Hz only)
f = sRate*(0:(n/2))/n;
nexttile;
plot(f(1:200),P1(1:200));
title('Frequency Spectrum');
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Fourier Analysis and Filtering에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!