Posts

Showing posts from December, 2023

8. Implement a Low pass / High pass / Band pass / Band stop IIR Filter using Butterworth approximation.

Image
 

7. Design FIR Low pass filter using a) Rectangular window b) Hanning window c) Hamming window d) Bartlett window

Image
 

6. Perform the following properties of DFT- a) Circular shift of a sequence. b) Circular fold of a sequence.

 Code: //Circular Shift of a sequence clc; clear all; close; //Circular time shifting property x=input('Enter the input signal'); l=input('Enter the units of shift'); nx=length(x); n1=[0:1:nx-1]; n2=pmodulo(n1-l,nx); y=x(n2+1); disp('Circularly time shifted signal==>'); disp(y); Yk=zeros(1,nx); Xk=fft(x); for j=0:nx-1 Yk(j+1)=Xk(j+1)*exp((-1*%i*2*%pi*j*l)/nx) End disp('DFT of Circularly time shifted signal using the property==>'); disp(round(Yk)); Yk1=fft(y); disp('DFT of Circularly time shifted signal is ==>'); disp((Yk1)); Code: clc; clear all; close; //Circular time reversal property x=[1 2 3 4 6 8]; disp('Input signal x(n)==>'); disp(x); Xk=fft(x); disp('DFT of x(n)==>'); disp(Xk); nx=length(x); n1=[0:1:nx-1]; n2=pmodulo(-n1,nx); y=x(n2+1); disp('Circularly time reversed signal x(-n)==>'); disp(y); //DFT of x(-n) is X(-k) N=length(x); k=n1; k1=pmodulo(-k,N); Yk=Xk(k1+1); disp('DFT of Circularly ti...

5. To find N point DFT and plot its magnitude and phase spectra. To find N point DFT and plot its magnitude and phase spectra.

 Code: //To calculate DFT of the sequence: clear all; clc; close; x=input(" Input sequence x :- ") nl=input("length of input sequence :- ") if length(x)<nl then x=[x zeros(1,nl-length(x))] end n=0:nl-1; k=0:nl-1; //dft Xdft= x*exp(-%i*((2*%pi)/nl)* k'*n); //dft formula Xdft1=fft(x); // direct Command //Idft Xidft = (Xdft*exp(%i*((2*%pi)/nl)* k'*n))/nl; //idft formula Xidft1=ifft(X); /// direct command figure(1); //input sequence subplot(2,2,1); a=gca(); a.x_location="origin"; a.y_location="origin"; plot2d3(n,x) ylabel("x[n]"); xlabel("n"); title("Input sequence"); //DFT sequence 'Xdft' subplot(2,2,2); a=gca(); a.x_location="origin"; a.y_location="origin"; plot2d3(k,Xdft) ylabel("Y[k]"); xlabel("k"); title("DFT sequence"); //IDFT sequence 'Xidft' subplot(2,2,3); a=gca(); a.x_location="origin"; a.y_location="origin"; plot2d...

4. To perform linear convolution from circular convolution and vice versa

 Code: clc; clear all; close; //input sequences x=[1,2,0,3,4,1]; h=[2,0,1,3,1]; //find length of input sequences nx=length(x); nh=length(h); N=nx+nh-1; // Length of linear convolution M=max(nx,nh); // Length of circular convolution Y1=conv(x,h);//Linear convolution //Circular convolution x_len=[x,zeros(1,M-nx)]; h_len=[h,zeros(1,M-nh)]; DFT_x=fft(x_len); DFT_h=fft(h_len); DFT_xh=DFT_x.*DFT_h; circ_xh=ifft(DFT_xh); //Circular Convolution from linear convolution for i=1:M if (i<=(N-M)) then Y2 (i)=Y1(i)+Y1(i+M); else Y2(i)=Y1(i); end end //linear cnvolution from circular convolution X=[x,zeros(1,nh-1)]; H=[h,zeros(1,nx-1)]; x_dft=fft(X); h_dft=fft(H); xh_dft=x_dft.*h_dft; Y3= ifft(xh_dft); //Display various sequences on console window disp(x,"Input Sequence x"); disp(h,"Input Sequence h"); disp(Y1,"Linearly Convolved sequence using conv function"); disp(circ_xh,"Circularly Convolved sequence using fft function"); disp(Y3," Linear Convolutio...

