0% found this document useful (0 votes)
64 views58 pages

Program:-Unit Step Signal

The document describes generating and plotting various types of signals using MATLAB including unit step, ramp, exponential, sinusoidal, and impulse signals. It also describes performing linear and circular convolution on discrete signals as well as sampling a signal and observing the effects of aliasing. Finally, it generates a band pass filter impulse response and plots its frequency response. The programs demonstrate signal processing techniques using MATLAB.
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 DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
64 views58 pages

Program:-Unit Step Signal

The document describes generating and plotting various types of signals using MATLAB including unit step, ramp, exponential, sinusoidal, and impulse signals. It also describes performing linear and circular convolution on discrete signals as well as sampling a signal and observing the effects of aliasing. Finally, it generates a band pass filter impulse response and plots its frequency response. The programs demonstrate signal processing techniques using MATLAB.
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 DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 58

PROGRAM:-

UNIT STEP SIGNAL

t=0:1:3;

x=ones(1,4);

subplot(2,3,1);

plot(t,x);

xlabel('t');

ylabel('u(t)');

title('unit step signal');


unit step signal
2

1.8

1.6

1.4

1.2
u(t)

0.8

0.6

0.4

0.2

0
0 0.5 1 1.5 2 2.5 3
t

UNIT RAMP SIGNAL

t=0:0.01:03;

x=t;

subplot(2,3,2);

plot(t,x);

xlabel('t');
ylabel('r(t)');

title('unit ramp signal');

unit ramp signal


3

2.5

1.5
r(t)

0.5

0
0 0.5 1 1.5 2 2.5 3
t
UNIT EXPONENTIAL SIGNAL

t=0:0.01:03;

x=exp(-t);

subplot(2,3,2);

plot(t,x);

xlabel('t');
ylabel('e(t)');

title('exponential signal');
exponential signal
1

0.9

0.8

0.7

0.6
e(t)

0.5

0.4

0.3

0.2

0.1

0
0 0.5 1 1.5 2 2.5 3
t

SINUSOIDAL SIGNAL

t=0:0.01:03;

x=sin(2*pi*t);

subplot(2,3,4);

plot(t,x);
xlabel('t');

ylabel('x(t)');

title('sinusoidal signal');

sinusoidal signal
1

0.8

0.6

0.4

0.2
x(t)

-0.2

-0.4

-0.6

-0.8

-1
0 0.5 1 1.5 2 2.5 3
t
RESULT:-

Thus the generation of input signal was executed successfully using MATLAB.

PROGRAM:-

UNIT STEP SIGNAL

n=0:1:3;

x=ones(1,4);
subplot(2,3,1);

stem(n,x);

xlabel('n');

ylabel('u(n)');

title('unit step signal');

unit step signal


1

0.9

0.8

0.7

0.6
u(n)

0.5

0.4

0.3

0.2

0.1

0
0 0.5 1 1.5 2 2.5 3 3.5 4
n
UNIT RAMP SIGNAL

n=0:1:19;

x=n;

subplot(2,3,4);

stem(n,x);
xlabel('n');

ylabel('u(n)');

title('unit ramp signal');


unit ramp signal
20

18

16

14

12
u(n)

10

0
0 2 4 6 8 10 12 14 16 18 20
n
UNIT IMPULSE SIGNAL

n=0;

x=ones(1,1);

subplot(2,3,3);

stem(n,x);

xlabel('n');

ylabel('u(n)');

ylabel('delta(n)');

title('unit impulse sequence');


unit impulse sequence
1

0.9

0.8

0.7

0.6
delta(n)

0.5

0.4

0.3

0.2

0.1

0
-1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 1
n
SINUSOIDAL SIGNAL

n=0:1:19;

x=sin(2*pi*n/13);

subplot(2,3,2);

stem(n,x);

xlabel('n');

ylabel('u(n)');

title('sinusoidal signal');
sinusoidal signal
1

0.8

0.6

0.4

0.2
u(n)

-0.2

-0.4

-0.6

-0.8

-1
0 2 4 6 8 10 12 14 16 18 20
n
RESULT:-

Thus the generation of input signal was executed successfully using MATLAB.
PROGRAM:-

x=input('ENTER THE INPUT SEQUENCE');

h=input('ENTER THE IMPULSE RESPONSE SEQUENCE');

y=conv(x,h);

