How to plot the spectrum of the sum of sine waves

234 ビュー (過去 30 日間)
pq
pq 2016 年 4 月 7 日
回答済み: Rick Rosson 2016 年 4 月 10 日
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 件)

Rick Rosson
Rick Rosson 2016 年 4 月 10 日
x_fft = abs(fft(x)/noSamples);
xn_fft = abs(fft(xn)/noSamples);

Community Treasure Hunt

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

Start Hunting!

Translated by