Sie sind auf Seite 1von 10

1.

program for unit step,impulse response,


sine,cos,
for unit step
clc;
clear all;
n=5;
t=-n:1:n;
x=[zeros(1,n),1,ones(1,n)];
stem(t,x);
xlabel('t');
ylabel('magnitude');
title('unit step signal');
for unit impulse

clc;
clear all;
n=5;
t=-n:1:n;
x=[zeros(1,n),1,zeros(1,n)];
stem(t,x);
xlabel('t');
ylabel('magnitude');
title('unit impulse signal');

for sine
clc;
clear all;
n=0:0.5:(2*pi);
y=sin(n);
stem(n,y);
xlabel('n');
ylabel('magnitude');
title('sinusoidal signal');

for cos
clc;
clear all;
n=0:0.5:(2*pi);
y=cos(n);
stem(n,y);
xlabel('n');
ylabel('magnitude');
title('cosine signal');

2. Program for DFT/IDFT


clc;
x1 = input('Enter the sequence:');
n = input('Enter the length:');
m = fft(x1,n);
disp('N-point DFT of a given sequence:');
disp(m);
N = 0:1:n-1;
subplot(1,2,1);
stem(N,m);
xlabel('Length');
ylabel('Magnitude of X(k)');
title('Magnitude spectrum:');
an = angle(m);
subplot(1,2,2);
stem(N,an);
xlabel('Length');
ylabel('Phase of X(k)');
title('Phase spectrum:');

3. Program for frequency response

clc;
clear all;
b = [1, 4];
a = [1, -5];
w = -2*pi: pi/256: 2*pi;
[h] = freqz(b, a, w);
subplot(2, 1, 1);
plot(w, abs(h));
xlabel('Frequency \omega');
ylabel('Magnitude');
title('frequency response of given signal');
grid;
subplot(2, 1, 2);
plot(w, angle(h));
xlabel('Frequency \omega');
ylabel('Phase - Radians');
grid;
4. PROGRAM FOR FFT
clc;
clear all;
x=input('enter input sequence a(n)');
n=length(x);
y=fft(x,n);
m=abs(y);
subplot(1,2,1);
stem(m);
xlabel('time');
ylabel('magnitude');
title('m plot');
p=angle(y);
subplot(1,2,2);
stem(p);
xlabel('time');
ylabel('phase in radians');
title('phase plot');

5. Program for power spectrum