3. To find linear and circular cross convolution.

 Code: clc; clear all; close; //linear convolution x=[1,2,3,4,5];// First Signal y=[1,2,1,2];// Second Signal y=mtlb_fliplr(y); nx=length(x); ny=length(y); N=nx+ny-1; n1=0:nx-1; n2=0:ny-1; n=0:nx+ny-2; X_lin=[x,zeros(1,ny-1)]; //append zeros to make length equal to nx+nh-1 Y_lin=[y,zeros(1,(nx-1))]; //append zeros to make length equal to nx+nh-1 // Formation of Toeplitz Matrix for i=1:N for j=1:N if (i<j) then Y2_lin(i,j)=0; else Y2_lin(i,j)=Y_lin(i-j+1); end end end rxy_lin=Y2_lin*X_lin'; // matrix multiplication to obtain linear correlation disp('The first signal x(n) is '); disp(x); disp('The second signal y(n) is '); disp(y); disp('The toeplitz matrix of y(n)to calculate linear correlation is '); disp(Y2_lin); disp('The linear correlation for x(n)and y(n) is '); disp(rxy_lin'); //Plotting of the signals figure(1); subplot(2,2,1); a=gca(); a.x_location="origin"; a.y_location="origin"; plot2d3(n1,x); a.children.children.f...

2. To find linear and circular convolution.

 Code: clc; clear all; close; //linear convolution x=[1,2,3,4,5]; // First Signal h=[1,2,1,2]; // Second Signal nx=length(x); nh=length(h); N=nx+nh-1; n1=0:nx-1; n2=0:nh-1; n=0:nx+nh-2; X_lin=[x,zeros(1,nh-1)]; //append zeros to make length equal to nx+nh-1 H_lin=[h,zeros(1,(nx-1))]; //append zeros to make length equal to nx+nh-1 // Formation of Toeplitz Matrix for i=1:N for j=1:N if (i<j) then X2_lin(i,j)=0; else X2_lin(i,j)=X_lin(i-j+1); end end end Y_lin=X2_lin*H_lin';// matrix multiplication to obtain linear convolution disp('The first signal x(n) is '); disp(x); disp('The second signal h(n) is '); disp(h); disp('The toeplitz matrix of x(n) to calculate linear convolution is '); disp(X2_lin); disp('The linear convolution for x(n)and h(n) is '); disp(Y_lin'); //Plotting of the signals figure(1); subplot(2,2,1); a=gca(); a.x_location="origin"; a.y_location="origin"; plot2d3(n1,x); a.children.children.foreground=5; xtitle(...

1. Generation of basic signals sine, cosine, ramp, step, impulse and exponential in continuous and discrete domains using user defined functions.

 Code: //Continuous Waveform clc; clear all; close; function y=ramp(t) m=length(t); for i=1:m if t(i)>=0 then y(i)=t(i); else y(i)=0; end end return endfunction function y=impulse(t) m=length(t); for i=1:m if t(i)==0 then y(i)=1; else y(i)=0; end end return endfunction function y=unit(t) m=length(t); for i=1:m if t(i)>=0 then y(i)=1; else y(i)=0; end end return endfunction function y=cosine(t) y=0.5*(exp(%i*w*t)+exp(-1*%i*w*t)); return endfunction function y=sine(t) y=0.5*-1*%i*(exp(%i*w*t)-exp(-1*%i*w*t)); return endfunction function y=exponential(b, t) y=exp(b*t) return endfunction t1=-5:0.1:20; t2=-5:0.001:30; t3=0:0.1:10; figure(1); subplot(2,3,1); a=gca(); a.x_location="origin"; a.y_location="origin"; plot2d(t2,impulse(t2)); a.children.children.foreground=5 xtitle('continuous impulse function','time','amplitude'); figure(1); subplot(2,3,2); a=gca(); a.x_location="origin"; a.y_location="origin"; plot2d(t2,unit(t2...