0% found this document useful (0 votes)
136 views3 pages

Excercise 1: %generation of Unit Impulse: %generation of Ramp Signal

This document contains code to generate and analyze various signals including ramp, unit impulse, unit step, sine, cosine, and exponential signals. It also contains code to perform operations on signals such as linear convolution using both direct method and circular convolution, sampling a signal at different rates, IIR filtering using bilinear transformation, FIR filtering using different window functions, and FFT.

Uploaded by

msd91
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
136 views3 pages

Excercise 1: %generation of Unit Impulse: %generation of Ramp Signal

This document contains code to generate and analyze various signals including ramp, unit impulse, unit step, sine, cosine, and exponential signals. It also contains code to perform operations on signals such as linear convolution using both direct method and circular convolution, sampling a signal at different rates, IIR filtering using bilinear transformation, FIR filtering using different window functions, and FFT.

Uploaded by

msd91
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

Excercise 1

%Generation of ramp signal:


%Generation of unit impulse:
n5=input('Enter the range of ramp signal');
clc;clear all;close all;
n6=0:n5-1;
n1=-2:1:2;
subplot(2,3,6);
y1=[zeros(1,2),ones(1,1),zeros(1,2)];
stem(n6,n6);
subplot(2,3,1);
ylabel('Asmplitude-->');
stem(n1,y1);
xlabel('d[n]-->');
ylabel('Amplitude-->');
title('Ramp Signal');
xlabel('a[n]-->');
title('Unit impulse');
%Generation of unit step:
n=input('Enter N value for unit step'); Exercise 2:
n2=0:1:n-1; Linear Convolution
y2=ones(1,n); clc;clear all;close all;
subplot(2,3,2); x=input('Enter the 1st sequence');
stem(n2,y2); h=input('Enter the 2nd sequence');
ylabel('Amplitude-->'); y=conv(x,h);
xlabel('b[n]-->'); title('figure 1');
title('Unit step'); subplot(3,1,1);
%Generation of sine signal: stem(x);
t1=0:.001:pi; xlabel('x[n]-->');
y3=sin(2*pi*1*t1); ylabel('amplitude-->');
subplot(2,3,3); title('figure 2');
plot(t1,y3); subplot(3,1,2);
ylabel('Amplitude-->'); stem(h);
xlabel('a(t)-->'); xlabel('h[n]-->');
title('Sine Signal'); ylabel('amplitude-->');
title('convolution of x and h');
%Generation of cosine signal: subplot(3,1,3);
t2=0:.001:pi; stem(y);
y4=cos(2*pi*1*t2); xlabel('y[n]-->');
subplot(2,3,4); ylabel('amplitude');
plot(t2,y4); disp(y);
ylabel('Amplitude-->');
xlabel('b(t)-->'); Circular convolution:
title('Cosine signal'); clc;clear all;close all;
%Generation of exponential signal: g=input('enter the first sequence');
n3=input('Enter the length of the h=input('enter the sec sequence');
sequence(exponential)'); n1=length(g);
n4=0:n3-1; n2=length(h);
a=input('Enter the value of a(for exp(a*t))'); if(n1==n2)
y5=exp(a*n4); n5=n1;
subplot(2,3,5); else
stem(n4,y5); n3=n1-1;
ylabel('Amplitude-->'); n4=n2-1;
xlabel('c[n]-->'); n5=n1+n2-1;
title('Exponential Signal'); g=[g zeros(1,n4)];
h=[h zeros(1,n3)]; disp(h);
end; subplot(3,1,2);
disp(g); stem(h);
subplot(3,1,1); xlabel('(b) n-->');
stem(g); ylabel('Amplitude -->');
xlabel('time'); title('Second sequence');
ylabel('amp'); for N=1:n
title('first seq'); y(N)=0;
disp(h); for i=1:n
subplot(3,1,2); j=N-i+1;
stem(h); if(j<=0)
xlabel('time'); j=j+n;
ylabel('amp'); end
title('sec seq'); y(N)=y(N)+[g(j)*h(i)];
for N=1:n5 end
y(N)=0; end
for i=1:n5 disp(y);
j=N-i+1; subplot(3,1,3);
if(j<=0) stem(y);
j=j+n5; xlabel('(c) n-->');
end; ylabel('Amplitude -->');
y(N)=y(N)+[g(j)*h(i)]; title('Convolved sequence');
end; y=conv(x,h);
end; figure 1;
disp(y); rootplot(3,1,1);
subplot(3,1,3); stem(x)
stem(y); ylabel('Amplitude');
xlabel('time'); xlabel('x[n]');
ylabel('amp'); subplot(3,1,2);
title('convoluted seq'); stem(h)
ylabel('amplitude');
Linear Through circular: xlabel('h[n]');
%Linear Convolution through Circular subplot(3,1,3);
Convolution stem(y);
clc; clear all; close all; ylabel('Amplitude');
g=input('Enter the first sequence'); xlabel('y[n]');
h=input('Enter the second sequence'); disp(y);
n1=length(g);
n2=length(h); Excercise 3:
n=n1+n2-1;
%PROGRAM TO ILLUSTRATE SAMPLING
g=[g zeros(1,(n-n1))];
%original signal
h=[h zeros(1,(n-n2))];
f = 2000;
disp(g);
T = 1/f;
subplot(3,1,1);
dt = T/100;
stem(g);
t = 0:dt:(5*T);
xlabel('(a) n-->');
x = cos(2*pi*f*t);
ylabel('Amplitude -->');
figure(1)
title('First sequence');
subplot(211) ylabel('Imaginary axis--->');
plot(t,x,'r-.'); xlabel('Real axis--->');
title('Original signal')
Exercise 5:
%signal sampled at Fs > Nyquist rate IIR
fs1=15000; %using bilinear transformation method
dt1 = 1/fs1; clc;clear all;close all;
t1 = 0:dt1:(5*T); wp=2*2000/44100;
x1 = cos(2*pi*f*t1); ws=2*10000/44100;
subplot(212) pdb=0.5;
plot(t,x,'r-.'); sdb=50;
hold on fs=1;
plot(t1,x1); [N,wn]=buttord(wp,ws,pdb,sdb);
title('signal sampled at Fs > Nyquist rate') [b,a]=butter(N,wn);
[bz,az]=bilinear(b,a,fs);
%signal sampled at Fs = Nyquist rate figure(1);
fs2=4000; freqz(bz,az);
dt2 = 1/fs2;
t2 = 0:dt2:(5*T); Exercise 6:
x2 = cos(2*pi*f*t2); FIR
figure(2) N=11;
subplot(211) wc=(1/6);
plot(t,x,'r-.'); hn=fir1(N-1,wc,boxcar(N));
hold on freqz(hn,1,N);
plot(t2,x2); N=11;
title('signal sampled at Fs = Nyquist rate') wc=(1/6);
hn=fir1(N-1,wc,hamming(N));
%signal sampled at Fs < Nyquist rate' freqz(hn,1,N);
fs3=1500; N=11;
dt3= 1/fs3; wc=(1/6);
t3= 0:dt3:(5*T); hn=fir1(N-1,wc,hanning(N));
x3 = cos(2*pi*f*t3); freqz(hn,1,N);
subplot(212)
plot(t,x,'r-.');
hold on
plot(t3,x3);
title('signal sampled at Fs < Nyquist rate')

Exercise 4:
FFT
clc;
close all;
clear all;
a=input('Enter the sequence');
n=input('Enter the length of fft');
y=fft(a,n);
stem(y);

You might also like