-3

I have four frequency components of non stationary signals defined as shown below in the code. When i tried to plot the frequency domain of these signals, i got a graph with only three frequency peaks as shown below in the image.?!

kindly let me know why ia m getting only three peaks while i have four freq. components.

COde:

% Time specifications:
Fs = 8000;                       % samples per second
dt = 1/Fs;                       % seconds per sample
StopTime = 2;                    % seconds
t = (0:dt:StopTime-dt);             % seconds

t1 = (0:dt:.25);
t2 = (.25:dt:.50);
t3 = (.5:dt:.75);
t4 = (.75:dt:1);

x1 = (10)*sin(2*pi*10*t1);
x2 = (10)*sin(2*pi*20*t2) + x1;
x3 = (10)*sin(2*pi*50*t3) + x2;
x4 = (10)*sin(2*pi*70*t4) + x3;

NFFT  = 2 ^ nextpow2(length(t));     % Next power of 2 from length of y
Y    = fft(x4, NFFT);
f    = Fs / 2 * linspace(0, 1, NFFT/2 + 1);
figure;
plot(f(1:200), 2 * abs( Y( 1:200) ) );

% Plot the signal versus time:
figure;
xlabel('time (in seconds)');
ylabel('Amplitude');
title('non-stationary Signal versus Time');

hold on
plot(t1,x1,'r');
plot(t2,x2,'g');
plot(t3,x3,'b');
 plot(t4,x4,'black');
  legend('x1 = (10)*sin(2*pi*15*t1) + (10)*sin(2*pi*8*t1)', 'x2 = (10)*sin(2*pi*25*t2)   
 +    
 x1', 'x3 = (10)*sin(2*pi*50*t3) + x2', 'x4 = (10)*sin(2*pi*75*t4) + x3', ...
'Location',  'SouthWest');

IMage:: enter image description here

rmaik
  • 1,076
  • 3
  • 15
  • 48
  • 1
    Could you edit your code so that it only includes the relevant portions (the time-domain plot isn't relevant), and make sure the comments make sense (15Hz??). – Oliver Charlesworth Jan 01 '15 at 13:08
  • i edited my question sorry – rmaik Jan 01 '15 at 13:10
  • 3
    I copied your code and I get 4 peaks in frequency, are you sure about the question? – Rashid Jan 01 '15 at 13:21
  • @Kamtal yes i am sure, the graph i posted is what i gor according to the posted cde – rmaik Jan 01 '15 at 15:21
  • 1
    Copy-pasting the code in your question into my Matlab R2014b command window, I get four peaks as well. If you're using a script file rather than an a function M-file, try a `clear all` to make sure that you don't issues with old variables. What `version` are you using? – horchler Jan 02 '15 at 00:06

1 Answers1

0

You've plotted the fft for x3, which is the sum of the first three signals only. I think you meant to plot this for x4, which includes the fourth signal.