Friday, January 8, 2010

DSP Tutorial Matlab Script



The script below will get you started plotting basic time domain signals. The following tutorials are available on additional DSP topics:





This is a simple Matlab script which describes the basic plotting of time-domain signals.

%% DSP Tutorial Script
% James Eastham
% Member, IEEE
% Created on: 01/08/2010
% Revision: R1

%% Plotting a Basic Time Domain Signals
% Sinewave with a peak amplitude of 1 and a fequency of freq
clear all;
close all;
freq = 5; %5Hz
n=0:.01:.2; %number of discrete values on X axis
x = cos (2*pi*freq*n); %our cosine signal
figure('Color',[1 1 1]);
plot(n,x);
title('Example of Tim-Domain Signal');
xlabel('Time(s)');
ylabel('Amplitude');

%% Plotting a Basic Time Domain Signal Continued
figure('Color',[1 1 1]);
stem(n,x,'--rs','LineWidth',2,'MarkerEdgeColor','k','MarkerFaceColor','g','Markersize',10);
hold on;
plot(n,x);
title('Example of Time-Domain Signal Plot');
xlabel('Time(s)');
ylabel('Amplitude');


%% Plotting with the Subplot Feature
% subplot(m,n,p) breaks the figure window into an
% m-by-n matrix
figure('Color',[1 1 1]);
subplot(2,1,1);
plot(n,x);
title('Example of the Time-Domain Signal');
xlabel('Time(s)');
ylabel('Amplitude');
ns=1:length(n);
subplot(2,1,2);
stem(ns,x,'.r');
title('Example of the Descrete Points');
xlabel('Descrete Sample');
ylabel('Amplitude');
axis([1 21 -1.2 1.2]);
grid on;

2 comments:

i said...
This comment has been removed by a blog administrator.
william said...


Every person has the passion in any aspects or things.
If you love something and it came in front of you it completes your day and your mood turns into something you won't expected.
I love your work and I want to read more about it. Visit my site if you have time . Thank you.

triciajoy.com

www.triciajoy.com