How to plot the spectrum of the sum of sine waves

34 visualizaciones (últimos 30 días)
pq
pq el 7 de Abr. de 2016
Movida: Voss el 27 de Feb. de 2024
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}')
  2 comentarios
Joyce
Joyce el 27 de Feb. de 2024
Movida: Voss el 27 de Feb. de 2024
Generate a composite signal by summing 2 sine waves of frequencies 100HZ and 300 HZ APPLY FFT components write matlab program to plot magnitude spectrum
Voss
Voss el 27 de Feb. de 2024
Movida: Voss el 27 de Feb. de 2024

Iniciar sesión para comentar.

Respuestas (1)

Rick Rosson
Rick Rosson el 10 de Abr. de 2016
x_fft = abs(fft(x)/noSamples);
xn_fft = abs(fft(xn)/noSamples);

Categorías

Más información sobre Spectral Measurements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by