How to plot the spectrum of the sum of sine waves
14 次查看(过去 30 天)
显示 更早的评论
I need to plot the spectrum of the sum of 3 sine waves (100 Hz & 20 dB SPL, 300 Hz& 30 dB SPL, and 400 Hz & 15 dB SPL). This is what I have so far, but the amplitude on the y axis seems wrong.
% Sampling
fs = 1000; % Sampling rate [Hz]
Ts = 1/fs; % Sampling period [s]
fNy = fs / 2; % Nyquist frequency [Hz]
duration = 10; % Duration [s]
t = 0 : Ts : duration-Ts; % Time vector
noSamples = length(t); % Number of samples
A_1 = 20;
A_2 = 30;
A_3 = 15;
f_1 = 100;
f_2 = 300;
f_3 = 400;
s_1 = A_1*sin((2*pi*f_1*t));
s_2 = A_2*sin((2*pi*f_2*t));
s_3 = A_3*sin((2*pi*f_3*t));
% Contaminated signal
xn = s_1+s_2+s_3;
% Frequency analysis
f = 0 : fs/noSamples : fs - fs/noSamples; % Frequency vector
% FFT
x_fft = abs(fft(x));
xn_fft = abs(fft(xn));
% Plot
plot(f,xn_fft);
xlim([0 fNy]);
xlabel('Frequency (Hz)')
ylabel('Amplitude (dB SPL)')
title('{Spectrum}')
回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spectral Measurements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!