Popular Posts

Tuesday, October 18, 2011

MATLAB Programs


GENERATION OF SIMPLE SIGNALS



%GENERATION OF SIMPLE SIGNALS


clc;
clear all;
close all;
%Unit Impulse Signal
t=-2:2;
y=[zeros(1,2),1, zeros(1,2)];
subplot(221);
stem(t,y);
xlabel('Time Index');
ylabel('Amplitude');
%Unit Step Sequence
n=input('Enter the
length of step sequence N = '
);
t=0:n-1;
y1=ones(1,n);
subplot(222);
stem(t,y1);
xlabel('Time Index');
ylabel('Amplitude');
%Ramp Sequence
n1=input('Enter the length of ramp sequence N = ');
t=0:n1;
subplot(223);
stem(t,t);
xlabel('Time Index');
ylabel('Amplitude');
n2=input('Enter the
length of exponential sequence N = '
);
t=0:n2;
a=input('Enter the
value of a = '
);
y2=exp(a*t);
subplot(224);
stem(t,y2);
xlabel('Time Index');
ylabel('Amplitude'); 


Enter the length of step sequence N = 8
Enter the length of ramp sequence N = 8
Enter the length of exponential sequence N = 8
Enter the value of a = -1

OUTPUT

 



AM GENERATION WITH DOUBLE SIDE BAND (DSB) AND SUPPRESSED CARRIER

%AM Wave DSB with carrier


clc;
clear all;
close all;
fc=input('Enter the carrier signal frequency in hz,fc = ');
fm=input('Enter the modulating signal frequency in hz,fm = ');
m=input('Modulation index,m= ');
n=0:0.001:1;
c=sin(2*pi*fc*n);%carrier signal
M=sin(2*pi*fm*n);% modulating signal
y=(1+m*M).*c;%AM signal
subplot(2,1,1);
plot(n,y);
ylabel('amplitude');
xlabel('time index');

%AM
with suppressed carrier
n=0:0.001:1;
c=sin(2*pi*fc*n);%carrier signal
M=sin(2*pi*fm*n);% modulating signal
y=M.*c;
subplot(2,1,2);
plot(n,y);
axis([0 1 -2 2]);
ylabel('amplitude');
xlabel('time index');



Enter the carrier signal frequency in Hz, fc = 50 
Enter the modulating signal frequency in Hz, fm = 5 
Modulating index, m = 0.5


OUTPUT



LINEAR CONVOLUTION USING BUILT IN FUNCTION




%Linear Convolution using built-in function

clc;
clear all;
close all;
x=input('Enter the input sequence x[n] = ');
lx=input('Enter the starting time index of x[n] = ');
h=input('Enter the input sequence h[n] = ');
lh=input('Enter the starting time index of h[n] = ');
y= conv(x,h);
n=lx+lh:length(y)+lx+lh-1;
stem(n,y);
ylabel('Amplitude');
xlabel('Time Index');
title('Linear Convolution');



Enter the input sequence x[n] = [1 2 3 4]
Enter the starting time index of x[n] = -2
Enter the input sequence h[n] = [3 3 4]
Enter the starting time index of h[n] = -1



SQUARE WAVE FROM SINUSOIDAL HARMONICS


%SQUARE WAVE FROM SINUSOIDAL HARMONICS

clc;
clear all;
close all;
y=0;
h=input('No of harmonics = ');
f=input('enter the frequency =');
t=0:0.005:1/f
for i=1:2:h
y= y+sin(i*2*pi*f*t)/i;
plot(t,y);
pause;
hold on;
end


No of harmonics = 20
enter the frequency =0.5








 
IMPULSE RESPONSE OF LTI SYSTEM 




%Impulse Response of LTI System

clc;
clear all;
close all;
N=input('Enter the required length of the impulse response, N = ');
b=input('Enter coeffecients of x[n], b = ')
a=input('Enter coeffecients of y[n], a = ')
x=[1, zeros(1, N-1)];
y=filter(b,a,x);
n=0:N-1;
stem(n,y);
xlabel('Time Index n');
ylabel('Amplitude');
title('Impulse response of the system');



Enter the required length of the impulse response, N = 40
Enter coeffecients of x[n], b = [ -0.8 -0.44 -0.36 -0.22]

b =

   -0.8000   -0.4400   -0.3600   -0.2200

Enter coeffecients of y[n], a = [1 0.7 -0.45 -0.6]

a =

    1.0000    0.7000   -0.4500   -0.6000



No comments:

Post a Comment