I can't make sense of the amplitude spectrum of a signal. Help please.

3 次查看(过去 30 天)
Hi,
I have a sinusoidal signal namely:
signal = sin(2*pi*0.08*t) + sin(2*pi*0.2*t) + sin(2*pi*0.32*t) + sin(2*pi*0.4*t);
so the segment of the code becomes:
freqs = [0.08, 0.2, 0.32, 0.4];
periods = 1./ freqs;
% Let the max value of t be 4 times the largest period
t_max = 4 * periods(1);
% Let us have 500 samples over the interval [0, t_max].
t = linspace(0, t_max, 500);
% The synthesized signal
signal = sin(2*pi*0.08*t) + sin(2*pi*0.2*t) + sin(2*pi*0.32*t) + sin(2*pi*0.4*t);
Now I wanna view the amplitude spectrum for the first 50 samples.
So I did this:
signal_first_50_samples= signal (1:50);
% Display its magnitude spectrum.
N = 64;
signal_spect = abs (fft(signal_first_50_samples,N));
signal_spect = fftshift(signal_spect);
F = [-N/2:N/2-1]/N;
plot (F, signal_spect)
set(gca, 'XTick',[-0.5:0.1:1])
grid on;
I was expecting spikes at each of the frequencies, however, I got this:
can anyone help me understand?
Thanks

采纳的回答

Image Analyst
Image Analyst 2014-12-7
If the signal is 500 samples and has 4 periods, then each period is 125 samples long. If you take less than half that you probably don't have a long enough signal to get a reliable spectrum. You're trying to get a spectrum when some of the frequencies don't even have half a cycle in the signal. Why did you take just 50 and not the whole signal?
  4 个评论
MatlabGirl
MatlabGirl 2014-12-7
i did something else i had only 50 samples for the singal and took all of them
%%50 samples taking 50
clc;
clear;
% We are given 4 different frequencies
freqs = [0.08, 0.2, 0.32, 0.4];
periods = 1./ freqs;
% Let the max value of t be 4 times the largest period
t_max = 4 * periods(1);
% Let us have 50 samples over the interval [0, t_max].
t = linspace(0, t_max, 50);
% The synthesized signal
signal = sin(2*pi*0.08*t) + sin(2*pi*0.2*t) + sin(2*pi*0.32*t) + sin(2*pi*0.4*t);
% Determine the first 50 samples of this signal
% signal_first_50_samples= signal (1:50);
% Display its magnitude spectrum.
% ??????????????????????????????????????????????????????????????????????
% I was expecting spikes at each freq
N = 64;
signal_spect = abs (fft(signal,N));
signal_spect = fftshift(signal_spect);
F = [-N/2:N/2-1]/N;
figure
plot (F, signal_spect)
%set(gca, 'XTick',[-0.5:0.05:1])
grid on;
I got this
it looks about right
but I wonder why it didn't work when i had 500 samples and i took all 500 of them
any ideas?
Image Analyst
Image Analyst 2014-12-7
Looks like your sampling frequency is not enough to follow the curves exactly. But at least you're getting all 4 spikes now like you should. It appears that there is some effect of the overall, total sample length because I can see side lobes caused by the sinc function, which is what you will get when you truncate your signal by a rect function. If you had higher resolution and took more cycles, that effect would be less.

请先登录,再进行评论。

更多回答(0 个)

标签

Community Treasure Hunt

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

Start Hunting!

Translated by