Untitled
unknown
plain_text
10 months ago
5.5 kB
14
Indexable
Never
R PROGRAM: EXPONENTIAL: clc clear all close all n=0:2:40; A=2; a=-0.2; x=A*exp(a*n); stem(n,x); xlabel('sampel'); ylabel('mag'); title('expsig'); SINUISOIDAL: clc; clear all; close all; n=-20:0.1:20; A=2; fi=0.1; x=A*sin(2*pi*fi*n); stem(n,x); xlabel('sample'); ylabel('mag'); title('sinsig'); RAMP SIGNAL: clc; clear all; close all; n=-20:1:20; x=zeros(size(n)); for i=1:length(n) if n(i)>0 x(i)=n(i) end end stem(n,x); xlabel('sample'); ylabel('mag'); title('rampsignal'); Experiment 2(Correlation) clc clear all close all a=[-5,-3,-1,0,1,3,5]; b=[1,1,1,0,1,1,1]; z=xcorr(a); y=xcorr(b); x=xcorr(a,b); figure; n=-6:6; m=-3:3; subplot(5,1,1); stem(m,a); subplot(5,1,2); stem(m,b); subplot(5,1,3); stem(n,z); subplot(5,1,4); stem(n,y); subplot(5,1,5); stem(n,x); Experiment 3(Convolution) clear all close all x=[-4,-3,-2,0,1,2,3] y=[0,1,1,2,1,1,0] z=conv(x,y) figure; subplot(3,1,1) stem(-3:3,x) subplot(3,1,2) stem(-3:3,y) subplot(3,1,3) stem(-6:6,z) Experiment4(Z transform) clc clear all close all num=[-3 2 2 4 6 8]; den=[1 3 6.5 12 16 18 ]; N=max(length(num),length(den)); h=impz(num,den,N+1); figure; stem(h); Experiment5(DTFT) clc clear all close all w= -4*pi: pi/256: 4*pi; num=[1 0.6]; den=[1 0.3 -0.8]; h=freqz(num,den,w); figure; plot(w,abs(h)); title('Magnitude response'); figure; plot(w,angle(h)); title('Phase response'); Experiment6(DFT) clc clear all close all w= -4*pi: pi/256: 4*pi; num=[1 0.6]; den=[1 0.3 -0.8]; h=freqz(num,den,w); figure; plot(w,abs(h)); title('Magnitude response'); figure; plot(w,angle(h)); title('Phase response'); Experiment7(Circular COnvolution) R PROGRAM clc clear all close all x1=[1,2,-3,4]; x2=[1,0,2,0]; N=length(x1); X1=fft(x1,N); X2=fft(x2,N); Y=X1.*X2; y=ifft(Y,N); stem(y) z=cconv(x1,x2,z); stem(z) Experiment8(Butterworth) clc clear all close all f1=10; f2=20; fc=15; fs=500; t=0:0.02:1; x=2*sin(2*pi*f1*t)+3*cos(2*pi*f2*t); [b,a]=butter(6,fc/(fs/2)); freqz(b,a,[],fs); xf=filter(b,a,x); figure; plot(t,x); figure; plot(t,xf); clc clear all close all f1=10; f2=20; fc=25; fs=500; t=0:0.02:10; x=2*sin(2*pi*f1*t)+3*cos(2*pi*f2*t); [b,a]=butter(6,fc/(fs/2)); freqz(b,a,[],fs); xf=filter(b,a,x); figure; plot(t,x); figure; plot(t,xf); Experiment 9(Chebyshev) clc; close all; f1=10; f2=20; fc=30; fs=70; t=0:1/fs:5; N=5; x=10*sin(2*pi*f*t)+2*cos(2*pi*f2*t); [b,a]=cheby1(N,3,(fc*2/fs)); figure; freqz(b,a,[],fs); xf=filter(b,a,x); figure; plot(t,x); figure; plot(t,xf); Experiment10(using windowing) Low Pass clc; close all; f1=100; f2=200; f3=300 fs=1000; fc1=150; fc2=250; t=0:1/fs:0.2; N=30; x1=10*sin(2*pi*f1*t); x2=2*cos(2*pi*f2*t); x3=5*sin(2*pi*f3*t); x=10*sin(2*pi*f1*t)+2*cos(2*pi*f2*t)+5*sin(2*pi*f3*t); b=fir1(N,[fc1/(fs/2)],'low',boxcar(N+1)); figure; freqz(b,1,N); xf=filter(b,1,x); figure; plot(t,xf); figure; plot(t,x1) High Pass clc; close all; f1=100; f2=200; f3=300 fs=1000; fc1=150; fc2=250; t=0:1/fs:0.2; N=30; x1=10*sin(2*pi*f1*t); x2=2*cos(2*pi*f2*t); x3=5*sin(2*pi*f3*t); x=10*sin(2*pi*f1*t)+2*cos(2*pi*f2*t)+5*sin(2*pi*f3*t); b=fir1(N,[fc2/(fs/2)],'high',hamming(N+1)); figure; freqz(b,1,N); xf=filter(b,1,x); figure; plot(t,xf); figure; plot(t,x3); Bandpass clc; close all; f1=100; f2=200; f3=300 fs=1000; fc1=150; fc2=250; t=0:1/fs:0.2; N=30; x1=10*sin(2*pi*f1*t); x2=2*cos(2*pi*f2*t); x3=5*sin(2*pi*f3*t); x=10*sin(2*pi*f1*t)+2*cos(2*pi*f2*t)+5*sin(2*pi*f3*t); b=fir1(N,[fc1/(fs/2) fc2/(fs/2)],'bandpass',boxcar(N+1)); figure; freqz(b,1,N); xf=filter(b,1,x); figure; plot(t,xf); figure; plot(t,x2); Experiment11(FIR Parks Mccanson Approach) Low Pass Filter clc clear all close all F = [0,0.3,0.4,0.7,0.8,1]; A = [0,0,1,1,0,0]; f1 = 100; f2 = 200; f3 = 300; N = 30; t = 0.1:1/500:0.2; x = 2*sin(2*pi*f1*t) + 5*cos(2*pi*f2*t) + 4*cos(2*pi*f3*t); x1 = 2*sin(2*pi*f1*t); x2 = 2*sin(2*pi*f2*t); x3 = 2*sin(2*pi*f3*t); b = firpm(N,F,A); figure; freqz(b,1,N) figure; plot(t,x) xf = filter(b,1,x); figure; plot(t,xf) High Pass Filter- clc clear all close all F = [0,0.3,0.4,0.7,0.8,1]; A = [0,0,0,0,1,1]; f1 = 100; f2 = 200; f3 = 300; N = 30; t = 0.1:1/500:0.2; x = 2*sin(2*pi*f1*t) + 5*cos(2*pi*f2*t) + 4*cos(2*pi*f3*t); x1 = 2*sin(2*pi*f1*t); x2 = 2*sin(2*pi*f2*t); x3 = 2*sin(2*pi*f3*t); b = firpm(N,F,A); figure; freqz(b,1,N) figure; plot(t,x) xf = filter(b,1,x); figure; plot(t,xf) Band Pass Filter- clc clear all close all F = [0,0.3,0.4,0.7,0.8,1]; A = [0,0,1,1,0,0]; f1 = 100; f2 = 200; f3 = 300; N = 30; t = 0.1:1/500:0.2; x = 2*sin(2*pi*f1*t) + 5*cos(2*pi*f2*t) + 4*cos(2*pi*f3*t); x1 = 2*sin(2*pi*f1*t); x2 = 2*sin(2*pi*f2*t); x3 = 2*sin(2*pi*f3*t); b = firpm(N,F,A); figure; freqz(b,1,N) figure; plot(t,x) xf = filter(b,1,x) figure; plot(t,xf) Band Stop Filter- clc clear all close all F = [0,0.3,0.4,0.7,0.8,1]; A = [0,0,1,1,0,0]; f1 = 100; f2 = 200; f3 = 300; N = 30; t = 0.1:1/500:0.2; x = 2*sin(2*pi*f1*t) + 5*cos(2*pi*f2*t) + 4*cos(2*pi*f3*t); x1 = 2*sin(2*pi*f1*t); x2 = 2*sin(2*pi*f2*t); x3 = 2*sin(2*pi*f3*t); b = firpm(N,F,1-A); figure; freqz(b,1,N) figure; plot(t,x) xf = filter(b,1,x) figure; plot(t,xf)