Monday, January 18, 2010

DSP Tutorial #4: Plotting Complex Signals

In this example we will plot a more complex time domain signal in Matlab:



clear all; %clear all variables
fs = 50; % sample freq
Ts=1/fs; % sample period
n=0:1*fs; % time window (fs=samples per second), 1 second
tn=n*Ts; % sample index
sig_a=cos(2*pi*5*tn);
sig_b=1.5+cos(2*pi*20*tn);
x=sig_a+sig_b;
% Time domain plot of x(t)=cos(2*pi*5*tn)
figure('Color',[1 1 1]);
h=plot(tn,x,'g','LineWidth',3);box off;hold on;
plot(tn,sig_a,'--r','LineWidth',2);
plot(tn,sig_b,'--k','LineWidth',2);
title('Example of Composite Signal: 2 Signals Added');
legend('Composite','Signal 1','Signal 2');
xlabel('Time(s)');
ylabel('Amplitude');
figure('Color',[1 1 1]);
plot(tn,sig_a);
title('Stem Plot Example: Fs = 50 (50 Points)');
axis('tight');

No comments: