Professional Documents
Culture Documents
n1=input('Enter the range of the first sequence'); x1=input('Enter the first sequence'); n2=input('Enter the range of the second
sequence'); x2=input('Enter the second sequence'); n=min(min(n1),min(n2)):max(max(n1),max(n2)); y1=zeros(1,length(n));
y2=y1;
y1(find((n>=min(n1))&(n<=max(n1))==1))=x1; y2(find((n>=min(n2))&(n<=max(n2))==1))=x2;
y=y1+y2; subplot(2,2,1); stem(n1,x1); title('First seq. x1(n)'); xlabel('sample'); ylabel('amplitude');
subplot(2,2,2); stem(n2,x2); title('Second seq. x2(n)'); xlabel('sample'); ylabel('Amplitude');
subplot(2,1,2);stem(n,y) title('addition of signal'); xlabel('sample'); ylabel('Amplitude');
clc;close all;
N=input('Enter the range'); xn1=input('Enter the 1st sequence');
xn2=input('Enter the 2nd sequence'); Xk1=fft(xn1); Xk2=fft(xn2); Xk3=Xk1.*Xk2; xn3=ifft(Xk3);
subplot(3,1,1); stem(xn1); title('1st Sequence');
subplot(3,1,2); stem(xn2); title('2nd Sequence');
subplot(3,1,3); stem(abs(xn3)); title('IFFT');
n1=input('enter the range of x'); x=input('sequence x'); n2=input('range of h'); h=input('sequence h');
n=(min(n1)+min(n2)):(max(n1)+max(n2)); y=conv(x,h); stem(n,y);
subplot(2,2,1); stem(n1,x); title('First seq. x'); xlabel('Sample'); ylabel('Amplitude');
subplot(2,2,2); stem(n2,h); title('Second seq. h'); xlabel('Sample'); ylabel('Amplitude');
subplot(2,1,2); stem(n,y); title('Convolution of signal'); xlabel('Sample'); ylabel('Amplitude');
x=input('Enter 1st Sequence'); h=input('Enter 2nd Sequence'); y=xcorr(x,h); subplot(3,1,1); stem(x); xlabel('a(n)');
ylabel('Amplitude');
subplot(3,1,2); stem(h); xlabel('b(n)'); ylabel('Amplitude'); subplot(3,1,3); stem(fliplr(y)); xlabel('c(n)'); ylabel('Amplitude');
clc,close all,clear all; x=input('Enter 1st Sequence'); h=input('Enter 2nd Sequence'); b=(fliplr(h)); y=conv(x,b); subplot(3,1,1);
stem(x); xlabel('a(n)'); ylabel('Amplitude'); subplot(3,1,2); stem(h); xlabel('b(n)'); ylabel('Amplitude'); subplot(3,1,3);
stem(fliplr(y)); xlabel('c(n)'); ylabel('Amplitude');
clc;close all; N=input('Enter the range'); xn=input('Enter the sequence');
n=[0:1:N-1]; k=[0:1:N-1]; WN=exp(-j*2*pi/N); nk=n'*k; WNnk=WN.^nk; Xk=xn*WNnk;
subplot(2,2,1); stem(xn); title('Input Sequence');
subplot(2,2,2); stem(abs(Xk)); title('Magnitude of DFT');
subplot(2,2,3); stem(angle(Xk)); title('Phase of DFT');
n=[0:1:N-1]; k=[0:1:N-1]; WN=exp(-j*2*pi/N); nk=n'*k; WNnk=WN.^(-nk); Xk1=(Xk*WNnk)/N;
subplot(2,2,4); stem(abs(Xk1)); title('Magnitude of IDFT');
% Band-pass filter
wn=[wp ws]; b=fir1(n,wn,y); [h,o]=freqz(b,1,256); m=20*log10(abs(h));
subplot(2,2,3); plot(o/pi,m); ylabel('gain in dB'); xlabel('(c) normalized frequency')
% Band stop filter
b=fir1(n,wn,'stop',y); [h,o]=freqz(b,1,256); m=20*log10(abs(h));
subplot(2,2,4); plot(o/pi,m); ylabel('gain in dB'); xlabel('(d) normalized frequency')
n=input('Enter the range of the sequence'); x=input('Enter the sequence');subplot(2,1,1); stem(n,x); title('Original seq. x(n)');
xlabel('sample'); ylabel('Amplitude'); y=fliplr(x); subplot(2,1,2); stem(n,y); title('Folded seq. x(-n)'); xlabel('sample');
ylabel('Amplitude');
clc; clear all; close all; rp=input('enter the passband ripple'); rs=input('enter the stopband ripple');
wp=input('enter the passband freq'); ws=input('enter the stopband freq');
fs=input('enter the sampling freq'); w1=2*wp/fs; w2=2*ws/fs; [n, wn] = buttord(w1, w2, rp, rs, 's');
% Design the Filter
[z,p,k] = butter(n,wn,'s'); [b,a]=zp2tf(z,p,k); [b,a] = butter(n,wn,'s'); W=0:0.01:pi;
[h,om]=freqs(b,a,W); m=20*log10(abs(h)); an =angle(h);
subplot(2,1,1); plot(om/pi,m); ylabel('gain in dB'); xlabel('(a) normalized frequency');
subplot(2,1,2); plot(om/pi,an); ylabel('phase in radian'); xlabel('(b) normalized frequency');
clc; clear all; close all; rp=input('enter the passband ripple'); rs=input('enter the stopband ripple');
fp=input('enter the passband freq'); fs=input('enter the stopband freq');
f=input('enter the sampling freq'); wp=2*fp/f;ws=2*fs/f; [n] = cheb1ord(wp,ws,rp,rs,'s');
wn=[wp ws]; [b,a] = cheby1 (n,rp, wn, 'bandpass','s'); W=0:0.01:pi; [h,om]=freqs(b,a,W);
m=20*log10(abs(h)); an=angle(h); subplot(2,1,1); plot(om/pi,m); ylabel('gain in dB');
xlabel('(a) normalized frequency'); subplot(2,1,2); plot(om/pi,an); ylabel('phase in radian'); xlabel('(b) normalized frequency');
% n1=input('Enter the lower range'); % n2=input('Enter the upper range'); % n0=input('Enter the reference point'); function
[n,x]=rampseq(n0,n1,n2); n=[0:n2]; x=n; plot(n,x); xlabel('samples n'); ylabel('Amplitude'); title('Ramp Sequence');
n=input('Enter the range of the sequence'); x=input('Enter the sequence'); a=input('Enter the scaling factor'); subplot(2,1,1);
stem(n,x);
title('Original seq. x(n)'); xlabel('sample'); ylabel('Amplitude'); y=a*x; subplot(2,1,2); stem(n,y); title('shifting of x(n)');
xlabel('sample'); ylabel('amplitude');
A=1; t=0:0.01:2*pi; f=1; s=A*sin(t); c=A*cos(t); plot(t,s,t,c); xlabel('time'); ylabel('Amplitude'); grid on;
n=input('Enter the value of n'); m=-n:n; i=[zeros(1,n) 1 ones(1,n)]; stem(m,i); xlabel('Range of n'); ylabel('Amplitude'); title('Unit
Step Sequence');