Posts

Upsampler

  clc ; clear ; close ; x = 0 : 5 ; disp ( " squareroot " ,sa1 ) ; y = [ ] ; for i = 1 : 6 y ( 1 , 2 * i ) = x ( i ) ; end subplot ( 1 , 2 , 1 ) ; plot2d3 ( x ) ; subplot ( 1 , 2 , 2 ) ; plot2d3 ( y ) ;

Dead Band for Second order System

  clc ; clear ; close ; n = - 1 ; y = 12 ; while n < 8 n = n + 1 ; y = [ y 0.9 * y ( n + 1 ) ] ; end disp ( y ) ; disp ( [ - y ( n + 2 ) y ( n + 2 ) ] )

FIR Filter

  clear ; clc ; close ; N = 7 ; U = 4 ; a = window ( ' re ' ,N ) ; for n = - 3 + U : 1 : 3 + U if ( n == 4 ) h ( n ) = 0.4 ; else h ( n ) = ( sin ( 2 * %pi * ( n - U ) / 5 ) / %pi * ( n - U ) ) ; end h1 ( n ) = h ( n ) * a ( n ) ; end [ av,ba ] = frmag ( h1, 256 ) ; pu = 20 * log10 ( av ) / max ( av ) ; plot ( 2 * ba,pu ) ; xgrid ( 2 ) ;

IIR Filter

  clc ; clear ; close ; z = poly ( 0 , ' z ' ) ; numerator = - 0.405 - 0.810 * z - 0.405 * z ^ 2 ; denominator = 0.202 + 0.404 * z + z ^ 2 ; h = numerator / denominator; // Compute the magnitude response [ hzm, fr ] = frmag ( h, 256 ) ; plot ( fr, hzm ) ; title ( ' Lowpass Butterworth Filter Response ' ) ; ylabel ( ' Amplitude -- > ' ) ; xlabel ( ' Normalized Frequency (f/fs) -- > ' ) ;

Compute Convolution for Longer Sequence

  clc ; clear ; close ; h1 = [ - 1 , 1 ] ; l1 = [ 1 , 2 , 3 , 4 , 4 , 3 , 2 , 1 ] ; h2 = [ 1 , 2 ] ; l2 = [ 1 , 2 , - 1 ] ; s3 = convol ( l2,h2 ) ; disp ( s3 ) ; length1 = length ( h1 ) ; length2 = length ( l1 ) ; total = length2 - length1; //h1=[h1 zeros(1,total)]; s2 = convol ( h1,l1 ) ; disp ( s2 ) ;

Spectrum Analysis using DFT

 Program: clc ; clear ; close ; fs = 125 ; fm = 10 ; m = 2 ; t = 0.0001 : 1 / fs : m / fm; x = 3 * cos ( 2 * %pi * fm * t ) ; N = ( m * fs / fm ) for k = 1 : N X1 ( k ) = 0 ; for n = 1 : length ( x ) X1 ( k ) = X1 ( k ) + x ( n ) .* exp ( ( - %i ) * 2 * %pi * ( n - 1 ) * ( k - 1 ) / N ) end end subplot ( 1 , 2 , 1 ) ; plot2d3 ( t,x ) ; k = 0 : N - 1 ; f = k * fs / N; subplot ( 1 , 2 , 2 ) ; plot2d3 ( f, abs ( X1 ) ) ;

Computation of DFT Using Basic Equation of FFT and Power Spectrum Estimating using DFT

Image
Program: clc ; clear ; x = [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 ] ; N = 8 ; n = 0 : N - 1 ; x = clean ( fft ( x ) ) ; y = clean ( ifft ( x ) ) ; mag = abs ( x ) ; phase = atan ( x ) ; disp ( " fft value was " ,x ) ; disp ( " ifft value was " ,y ) ; subplot ( 1 , 3 , 1 ) ; plot2d3 ( n,x ) ; xlabel ( " n-value " ) ; ylabel ( " amplitude of x(n) " ) ; title ( " Input sequence " ) ; subplot ( 1 , 3 , 2 ) ; plot2d3 ( n,mag ) ; xlabel ( " n value " ) ; ylabel ( " Magnitude of x(n) " ) ; title ( " Magnitude plot " ) ; subplot ( 1 , 3 , 3 ) ; plot2d3 ( n,phase ) ; xlabel ( " n value " ) ; ylabel ( " Phase of x(n) " ) ; title ( " Phase plot " ) ; Output