Monday, November 23, 2015

Sampling a Signal using Matlab

SAMPLING:
The matlab code for sampling of sinusoidal signal shown in below..
clc;
clear all;
close all;
fs=500e3; %Very high sampling rate 500 kHz
f=10e3; %Frequency of sinusoid
nCyl=5; %generate five cycles of sinusoid
t=0:1/fs:nCyl*1/f; %time index
x=cos(2*pi*f*t);
figure,
 plot(t,x)
title('Continuous sinusoidal signal');
xlabel('Time(s)');
ylabel('Amplitude');
fs1=30e3; %3kHz sampling rate
t1=0:1/fs1:nCyl*1/f; %time index
x1=cos(2*pi*f*t1);
 fs2=50e3; %5kHz sampling rate
t2=0:1/fs2:nCyl*1/f; %time index
x2=cos(2*pi*f*t2);
figure,
subplot(2,1,1);
%plot(t,x);
stem(t1,x1);
title('Sampling Continuous sinusoidal signal at f1=3kHz');
xlabel('Time(s)');
ylabel('Amplitude');
%hold on;

subplot(2,1,2);
%plot(t,x);
stem(t2,x2);
title('Sampling Continuous sinusoidal signal at f2=5kHz');
xlabel('Time(s)');
ylabel('Amplitude');
hold on;

OUTPUT:


See you with next tutorial.....

No comments:

Post a Comment