disp('output');

disp(y);

N1=length(x);

n=0:1:N1-1;

subplot(3,2,1);

stem(n,x);

xlabel('n');

ylabel('x(n)');

title('INPUT SEQUENCE');

N2=length(h);

n=0:1:N2-1;

subplot(3,2,2);

stem(n,h);

xlabel('n');

ylabel('h(n)');

title('IMPULSE RESPONSE SEQUENCE');

n=length(y);

n=0:1:N1+N2-2;

subplot(3,2,3);

stem(n,y);

xlabel('n');
ylabel('y(n)');

title('OUTPUT SEQUENCE');
INPUT SEQUENCE IMPULSE RESPONSE SEQUENCE
3 2

2 1
x(n)

h(n)
1 0

0 -1
0 1 2 3 0 1 2 3
n n
OUTPUT SEQUENCE
10

5
y(n)

-5
0 2 4 6
n
RESULT:-

Thus the linear convolution of discrete signals was executed successfully using MATLAB.

PROGRAM:-

x=input('enter the input sequence');

h=input('enter the impulse response sequence');

N1=length(x);

N2=length(h);

if(N1>N2)

h=[h zeros(1,N1-N2)];

else

x=[x zeros(1,N2-N1)];

end

N=length(x);

X=fft(x,N);

H=fft(h,N);

y=X.*H;
Y=ifft(y);

display(Y);

n=0:1:N-1;

subplot(2,2,1);

stem(n,x);

xlabel('n');

ylabel('x(n)');

title('input sequence');

n=0:1:N1-1;

subplot(2,2,2);

stem(n,h);

xlabel('n');

ylabel('h(n)');

title('impulse response sequence');

n=0:1:N-1;

subplot(2,2,3);

stem(n,Y);

xlabel('n');

ylabel('y(n)');

title('output sequence');
input sequence impulse response sequence
2 4

1.5 3
x(n)

h(n)
1 2

0.5 1

0 0
0 1 2 3 0 1 2 3
n n
output sequence
20

15
y(n)

10

0
0 1 2 3
n
RESULT:-

Thus the circular convolution of discrete signals was executed successfully using MATLAB.

PROGRAM:-

SAMPLING

clc;
clear all;

close all;

f1=1/128;

f2=5/128;

n=0:255;

fc=50/128;

x=cos(2*pi*f1*n)+cos(2*pi*f2*n);

xa=cos(2*pi*fc*n);

xamp=x.*xa;

subplot(2,2,1);

plot(n,x);

title('x(n)');

xlabel('n.....>');

ylabel('amplitude....>');

subplot(2,2,2);

plot(n,xa);

title('xa(n)');

xlabel('n.....>');

ylabel('amplitude....>');

subplot(2,2,3);

plot(n,xamp);

title('xamp(n)');

xlabel('n....>');

ylabel('amplitude...>');
EFFECTS OF ALIASING

n=0:127;

n1=128;

f1=1/128;

f2=5/128;

fc=50/128;

x=cos(2*pi*f1*n)+cos(2*pi*f2*n);

xa=cos(2*pi*fc*n);

xamp=x.*xa;

xam=fft(xamp,n1);

subplot(2,2,4);

stem(n,xam);

title('xamp(n)');

xlabel('n...>');

ylabel('amplitude..>');
x(n) xa(n)
2 1

1 0.5
amplitude....>

amplitude....>
0 0

-1 -0.5

-2 -1
0 100 200 300 0 100 200 300
n.....> n.....>
xamp(n) xamp(n)
2 40

1
20
amplitude...>

amplitude..>

0
0
-1

-2 -20
0 100 200 300 0 50 100 150
n....> n...>
RESULT:-

Thus the program of sampling and effects of aliasing of signals was executed successfully using
MATLAB.

PROGRAM:-

BAND PASS FILTER

clear all;

wc1=0.25*pi;

wc2=0.75*pi;

N=25;

a=(N-1)/2;

eps=0.001;

n=0:1:N-1;

hd=(sin(wc2*(n-a+eps))-sin(wc1*(n-a+eps)))./(pi*(n-a+eps));

wr=boxcar(N);

hn=hd.*wr';

w=0:0.01:pi;

h=freqz(hn,1,w);

plot(w/pi,abs(h));

xlabel('normalised frequency');

ylabel('magnitude');
1.4

1.2

