Sampled signal spectrum ?

8 次查看(过去 30 天)
nabil noble
nabil noble 2021-1-6
someone knows the matlab program to plot a the spectrum of a sampled signal ; example : signal x(t) ?

回答(1 个)

Suraj Kumar
Suraj Kumar 2025-4-2
Hi Nabil,
To plot the spectrum of a sampled signal in MATLAB, we can use the Fast Fourier Transform (FFT) to convert the time-domain signal into its frequency-domain representation.To learn more about 'fft' function in MATLAB, please refer to the following documentation link: https://www.mathworks.com/help/matlab/ref/fft.html
We can compute the two-sided spectrum and convert it to a single-sided spectrum to get the amplitude of the frequency components. We can define the frequency domain (`f`) for plotting and then visualize the single-sided amplitude spectrum. This will allow us to see the dominant frequencies present in the signal.
You can refer to the attached code snippet for better understanding:
Fs = 400;
T = 1/Fs;
L = 1000;
t = (0:L-1)*T;
f1 = 100;
f2 = 200;
x = 0.5+ cos(2*pi*f1*t) + 2*cos(2*pi*f2*t);
figure;
plot(t, x);
title('Time-Domain Signal');
xlabel('Time (s)');
ylabel('Amplitude');
X = fft(x);
P2 = abs(X/L);
P1 = P2(1:L/2+1);
P1(2:end-1) = 2*P1(2:end-1);
f = Fs*(0:(L/2))/L;
figure;
plot(f, P1);
title('Single-Sided Amplitude Spectrum of x(t)');
xlabel('Frequency (Hz)');
ylabel('|P1(f)|');
Happy Coding!

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by