How to plot the spectrum of the sum of sine waves

23 Ansichten (letzte 30 Tage)
pq
pq am 7 Apr. 2016
Verschoben: Voss am 27 Feb. 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 Kommentare
Joyce
Joyce am 27 Feb. 2024
Verschoben: Voss am 27 Feb. 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 am 27 Feb. 2024
Verschoben: Voss am 27 Feb. 2024

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Rick Rosson
Rick Rosson am 10 Apr. 2016
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