clc;
clear all;
t = 0:0.001:0.6;
x = sin(2*pi*50*t)+sin(2*pi*120*t);
y = x + 2*randn(size(t));
figure,plot(1000*t(1:50),y(1:50));
title('Signal Corrupted with Zero-Mean
Random Noise');
xlabel('time (milliseconds)');
Y = fft(y,512);
Pyy = Y.* conj(Y) / 512;
f = 1000*(0:256)/512;
figure,plot(f,Pyy(1:257));
title('Frequency content of y');
xlabel('frequency (Hz)');
19. program for interpolation
clc;
t=0:0.03:2;
x=cos(2*pi*t);
a=interp(x,2);
b=interp(t,2);
subplot(2,1,1);
stem(t,x);
xlabel('no. of signals');
ylabel('i/p signals');
subplot(2,1,2);
stem(b,a);
title('interpolated signal');
20. program for decimation
clc;
t=0:0.03:2;
x=cos(2*pi*t);
a=decimate(x,2);
b=decimate(t,2);
subplot(2,1,1);
stem(t,x);
xlabel('no. of signals');
ylabel('i/p signals');
subplot(2,1,2);
stem(b,a);
title('decimated signal');
6. program for FIR LOW PASS FILTER

clc;
clear all;
close all;
rp=0.02;
rs=0.01;
fp=1000;
fs=1500;
f=10000;
wp=2*fp/f;
ws=2*fs/f;
num=-20*log10(sqrt(rp*rs))-13;
dem=14.6*(fs-fp)/f;
n=ceil(num/dem);
n1=n+1;
if(rem(n,2)~=0)
n1=n;
n=n-1;
end
c=input('enter your choice of window
function 1. rectangular 2. triangular 3.kaiser:
\n ');
if(c==1)
y=rectwin(n1);
disp('Rectangular window filter
response');
end
if (c==2)
y=triang(n1);
disp('Triangular window filter response');
end
if(c==3)
y=kaiser(n1);
disp('kaiser window filter response');
end
b=fir1(n,wp,'low',y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
plot(o/pi,m);
title('LPF');
ylabel('Gain in dB-->');
xlabel('Normalized frequency-->');

7. PROGRAM FOR FIR HIGH PASS

clc;
clear all;
close all;
rp=0.02;
rs=0.01;
fp=1000;
fs=1500;
f=10000;
wp=2*fp/f;
ws=2*fs/f;
num=-20*log10(sqrt(rp*rs))-13;
dem=14.6*(fs-fp)/f;
n=ceil(num/dem);
n1=n+1;
if(rem(n,2)~=0)
n1=n;
n=n-1;
end
c=input('enter your choice of window
function 1. rectangular 2. triangular 3.kaiser:
\n ');
if(c==1)
y=rectwin(n1);
disp('Rectangular window filter
response');
end
if (c==2)
y=triang(n1);
disp('Triangular window filter response');
end
if(c==3)
y=kaiser(n1);
disp('kaiser window filter response');
end
b=fir1(n,wp,'high',y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
plot(o/pi,m);
title('HPF');
ylabel('Gain in dB-->');
xlabel('Normalized frequency-->');
8. program for FIR BAND PASS

clc;
clear all;
close all;
rp=0.02;
rs=0.01;
fp=1000;
fs=1500;
f=10000;
wp=2*fp/f;
ws=2*fs/f;
num=-20*log10(sqrt(rp*rs))-13;
dem=14.6*(fs-fp)/f;
n=ceil(num/dem);
n1=n+1;
if(rem(n,2)~=0)
n1=n;
n=n-1;
end
c=input('enter your choice of window
function 1. rectangular 2. triangular 3.kaiser:
\n ');
if(c==1)
y=rectwin(n1);
disp('Rectangular window filter
response');
end
if (c==2)
y=triang(n1);
disp('Triangular window filter response');
end
if(c==3)
y=kaiser(n1);
disp('kaiser window filter response');
end
wn=[wp,ws];
b=fir1(n,wn,'bandpass',y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
plot(o/pi,m);
title('BPF');
ylabel('Gain in dB-->');
xlabel('Normalized frequency-->');

clc;
clear all;
close all;
rp=0.02;
rs=0.01;
fp=1000;
fs=1500;
f=10000;
wp=2*fp/f;
ws=2*fs/f;
num=-20*log10(sqrt(rp*rs))-13;
dem=14.6*(fs-fp)/f;
n=ceil(num/dem);
n1=n+1;
if(rem(n,2)~=0)
n1=n;
n=n-1;
end
c=input('enter your choice of window
function 1. rectangular 2. triangular 3.kaiser:
\n ');
if(c==1)
y=rectwin(n1);
disp('Rectangular window filter
response');
end
if (c==2)
y=triang(n1);
disp('Triangular window filter response');
end
if(c==3)
y=kaiser(n1);
disp('kaiser window filter response');
end
wn=[wp,ws];
b=fir1(n,wn,'stop',y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
plot(o/pi,m);
title('BSF');
ylabel('Gain in dB-->');
xlabel('Normalized frequency-->');

9. PROGRAM FOR FIR BAND STOP

10. program for butterworth low pass

clc;
clear all;
rp=0.15;
rs=60;
fp=1500;
fs=3000;
f=7000;
wp=2*fp/f;
ws=2*fs/f;
[n,wn]=buttord(wp,ws,rp,rs,'s');
[b,a]=butter(n,wn,'low','s');
w=0:.01:pi;
[h,om]=freqs(b,a,w);
m=20*log10(abs(h));
subplot(2,1,1);
plot(om/pi,m);
title('magnitude response of IIR Low Pass
filter is:');
xlabel('(a) Normalized freq. -->');
ylabel('Gain in dB-->');
an=angle(h);
subplot(2,1,2);
plot(om/pi,an);
title('phase response of IIR Low Pass filter
is:');
xlabel('(b) Normalized freq. -->');
ylabel('Phase in radians-->')

11. program for butterworth high pass

clc;
clear all;
rp=0.15;
rs=60;
fp=1500;
fs=3000;
f=7000;
wp=2*fp/f;
ws=2*fs/f;
[n,wn]=buttord(wp,ws,rp,rs,'s');
[b,a]=butter(n,wn,'high','s');
w=0:.01:pi;
[h,om]=freqs(b,a,w);
m=20*log10(abs(h));
subplot(2,1,1);
plot(om/pi,m);
title('magnitude response of IIR High Pass
filter is:');
xlabel('(a) Normalized freq. -->');
ylabel('Gain in dB-->');
an=angle(h);
subplot(2,1,2);
plot(om/pi,an);
title('phase response of IIR High Pass filter
is:');
xlabel('(b) Normalized freq. -->');
ylabel('Phase in radians-->')

12. program for butterworth band pass

clc;
clear all;
rp=0.15;
rs=60;
fp=1500;
fs=3000;
f=7000;
wp=2*fp/f;
ws=2*fs/f;
[n,wn]=buttord(wp,ws,rp,rs,'s');
wn=[wp,ws];
[b,a]=butter(n,wn,'bandpass','s');
w=0:.01:pi;
[h,om]=freqs(b,a,w);
m=20*log10(abs(h));
subplot(2,1,1);
plot(om/pi,m);
title('magnitude response of IIR Band Pass
filter is:');
xlabel('(a) Normalized freq. -->');
ylabel('Gain in dB-->');
an=angle(h);
subplot(2,1,2);
plot(om/pi,an);
title('phase response of IIR Band Pass filter
is:');
xlabel('(b) Normalized freq. -->');
ylabel('Phase in radians-->')

13. program for butterworth band stop

clc;
clear all;
rp=0.15;
rs=60;
fp=1500;
fs=3000;
f=7000;
wp=2*fp/f;
ws=2*fs/f;
[n,wn]=buttord(wp,ws,rp,rs,'s');
wn=[wp,ws];
[b,a]=butter(n,wn,'stop','s');
w=0:.01:pi;
[h,om]=freqs(b,a,w);
m=20*log10(abs(h));
subplot(2,1,1);
plot(om/pi,m);
title('magnitude response of IIR Band Stop
filter is:');
xlabel('(a) Normalized freq. -->');
ylabel('Gain in dB-->');
an=angle(h);
subplot(2,1,2);
plot(om/pi,an);
title('phase response of IIR Band Stop filter
is:');
xlabel('(b) Normalized freq. -->');
ylabel('Phase in radians-->')

14. program for chebshev low pass

clc;
clear all;
rp=0.15;
rs=60;
fp=1500;
fs=3000;
f=7000;
wp=2*fp/f;
ws=2*fs/f;
[n,wn]=cheb1ord(wp,ws,rp,rs,'s');
[b,a]=cheby1(n,rp,wp,'low','s');
w=0:.01:pi;
[h,om]=freqs(b,a,w);
m=20*log10(abs(h));
subplot(2,1,1);
plot(om/pi,m);
title('magnitude response of IIR Low Pass
filter is:');
xlabel('(a) Normalized freq. -->');
ylabel('Gain in dB-->');
an=angle(h);
subplot(2,1,2);
plot(om/pi,an);
title('phase response of IIR Low Pass filter
is:');
xlabel('(b) Normalized freq. -->');
ylabel('Phase in radians-->')

15. program for chebshev high pass

clc;
clear all;
rp=0.15;
rs=60;
fp=1500;
fs=3000;
f=7000;
wp=2*fp/f;
ws=2*fs/f;
[n,wn]=cheb1ord(wp,ws,rp,rs,'s');
[b,a]=cheby1(n,rp,wp,'high','s');
w=0:.01:pi;
[h,om]=freqs(b,a,w);
m=20*log10(abs(h));
subplot(2,1,1);
plot(om/pi,m);
title('magnitude response of IIR High Pass
filter is:');
xlabel('(a) Normalized freq. -->');
ylabel('Gain in dB-->');
an=angle(h);
subplot(2,1,2);
plot(om/pi,an);
title('phase response of IIR High Pass filter
is:');
xlabel('(b) Normalized freq. -->');
ylabel('Phase in radians-->')

16. program for chebshev band pass

clc;
clear all;
rp=0.15;
rs=60;
fp=1500;
fs=3000;
f=7000;
wp=2*fp/f;
ws=2*fs/f;
[n,wn]=cheb1ord(wp,ws,rp,rs,'s');
wn=[wp,ws];
[b,a]=cheby1(n,rp,wn,'bandpass','s');
w=0:.01:pi;
[h,om]=freqs(b,a,w);
m=20*log10(abs(h));
subplot(2,1,1);
plot(om/pi,m);
title('magnitude response of IIR Band Pass
filter is:');
xlabel('(a) Normalized freq. -->');
ylabel('Gain in dB-->');
an=angle(h);
subplot(2,1,2);
plot(om/pi,an);
title('phase response of IIR Band Pass filter
is:');
xlabel('(b) Normalized freq. -->');
ylabel('Phase in radians-->')

clc;
clear all;
rp=0.15;
rs=60;
fp=1500;
fs=3000;
f=7000;
wp=2*fp/f;
ws=2*fs/f;
[n,wn]=cheb1ord(wp,ws,rp,rs,'s');
wn=[wp,ws];
[b,a]=cheby1(n,rp,wn,'stop','s');
w=0:.01:pi;
[h,om]=freqs(b,a,w);
m=20*log10(abs(h));
subplot(2,1,1);
plot(om/pi,m);
title('magnitude response of IIR Band Stop
filter is:');
xlabel('(a) Normalized freq. -->');
ylabel('Gain in dB-->');
an=angle(h);
subplot(2,1,2);
plot(om/pi,an);
title('phase response of IIR Band Stop filter
is:');
xlabel('(b) Normalized freq. -->');
ylabel('Phase in radians-->');

17. program for CHEBSHEV band stop

18. %Generation of DTMF signals

Fs = 8000;
% Sampling frequency
Ts = 1/Fs;
Numof_samples =input('enter the no of
samples');
dialnumber=input('enter the dial number');
T = Ts*(0:Numof_samples-1)';
switch dialnumber
case 0
F1 = 941;
F2 = 1336;
case 1
F1 = 697;
F2 = 1209;
case 2
F1 = 697;
F2 = 1336;
case 3
F1 = 697;
F2 = 1477;
case 'A'
F1 = 697;
F2 = 1633;
case 4
F1 = 770;
F2 = 1209;
case 5
F1 = 770;
F2 = 1336;
case 6
F1 = 770;
F2 = 1477;
case 'B'
F1 = 770;
F2 = 1633;
case 7
F1 = 852;
F2 = 1209;
case 8
F1 = 852;
F2 = 1336;
case 9
F1 = 852;
F2 = 1477;
case 'C'
F1 = 852;
F2 = 1633;

case '*'
F1 = 941;
F2 = 1209;
case '#'
F1 = 941;
F2 = 1477;
otherwise
F1 = 941;
F2 = 1633;
end;
firstsine = cos(2*pi*F1*T);
sinusoidal signal
secondsine = cos(2*pi*F2*T);
second sinusoidal signal
d = firstsine + secondsine;
dtmfoutput = d ;
figure(1);
title('THE DTMF OUTPUT');
plot(dtmfoutput);

% first
%

after 5 th program 19 and 20 programs


mentioned

21. program for I/D sampling rate


converters
clc;
close all;

clear all;
L = 7;
M = 2;
N = 30;
n = 0:N-1;
x = sin(2*pi*0.43*n) + sin(2*pi*0.31*n);
y = resample(x,L,M);
subplot(2,1,1);
stem(n,x(1:N));
axis([0 29 -2.2 2.2]);

title('Input Sequence');
xlabel('Time index n');
ylabel('Amplitude');
subplot(2,1,2);
m = 0:(N*L/M)-1;
stem(m,y(1:N*L/M));
axis([0 (N*L/M)-1 -2.2 2.2]);
title('Output Sequence');
xlabel('Time index n');
ylabel('Amplitude');

Das könnte Ihnen auch gefallen