0.8
magnitude

0.6

0.4

0.2

0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
normalised frequency

BAND REJECT FILTER

clear all;

wc1=0.25*pi;

wc2=0.75*pi;

N=25;
a=(N-1)/2;

eps=0.001;

n=0:1:N-1;

hd=(sin(wc1*(n-a+eps))-sin(wc2*(n-a+eps))+sin(pi*(n-a+eps)))./(pi*(n-a+eps));

wr=boxcar(N);

hn=hd.*wr';

w=0:0.01:pi;

h=freqz(hn,1,w);

alpha=(N-1)/2;

plot(w/pi,abs(h));

xlabel('normalised frequency');

ylabel('magnitude');
1.4

1.2

0.8
magnitude

0.6

0.4

0.2

0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
normalised frequency
LOW PASS FILTER

clear all;

wc=0.5*pi;

N=25;

alpha=(N-1)/2;

eps=0.001;

n=0:1:N-1;

hd=sin(wc*(n-alpha+eps))./(pi*(n-alpha+eps));

wr=boxcar(N);

hn=hd.*wr';

w=0:0.01:pi;

h=freqz(hn,1,w);

alpha=(N-1)/2;

plot(w/pi,abs(h));

xlabel('normalised frequency');

ylabel('magnitude');
1.4

1.2

1
magnitude

0.8

0.6

0.4

0.2

0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
normalised frequency

HIGH PASS FILTER

clear all;

wc=0.5*pi;

N=25;

alpha=(N-1)/2;

eps=0.001;
n=0:1:N-1;

hd=(sin(pi*(n-alpha+eps))-sin(wc*(n-alpha+eps)))./(pi*(n-alpha+eps));

wr=boxcar(N);

hn=hd.*wr';

w=0:0.01:pi;

h=freqz(hn,1,w);

alpha=(N-1)/2;

plot(w/pi,abs(h));

xlabel('normalised frequency');

ylabel('magnitude');
1.4

1.2

0.8
magnitude

0.6

0.4

0.2

0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
normalised frequency
RESULT:-

Thus the design of FIR FILTER using rectangular window was executed successfully.

PROGRAM;-

BAND PASS FILTER

clear all;

wc1=0.25*pi;

wc2=0.75*pi;

N=25;

a=(N-1)/2;

eps=0.001;

n=0:1:N-1;

hd=(sin(wc2*(n-a+eps))-sin(wc1*(n-a+eps)))./(pi*(n-a+eps));

wh=hamming(N);

hn=hd.*wh';

w=0:0.01:pi;

h=freqz(hn,1,w);
plot(w/pi,abs(h));

xlabel('normalised frequency');

ylabel('magnitude');
1.4

1.2

0.8
magnitude

0.6

0.4

0.2

0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
normalised frequency

BAND REJECT FILTER

clear all;
wc1=0.25*pi;

wc2=0.75*pi;

N=25;

a=(N-1)/2;

eps=0.001;

n=0:1:N-1;

hd=(sin(wc1*(n-a+eps))-sin(wc2*(n-a+eps))+sin(pi*(n-a+eps)))./(pi*(n-a+eps));

wh=hamming(N);

hn=hd.*wh';

w=0:0.01:pi;

h=freqz(hn,1,w);

alpha=(N-1)/2;

plot(w/pi,abs(h));

xlabel('normalised frequency');

ylabel('magnitude');
1.4

1.2

0.8
magnitude

0.6

0.4

0.2

0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
normalised frequency

LOW PASS FILTER


clear all;

wc=0.5*pi;

N=25;

alpha=(N-1)/2;

eps=0.001;

n=0:1:N-1;

hd=sin(wc*(n-alpha+eps))./(pi*(n-alpha+eps));

wh=hamming(N);

hn=hd.*wh';

w=0:0.01:pi;

h=freqz(hn,1,w);

alpha=(N-1)/2;

plot(w/pi,abs(h));

xlabel('normalised frequency');

ylabel('magnitude');
1.4

1.2

0.8
magnitude

0.6

0.4

0.2

0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
normalised frequency

HIGH PASS FILTER

clear all;

wc=0.5*pi;

N=25;

alpha=(N-1)/2;

eps=0.001;
n=0:1:N-1;

hd=(sin(pi*(n-alpha+eps))-sin(wc*(n-alpha+eps)))./(pi*(n-alpha+eps));

