## Friday, April 20, 2012

The plot above shows two signals being added in the time domain and the spectrum of each time domain signal. The plot below shows the spectrum of each signal added in the frequency domain.

% Here we demonstrate the concept of additivity, that is, adding two or
% more signals in one domain results in the corresponding signals being
% added in the other domain.
close all;
fs=125;   %sample frequency = 125Hz
Ts=1/fs;  %sample period
n=0:100*fs; %sample index (fs=samples per second), w=window lenght
tn=n*Ts;
x=cos(2*pi*5*tn);
% Time domain plot of x(t)=cos(2*pi*5*tn)
figure('Color',[1 1 1]);
subplot(3,2,1);
h=plot(tn,x);box off;grid on;
xlabel('Time(s)');
ylabel('Amplitude');
title(['Time Domain: x1(t)=cos(2*pi*5*tn)']);
axis([0 1 -1.2 1.2]);
% Frequency domain plot of x(t)=cos(2*pi*5*tn)
subplot(3,2,2);
[X,f]=ComputeSpectrum(x,fs,2^14);
sig1=X;
h=plot(f,20*log(X));
box off; grid on;
set(h,'Linewidth',1);
xlabel('Frequency(Hz)');
ylabel('Amplitude(dB)');
title(['Frequency Domain: x1(t)=cos(2*pi*5*tn)']);
axis([4.4 5.8 -100 200]);

x=cos(2*pi*10*tn);
% Time domain plot of x(t)=cos(2*pi*10*tn)
subplot(3,2,3);
h=plot(tn,x);box off;grid on;
xlabel('Time(s)');
ylabel('Amplitude');
title(['Time Domain: x2(t)=cos(2*pi*10*tn)']);
axis([0 1 -1.2 1.2]);
% Frequency domain plot of x(t)=cos(2*pi*10*tn)
subplot(3,2,4);
[X,f]=ComputeSpectrum(x,fs,2^14);
h=plot(f,20*log(X));
sig2=X;
box off; grid on;
set(h,'Linewidth',1);
xlabel('Frequency(Hz)');
ylabel('Amplitude(dB)');
title(['Frequency Domain: x2(t)=cos(2*pi*10*tn)']);
axis([5 15 -100 250]);

x=(cos(2*pi*5*tn)) + (cos(2*pi*10*tn)); % add two signal in time domain
% Time domain plot of x(t)=cos(2*pi*5*tn)+cos(2*pi*10tn)
subplot(3,2,5);
h=plot(tn,x);box off;grid on;
xlabel('Time(s)');
ylabel('Amplitude');
title(['Time Domain: x1(t) + x2(t)']);
axis([0 1 -3 3]);
% Frequency domain plot of x(t)=cos(2*pi*5*tn)+cos(2*pi*10tn)
subplot(3,2,6);
[X,f]=ComputeSpectrum(x,fs,2^14);
h=plot(f,20*log(X));
box off; grid on;
set(h,'Linewidth',1);
xlabel('Frequency(Hz)');
ylabel('Amplitude(dB)');
title(['Frequency Domain: x1(t) + x2(t)']);
axis([0 30 -100 250]);
% Now, let's simply add the specturm of each signa.
figure('Color',[1 1 1]);
subplot(3,1,1);
h=plot(f,20*log(sig1));
box off; grid on;
set(h,'Linewidth',1);
xlabel('Frequency(Hz)');
ylabel('Amplitude(dB)');
title(['Frequency Domain: x1(t) + x2(t)']);
axis([0 30 -100 250]);

subplot(3,1,2);
h=plot(f,20*log(sig2));
box off; grid on;
set(h,'Linewidth',1);
xlabel('Frequency(Hz)');
ylabel('Amplitude(dB)');
title(['Frequency Domain: x1(t) + x2(t)']);
axis([0 30 -100 250]);

subplot(3,1,3);
h=plot(f,20*log(sig1+sig2));
box off; grid on;
set(h,'Linewidth',1);
xlabel('Frequency(Hz)');
ylabel('Amplitude(dB)');
title(['Frequency Domain: x1(t) + x2(t)']);
axis([0 30 -100 250]);