wh=hamming(N);

hn=hd.*wh';

w=0:0.01:pi;

h=freqz(hn,1,w);

alpha=(N-1)/2;

plot(w/pi,abs(h));

xlabel('normalised frequency');

ylabel('magnitude');
1.4

1.2

0.8
magnitude

0.6

0.4

0.2

0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
normalised frequency
RESULT:-

Thus the design of FIR FILTER using hamming window was executed successfully.

PROGRAM:-

clear all;

rp=input('Enter the passband ripple');

rs=input('Enter the stopband ripple');

fp=input('Enter the passband frequency');

fs=input('Enter the stopband frequency');

fsamp=input('Enter the sampling frequency');

wp=2*pi*fp/fsamp;

ws=2*pi*fs/fsamp;

[n,wn]=buttord(wp,ws,rp,rs,'s');

[num,den]=butter(n,wn,'s');

[b,a]=impinvar(num,den);

w=0:0.01:pi;

[h,om]=freqz(b,a,w);

m=20*log10(abs(h));

an=angle(h);
subplot(2,1,1);

plot(om/pi,m);

xlabel('normalised frequency');

ylabel('gain in db');

title('magnitude response');

subplot(2,1,2);

plot(om/pi,an);

xlabel('normalised frequency');

ylabel('phase in radian');

title('phase response');
magnitude response
0

-20
gain in db

-40

-60

-80
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
normalised frequency
phase response
4

2
phase in radian

-2

-4
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
normalised frequency
RESULT:-

Thus the design of low pass butterworth IIR filter using impulse invariant transformation was
executed successfully using MATLAB.

PROGRAM:-

N=input('ENTER THE VALUE OF N:');

x=input('ENTER THE INPUT RESPONSE:');

L=length(x);

if(L>N)

X=[X zeroes(1,N-L)];

else

if(L<N)

disp('invalid sequence (the number of samples should be equal to N)');

break;

end

end

X=fft(x,N);

disp('x(k)=');

disp(X);

disp('mag[x(k)]=');
disp(abs(X));

disp('phase[x(k)]=');

disp(phase(X));

n=0:1:N-1;

subplot(2,2,1);

stem(n,x);

xlabel('n');

ylabel('INPUT SEQUENCE');

K=0:1:N-1;

subplot(2,2,2);

stem(K,abs(X));

xlabel('K');

ylabel('abs[x(k)]');

title('magnitude spectrum');

K=0:1:N-1;

subplot(2,2,3);

stem(K,phase(X));

xlabel('K');

ylabel('ang[x(k)]');

title('phase spectrum');
magnitude spectrum
1 6
INPUT SEQUENCE

abs[x(k)]
0.5
2

0 0
0 2 4 6 8 0 2 4 6 8
n K
phase spectrum
2

1
ang[x(k)]

-1

-2
0 2 4 6 8
K
RESULT:-

Thus the DFT of the signal is calculated using fast fourier transform and frequency response &
phase response was plotted using MATLAB successfully.

OUTPUT:-

ENTER THE VALUE OF N:8

ENTER THE INPUT RESPONSE:[1 1 1 1 1 1 0 0]

x(k)=

Columns 1 through 4

6.0000 -0.7071 - 1.7071i 1.0000 - 1.0000i 0.7071 + 0.2929i

Columns 5 through 8

0 0.7071 - 0.2929i 1.0000 + 1.0000i -0.7071 + 1.7071i

mag[x(k)]=

Columns 1 through 7

6.0000 1.8478 1.4142 0.7654 0 0.7654 1.4142

Column 8

1.8478

phase[x(k)]=
Columns 1 through 7

0 -1.9635 -0.7854 0.3927 0 -0.3927 0.7854

Column 8

1.9635

OUTPUT:-

Enter the passband ripple 0.5

Enter the stopband ripple 50

Enter the stopband frequency 1200

Enter the passband frequency 2400

Enter the sampling frequency 10000


OUTPUT:-

Enter the input sequence [2 1 2 1]

Enter the impulse response sequence [1 2 3 4]

Y=

14 16 14 16
OUTPUT:-

ENTER THE INPUT SEQUENCE [1 2 3 1]

ENTER THE IMPULSE RESPONSE SEQUENCE [1 2 1 -1]

output

1 4 8 8 3 -2 -1

You might also like