1. INTRODUCTION TO DSP PROCESSORS A signal can be defined as a function that conveys information, generally about the state or behavior of a physical system. There are two basic types of signals viz Analog (continuous time signals which are defined along a continuum of times) and Digital (discrete-time). Remarkably, under reasonable constraints, a continuous time signal can be adequately represented by samples, obtaining discrete time signals. Thus digital signal processing is an ideal choice for anyone who needs the performance advantage of digital manipulation along with today’s analog reality. Hence a processor which is designed to perform the special operations (digital manipulations) on the digital signal within very less time can be called as a Digital signal processor. The difference between a DSP processor, conventional microprocessor and a Microcontroller is listed below. Microprocessor or General Purpose Processor such as Intel xx86 or Motorola 680xx family Contains - only CPU -No RAM -No ROM -No I/O ports -No Timer Microcontroller such as 8051 family Contains - CPU - RAM - ROM -I/O ports - Timer & - Interrupt circuitry Some Micro Controllers also contain A/D, D/A and Flash Memory DSP Processors such as Texas instruments and Analog Devices Contains - CPU - RAM -ROM - I/O ports - Timer Optimized for – fast arithmetic - Extended precision - Dual operand fetch - Zero overhead loop - Circular buffering 1 The basic features of a DSP Processor are Feature Use Fast-Multiply accumulate Most DSP algorithms, including filtering, transforms, etc. are multiplication- intensive Multiple – access memory architecture Many data-intensive DSP operations require reading a program instruction and multiple data items during each instruction cycle for best performance Specialized addressing modes Efficient handling of data arrays and first-in, first-out buffers in memory Specialized program control Efficient control of loops for many iterative DSP algorithms. Fast interrupt handling for frequent I/O operations. On-chip peripherals and I/O interfaces On-chip peripherals like A/D converters allow for small low cost system designs. Similarly I/O interfaces tailored for common peripherals allow clean interfaces to off-chip I/O devices. 2 2. ARCHITECTURE OF 6713 DSP PROCESSOR This chapter provides an overview of the architectural structure of the TMS320C67xx DSP, which comprises the central processing unit (CPU), memory, and on-chip peripherals. The C67xE DSPs use an advanced modified Harvard architecture that maximizes processing power with eight buses. Separate program and data spaces allow simultaneous access to program instructions and data, providing a high degree of parallelism. For example, three reads and one write can be performed in a single cycle. Instructions with parallel store and application-specific instructions fully utilize this architecture. In addition, data can be transferred between data and program spaces. Such Parallelism supports a powerful set of arithmetic, logic, and bit-manipulation operations that can all be performed in a single machine cycle. Also, the C67xx DSP includes the control mechanisms to manage interrupts, repeated operations, and function calling. Fig 2 – 1 BLOCK DIAGRAM OF TMS 320VC 6713 3 Bus Structure The C67xx -bit buses (four program/data buses and four address buses): The program bus (PB) carries the instruction code and immediate operands from program memory. Three data buses (CB, DB, and EB) interconnect to various elements, such as the CPU,data address generation logic, program address generation logic, onchip peripherals, and data memory. The CB and DB carry the operands that are read from data memory.The EB carries the data to be written to memory. Four address buses (PAB, CAB, DAB, and EAB) carry the addresses needed for instruction execution. The C67xx DSP can generate up to two data-memory addresses per cycle using the two auxiliary register arithmetic units (ARAU0 and ARAU1). The PB can carry data operands stored in program space (for instance, a coefficient table) to the multiplier and adder for multiply/accumulate operations or to a destination in data space for data move instructions (MVPD and READA). This capability, in conjunction with the feature of dual-operand read, supports the execution of single-cycle, 3-operand instructions such as the FIRS instruction. The C67xx DSP also has an on-chip bidirectional bus for accessing on-chip peripherals. This bus is connected to DB and EB through the bus exchanger in the CPU interface. Accesses that use this bus can require two or more cycles for reads and writes, depending on the peripheral’s structure. Central Processing Unit (CPU) The CPU is common to all C67xE devices. The C67x CPU contains: 40-bit arithmetic logic unit (ALU) Two 40-bit accumulators Barrel shifter 17 X 17-bit multiplier 40-bit adder Compare, select, and store unit (CSSU) Data address generation unit Program address generation unit Arithmetic Logic Unit (ALU) The C67x DSP performs 2s-complement arithmetic with a 40-bit arithmetic logic unit (ALU) and two 40-bit accumulators (accumulators A and B). The ALU can also perform Boolean operations. The ALU uses these inputs: 16-bit immediate value 16-bit word from data memory 16-bit value in the temporary register, T Two 16-bit words from data memory 4 32-bit word from data memory 40-bit word from either accumulator The ALU can also function as two 16-bit ALUs and perform two 16-bit operations simultaneously. Fig 2 – 2 ALU UNIT 5 Accumulators Accumulators A and B store the output from the ALU or the multiplier/adder block. They can also provide a second input to the ALU; accumulator A can be an input to the multiplier/adder. Each accumulator is divided into three parts: Guard bits (bits 39–32) High-order word (bits 31–16) Low-order word (bits 15–0) Instructions are provided for storing the guard bits, for storing the high- and the low order accumulator words in data memory, and for transferring 32-bit accumulator words in or out of data memory. Also, either of the accumulators can be used as temporary storage for the other. Barrel Shifter The C67x DSP barrel shifter has a 40-bit input connected to the accumulators or to data memory (using CB or DB), and a 40-bit output connected to the ALU or to data memory (using EB). The barrel shifter can produce a left shift of 0 to 31 bits and a right shift of 0 to 16 bits on the input data. The shift requirements are defined in the shift count field of the instruction, the shift count field (ASM) of status register ST1, or in temporary register T (when it is designated as a shift count register).The barrel shifter and the exponent encoder normalize the values in an accumulator in a single cycle. The LSBs of the output are filled with 0s, and the MSBs can be either zero filled or sign extended, depending on the state of the sign-extension mode bit (SXM) in ST1. Additional shift capabilities enable the processor to perform numerical scaling, bit extraction, extended arithmetic, and overflow prevention operations. Multiplier/Adder Unit The multiplier/adder unit performs 17 X 17-bit 2s-complement multiplications with a 40- bit addition in a single instruction cycle. The multiplier/adder block consists of several elements: a multiplier, an adder, signed/unsigned input control logic, fractional control logic, a zero detector, a rounder (2s complement), overflow/saturation logic, and a 16-bit temporary storage register (T). The multiplier has two inputs: one input is selected from T, a data-memory operand, or accumulator A; the other is selected from program memory, data memory, accumulator A, or an immediate value. The fast, on-chip multiplier allows the C54x DSP to perform operations efficiently such as convolution, correlation, and filtering. In addition, the multiplier and ALU together execute multiply/accumulate (MAC) computations and ALU operations in parallel in a single instruction cycle. This function is used in determining the Euclidian distance and in implementing symmetrical and LMS filters, which are required for complex DSP algorithms. See section 4.5, Multiplier/Adder Unit, on page 4-19, for more details about the multiplier/adder unit. 6 Fig 2 – 3 MULTIPLIER/ADDER UNIT These are the some of the important parts of the processor and you are instructed to go through the detailed architecture once which helps you in developing the optimized code for the required application. 7 3. FREQUENCY RESPONSE OF A GIVEN SYSTEM GIVEN IN (TRANSF ER FUNCTION/ DIFFERENCE EQUATION FORM) AIM: To find the frequency response of the given LTI system given in difference equation form or Transfer function form and plot the same. SOFTWARE REQUIRED: MATLAB 7.0 or Above. MATLAB CODE: clc; clear all; close all; num=input('type the numerator vector: '); den=input('type the denominator vector: '); N= input(' enter the number of frequency points: '); w=0:pi/N:pi; H=freqz(num,den,w); figure; subplot(2,1,1); plot(w/pi,real(H)); xlabel('\omega/\pi'); ylabel('Amplitude'); title('real part'); subplot(2,1,2); plot(w/pi,imag(H)); xlabel('\omega/\pi'); ylabel('Amplitude'); title('imag part'); figure; subplot(2,1,1); plot(w/pi,abs(H)); xlabel('\omega/\pi'); ylabel('Magnitude'); title('Magnitude spectrum'); subplot(2,1,2); plot(w/pi,angle(H)); xlabel('\omega/\pi'); ylabel('phase(radians)'); title('Phase spectrum'); OUTPUT: type the numerator vector: [0.5 0 0.5] type the denominator vector: 1 enter the number of frequency points: 512 8 GRAPHS: real part Amplitude 1 0.5 0 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 0.6 0.7 0.8 0.9 1 0.7 0.8 0.9 1 0.7 0.8 0.9 1 / imag part Amplitude 0.5 0 -0.5 0 0.1 0.2 0.3 0.4 0.5 / Magnitude spectrum Magnitude 1 0.5 0 0 0.1 0.2 0.3 0.4 0.5 0.6 / Phase spectrum phase(radians) 2 1 0 -1 -2 0 0.1 0.2 0.3 0.4 0.5 0.6 / INFERENCE : The frequency response of the given system is generated using the ‘freqz’ command. The real part is the real part of the complex number representing the transfer function of the given system and the imaginary part is the imaginary part of the transfer function. The magnitude plot is the absolute value of magnitude versus the frequency and the phase plot is the phase angle versus the frequency is plotted for different systems. This program is very simple and requires defining the system and finding Frequency response and plotting. RESULT: The frequency response of the given system is found and the real and imaginary parts along with the magnitude and phase plots of the same are plotted. 9 10 11 4. IMPULSE RESPONSE OF A GIVEN SYSTEM (OF ANY ORDER) AIM: To find the impulse response of the given LTI system given in difference equation form or Transfer function form of any order and plot the same. SOFTWARE REQUIRED: MATLAB 7.0 or Above. MATLAB CODE: clc; clear all; close all; num=input('type the numerator vector'); den=input('type the denominator vector'); N= input(' enter the desired length of the output sequence'); n=0:N-1; imp=[1 zeros(1,N-1)]; H=filter(num,den,imp); disp(' the impulse response of the system is '); disp(H); stem(n,H); xlabel('time index'); ylabel('h(n)'); title(' Impulse response of the given system'); OUTPUT: type the numerator vector[ 1 2 -2 -1 2] type the denominator vector1 enter the desired length of the output sequence6 the impulse response of the system is 1 2 -2 -1 2 0 GRAPHS: Impulse response of the given system 2 1.5 1 h(n) 0.5 0 -0.5 -1 -1.5 -2 0 0.5 1 1.5 2 2.5 time index 3 3.5 4 4.5 5 12 INFERENCE: The impulse response of the given system is generated using the ‘filter’ command. This program is very simple and requires defining the system and finding impulse response and plotting. RESULT: The impulse response of the given system is found and is plotted. 13 14 15 5. GENERATION OF DISCRETE FOURIER TRANSFORM (DFT) OF A SEQUENCE AIM : To find the Discrete Fourier Transform of a sequence. SOFTWARE REQUIRED : MAT LAB 7.0 PROGRAM DESCRIPTION : In this program the Discrete Fourier Transform (DFT) of a sequence x[n] is generated by using the formula, N-1 X(k) = Σ x(n) e-2πjk / N n=0 Where, X(k) DFT of sequence x[n] N represents the sequence length and it is calculated by using the command ‘length’. The DFT of any sequence is the powerful computational tool for performing frequency analysis of discrete-time signals. MATLAB CODE : clc; clear all; close all; a=input('Enter the sequence :'); N=length(a); disp('The length of the sequence is:');N for k=1:N y(k)=0; for i=1:N y(k)=y(k)+a(i)*exp((-2*pi*j/N)*((i-1)*(k-1))); end; end; k=1:N disp('The result is:');y figure(1); subplot(211); stem(k,abs(y(k))); grid; xlabel('sample values n-->'); ylabel('Amplitudes-->'); title('Mangnitude response of the DFT of given sequence'); subplot(212); stem(angle(y(k))*180/pi); grid; xlabel('sample values n-->'); ylabel('phase-->'); title('Phase response of the DFT of given sequence'); 16 OUTPUTS: Enter the sequence : [1 2 3 4] The length of the sequence is: N = 4 k= 1 2 3 4 The result is: y = 10.0000 -2.0000 + 2.0000i 2.0000i -2.0000 - 0.0000i -2.0000 - GRAPHS : Mangnitude response of the DFT of given sequence Amplitudes--> 10 5 0 1 1.5 1 1.5 2 2.5 3 3.5 sample values n--> Phase response of the DFT of given sequence 4 200 phase--> 100 0 -100 -200 2 2.5 sample values n--> 3 3.5 4 INFERENCE : To perform the frequency analysis on a discrete-time signal x[n] can be generated from a continuous signal x(t). Here in the program y(k) refers to the DFT of the sequence a. The DFT consists of two parts. The magnitude and phase angle of x(k) are calculated by using abs and angle commands and plotted using stem command. RESULT : The Discrete Fourier Transform ( DFT ) of a sequence is obtained and response is plotted. 17 18 19 6. GENERATION OF INVERSE DISCRETE FOURIER TRANSFORM (IDFT) OF A SEQUENCE AIM: To find the Inverse Discrete Fourier Transform of a sequence. SOFTWARE REQUIRED : MAT LAB 7.0 PROGRAM DESCRIPTION : In this program the Inverse Discrete Fourier Transform ( IDFT ) of a sequence X(k) is generated by using the formula, N-1 x [n] =Σ X(k) e2πjk/N n=0 Where, x[n] IDFT of sequence X (k) N represents the sequence length and it is calculated by using the command ‘length’. The IDFT results in the sequence from its DFT. MATLAB CODE : clc; clear all; close all; a=input('Enter the sequence :'); N=length(a); disp('The length of the sequence is:');N for n=1:N y(n)=0; for k=1:N y(n)=y(n)+a(k)*exp((2*pi*j*(k-1)*(n-1))/N); end; end; n=1:N y1=1/N*y(n); disp('The result is:');y1 figure(1); stem(n,y1); grid; xlabel('sample values n-->'); ylabel('Amplitudes-->'); title('Mangnitude response of the IDFT of given DFT'); OUTPUTS: Enter the sequence : [1 0 1 0] The length of the sequence is: N = 4 n= 1 2 3 4 The result is: y1 = 0.5000 0 + 0.0000i 0.5000 - 0.0000i 0 + 0.0000i 20 GRAPHS : Mangnitude response of the IDFT of given DFT 0.5 0.45 0.4 Amplitudes--> 0.35 0.3 0.25 0.2 0.15 0.1 0.05 0 1 1.5 2 2.5 sample values n--> 3 3.5 4 INFERENCE: To perform the frequency analysis on a discrete-time signal x[n] can be generated from a continuous signal x(t). Here in the program IDFT of y(k) results in the sequence a. The IDFT consists of only magnitude response. The magnitude is calculated using abs command and plotted using stem command. RESULT: The Inverse Discrete Fourier Transform ( IDFT ) of a sequence is obtained and response is plotted. 21 22 23 7. FINDING THE FFT OF DIFFERENT SIGNALS AIM : To find the FFT of different signals like impulse, step, ramp and exponential. SOFTWARE REQUIRED: MAT LAB 7.0 PROGRAM DESCRIPTION: In this program using the command FFT for impulse, step, ramp and exponential sequences the FFT is generated. In the process of finding the FFT the length of the FFT is taken as N. The FFT consists of two parts: MAGNITUDE PLOT and PHASE PLOT. The magnitude plot is the absolute value of magnitude versus the samples and the phase plot is the phase angle versus the samples. MATLAB CODE: % FFT of the impulse sequence : magnitude and phase response clc; clear all; close all; %impulse sequence t=-2:1:2; y=[zeros(1,2) 1 zeros(1,2)]; subplot (3,1,1); stem(t,y); grid; input('y='); disp(y); title ('Impulse Response'); xlabel ('time -->'); ylabel ('--> Amplitude'); xn=y; N=input('enter the length of the FFT sequence: '); xk=fft(xn,N); magxk=abs(xk); angxk=angle(xk); k=0:N-1; subplot(3,1,2); stem(k,magxk); grid; xlabel('k'); ylabel('|x(k)|'); subplot(3,1,3); stem(k,angxk); disp(xk); grid; xlabel('k'); ylabel('arg(x(k))'); 24 OUTPUTS: y= 0 0 1 0 0 enter the length of the FFT sequence: 10 1.0000 0.9511i 1.0000 0.9511i 0.3090 - 0.9511i -0.8090 - 0.5878i -0.8090 + 0.5878i 0.3090 + 0.3090 - 0.9511i -0.8090 - 0.5878i -0.8090 + 0.5878i 0.3090 + GRAPHS: --> Amplitude Impulse Response 1 0.5 0 -2 -1.5 -1 -0.5 0 time --> 0.5 1 1.5 2 |x(k)| 1 0.5 0 0 1 2 3 4 5 6 7 8 9 5 6 7 8 9 k arg(x(k)) 5 0 -5 0 1 2 3 4 k 25 % FFT of the step sequence : magnitude and phase response clc; clear all; close all; %Step Sequence s=input ('enter the length of step sequence'); t=-s:1:s; y=[zeros(1,s) ones(1,1) ones(1,s)]; subplot(3,1,1); stem(t,y); grid input('y='); disp(y); title ('Step Sequence'); xlabel ('time -->'); ylabel ('--> Amplitude'); xn=y; N=input('enter the length of the FFT sequence: '); xk=fft(xn,N); magxk=abs(xk); angxk=angle(xk); k=0:N-1; subplot(3,1,2); stem(k,magxk); grid xlabel('k'); ylabel('|x(k)|'); subplot(3,1,3); stem(k,angxk); disp(xk); grid xlabel('k'); ylabel('arg(x(k))'); OUTPUTS: enter the length of step sequence: 5 y= 0 0 0 0 0 1 1 1 1 1 1 enter the length of the FFT sequence: 10 5.0000 -1.0000 + 3.0777i 0 -1.0000 + 0.7265i 0 -1.0000 - 0.7265i 0 -1.0000 - 3.0777i 0 -1.0000 26 GRAPHS: --> Amplitude Step Sequence 1 0.5 0 -5 -4 -1 -2 -3 3 2 1 0 time --> 4 5 |x(k)| 5 0 0 1 2 3 4 5 6 7 8 9 5 6 7 8 9 k arg(x(k)) 5 0 -5 0 1 2 3 4 k 27 % FFT of the Ramp sequence: magnitude and phase response clc; clear all; close all; %Ramp Sequence s=input ('enter the length of Ramp sequence: '); t=0:s; y=t subplot(3,1,1); stem(t,y); grid input('y='); disp(y); title ('ramp Sequence'); xlabel ('time -->'); ylabel ('--> Amplitude'); xn=y; N=input('enter the legth of the FFT sequence: '); xk=fft(xn,N); magxk=abs(xk); angxk=angle(xk); k=0:N-1; subplot(3,1,2); stem(k,magxk); grid xlabel('k'); ylabel('|x(k)|'); subplot(3,1,3); stem(k,angxk); disp(xk); grid xlabel('k'); ylabel('arg(x(k))'); OUTPUTS: enter the length of Ramp sequence: 5 y= 0 1 2 3 4 5 enter the length of the FFT sequence: 10 15.0000 -7.7361 - 7.6942i 2.5000 + 3.4410i 0.8123i -3.0000 2.5000 - 0.8123i -3.2639 + 1.8164i 7.6942i -3.2639 - 1.8164i 2.5000 + 2.5000 - 3.4410i -7.7361 + 28 GRAPHS: --> Amplitude ramp Sequence 5 0 0 0.5 0 1 1 1.5 2 2.5 time --> 3 3.5 4 4.5 5 |x(k)| 20 10 0 2 3 4 5 6 7 8 9 5 6 7 8 9 k arg(x(k)) 5 0 -5 0 1 2 3 4 k 29 % FFT of the Exponential Sequence : magnitude and phase response clc; clear all; close all; %exponential sequence n=input('enter the length of exponential sequence: '); t=0:1:n; a=input('enter "a" value: '); y=exp(a*t); input('y=') disp(y); subplot(3,1,1); stem(t,y); grid; title('exponential response'); xlabel('time'); ylabel('amplitude'); disp(y); xn=y; N=input('enter the length of the FFT sequence: '); xk=fft(xn,N); magxk=abs(xk); angxk=angle(xk); k=0:N-1; subplot(3,1,2); stem(k,magxk); grid; xlabel('k'); ylabel('|x(k)|'); subplot(3,1,3); stem(k,angxk); grid; disp(xk); xlabel('k'); ylabel('arg(x(k))'); OUTPUTS: enter the length of exponential sequence: 5 enter "a" value: 0.8 y= 1.0000 2.2255 4.9530 11.0232 24.5325 54.5982 enter the length of the FFT sequence: 10 98.3324 -73.5207 -30.9223i 50.9418 +24.7831i -41.7941 -16.0579i 38.8873 + 7.3387i -37.3613 38.8873 - 7.3387i -41.7941 +16.0579i 50.9418 -24.7831i -73.5207 +30.9223i 30 GRAPHS : exponential response amplitude 100 50 0 0 0.5 0 1 4 3.5 3 2.5 time 2 1.5 1 4.5 5 |x(k)| 100 50 0 2 3 4 5 6 7 8 9 5 6 7 8 9 k arg(x(k)) 5 0 -5 0 1 2 3 4 k INFERENCE : The FFT for impulse, step, ramp and exponential sequences is generated using the FFT command. The magnitude plot is the absolute value of magnitude versus the samples and the phase plot is the phase angle versus the samples is plotted for different signals for different values. This program is very simple and requires defining the signal and finding FFT and plotting. RESULT : The FFT of different signals like impulse, step, ramp and exponential is found and the magnitude and phase plots of the same is plotted. 31 32 33 8. POWER SPECTRAL DENSITY USING SQUARE MAGNITUDE AND AUTOCORRELATION AIM : To compute the Power Spectral Density of given signals using square magnitude and autocorrelation SOFTWARE REQUIRED : MAT LAB 7.0 PROGRAM DESCRIPTION : The stationary random processes do not have finite energy and hence do not processes a Fourier Transform. Such signals have finite average power and hence are characterized by a Power Density Spectrum or Power Spectral Density (PSD). In this program we have used the property of PSD that it can be calculated from its autocorrelation function by taking the time average. In the Square magnitude method after taking the FFT by taking the absolute value we get the PSD. PROGRAM : clc; clear all; close all; f1=input('Enter the frequency of first sequence in Hz: '); f2=input('Enter the frequency of the second sequence in Hz: '); fs=input('Enter the sampling frequency in Hz: '); t=0:1/fs:1; x=2*sin(2*pi*f1*t)+3*sin(2*pi*f2*t)+rand(size(t)); px1=abs(fft(x).^2); px2=abs(fft(xcorr(x),length(t))); subplot(211) plot(t*fs,10*log10(px1));%square magnitude grid; xlabel('Freq.in Hz-->'); ylabel('Magnitude in dB-->'); title('PSD using square magnitude method'); subplot(212) plot(t*fs,10*log10(px2));%autocorrelation grid; xlabel('Freq.in Hz-->'); ylabel('Magnitude in dB-->'); title('PSD using auto correlation method'); OUTPUTS: Enter the frequency of first sequence in Hz: 200 Enter the frequency of the second sequence in Hz: 400 34 Enter the sampling frequency in Hz: 1000 GRAPHS : PSD using square magnitude method Magnitude in dB--> 100 50 0 -50 0 100 200 0 100 200 300 400 500 600 700 Freq.in Hz--> PSD using auto correlation method 800 900 1000 800 900 1000 Magnitude in dB--> 60 50 40 30 300 400 500 600 Freq.in Hz--> 700 INFERENCE : The only constraint is to take the two frequencies must be two time lesser than the sampling frequencies. RESULT : Hence the PSD is computed using the square magnitude and Autocorrelation and graphs are plotted. 35 36 37 9. IMPLEMENTATION OF LP & HP FIR FILTER FOR A GIVEN SEQUENCE (USING WINDOWING TECHNIQUES) AIM: To implement the FIR filter for a given sequence by using windowing techniques. SOFTWARE REQUIRED: MATLAB 7.0 PROGRAM DESCRIPTION: A Finite Impulse Response (FIR) filter is a discrete linear time-invariant system whose output is based on the weighted summation of a finite number of past inputs. An FIR transversal filter structure can be obtained directly from the equation for discrete-time convolution. N-1 y [n] =Σ X(k) h(n-k) 0< n< N-1 k=0 In this equation, x(k) and y(n) represent the input to and output from the filter at time n. h(n-k) is the transversal filter coefficients at time n. These coefficients are generated by using FDS (Filter Design Software or Digital filter design package). FIR – filter is a finite impulse response filter. Order of the filter should be specified. Infinite response is truncated to get finite impulse response. Placing a window of finite length does this. Types of windows available are Rectangular, Barlett, Hamming, Hanning, Blackmann window etc. This FIR filter is an all zero filter. MATLAB CODE: clc; clear all; close all; rp=input('enter passband ripple'); rs=input('enter the stopband ripple'); fp=input('enter passband freq'); fs=input('enter stopband freq'); f=input('enter sampling freq '); 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) 38 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 %LPF b=fir1(n,wp,y); [h,o]=freqz(b,1,256); m=20*log10(abs(h)); subplot(2,1,1);plot(o/pi,m); title('LPF'); ylabel('Gain in dB-->'); xlabel('(a) Normalized frequency-->'); %HPF b=fir1(n,wp,'high',y); [h,o]=freqz(b,1,256); m=20*log10(abs(h)); subplot(2,1,2);plot(o/pi,m); title('HPF'); ylabel('Gain in dB-->'); xlabel('(b) Normalized frequency-->'); 39 USING RECTANGULAR WINDOW OUTPUT: enter passband ripple0.02 enter the stopband ripple0.01 enter passband freq1000 enter stopband freq1500 enter sampling freq 10000 enter your choice of window function 1. rectangular 2. triangular 3.kaiser: 1 Rectangular window filter response GRAPH: LPF Gain in dB--> 50 0 -50 -100 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 (a) Normalized frequency--> HPF 0.8 0.9 1 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 (b) Normalized frequency--> 0.8 0.9 1 Gain in dB--> 20 0 -20 -40 -60 40 USING TRIANGULAR WINDOW OUTPUT: enter passband ripple0.02 enter the stopband ripple0.01 enter passband freq1000 enter stopband freq1500 enter sampling freq 10000 enter your choice of window function 1. rectangular 2. triangular 3.kaiser: 2 Triangular window filter response GRAPH: LPF Gain in dB--> 0 -20 -40 -60 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 (a) Normalized frequency--> HPF 0.8 0.9 1 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 (b) Normalized frequency--> 0.8 0.9 1 Gain in dB--> 0 -10 -20 -30 41 USING KAISER WINDOW OUTPUT: enter passband ripple0.02 enter the stopband ripple0.01 enter passband freq1000 enter stopband freq1500 enter sampling freq 10000 enter your choice of window function 1. rectangular 2. triangular 3.kaiser: 3 kaiser window filter response GRAPH: LPF Gain in dB--> 50 0 -50 -100 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 (a) Normalized frequency--> HPF 0.8 0.9 1 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 (b) Normalized frequency--> 0.8 0.9 1 Gain in dB--> 20 0 -20 -40 -60 42 INFERENCE: This program requires certain specifications about the pass band and stop band ripple & frequencies and the sampling frequency. Here we have used a function called ‘fir1’ in order to design a Nth order Low pass and a High pass filter. This function returns the filter coefficients in length N+1 vector b. The cutoff frequency ‘wp’ must be between 0 < wp < 1.0 , with 1.0 corresponding to half the sampling rate. Based up on the choice of available windowing functions, the filter response is generated. RESULT: The LP and HP FIR Filter response for the given sequence is generated based upon the choice of the windowing function and the filter characteristics are plotted. 43 44 45 10. IMPLEMENTATION OF IIR LP FILTER FOR A GIVEN SEQUENCE AIM: To design and implement IIR (LPF) filters for a given sequence. SOFTWARE REQUIRED: MATLAB 7.0 PROGRAM DESCRIPTION: The IIR filter can realize both the poles and zeroes of a system because it has a rational transfer function, described by polynomials in z in both the numerator and the denominator: M H(z) = Σ bk z-k k=0_________ M Σ ak z-k k=0 The difference equation for such a system is described by the following: M N Y(n)= bk x(n-k) ak y(n-k) k=0 k=1 M and N are order of the two polynomials bk and ak are the filter coefficients. These filter coefficients are generated using FDS (Filter Design software or Digital Filter design package). IIR filters can be expanded as infinite impulse response filters. In designing IIR filters, cutoff frequencies of the filters should be mentioned. The order of the filter can be estimated using butter worth polynomial. That’s why the filters are named as butter worth filters. Filter coefficients can be found and the response can be plotted. MATLAB CODE: clc; clear all; close all; disp('enter the IIR filter design specifications'); 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'); disp('Frequency response of IIR LPF is:'); [b,a]=butter(n,wn,'low','s'); w=0:.01:pi; [h,om]=freqs(b,a,w); m=20*log10(abs(h)); an=angle(h); figure,subplot(2,1,1);plot(om/pi,m); 46 title('magnitude response of IIR LP filter is:'); xlabel('(a) Normalized freq. -->'); ylabel('Gain in dB-->'); subplot(2,1,2);plot(om/pi,an); title('phase response of IIR LP filter is:'); xlabel('(b) Normalized freq. -->'); ylabel('Phase in radians-->'); OUTPUT: enter the IIR filter design specifications enter the passband ripple0.15 enter the stopband ripple60 enter the passband freq1500 enter the stopband freq3000 enter the sampling freq7000 Frequency response of IIR LPF is: GRAPHS: magnitude response of IIR LP filter is: 0 -100 -200 -300 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 (a) Normalized freq. --> phase response of IIR LP filter is: 0.8 0.9 1 0 0.1 0.2 0.3 0.8 0.9 1 4 Phase in radians--> Gain in dB--> 100 2 0 -2 -4 0.4 0.5 0.6 0.7 (b) Normalized freq. --> 47 INFERENCE: This program requires certain specifications about the pass band and stop band ripple & frequencies and the sampling frequency. Here we have used a function called ‘[n,wn]=buttord(w1,w2,rp,rs,'s')’ in order to find the lowest order N of digital butterworth filter that loses no more than ‘rp’ db in the pass band and has at least ‘rs’ db of attenuation in the stop band . w1 and w2 are the pass band and stop band edge frequencies, normalized from 0 to 1. The function ‘butter’ designs a Nth order low pass digital butterworth filter and returns the filter coefficients in length N+1 vectors B(numerator) and A (denominator). RESULT: The HP IIR Filter response for the given sequence is generated and the filter characteristics are plotted. 48 49 50 11. IMPLEMENTATION OF IIR HP FILTER FOR A GIVEN SEQUENCE AIM: To design and implement IIR (HPF) filters for a given sequence. SOFTWARE REQUIRED: MATLAB 7.0 PROGRAM DESCRIPTION: The IIR filter can realize both the poles and zeroes of a system because it has a rational transfer function, described by polynomials in z in both the numerator and the denominator: M H(z) = Σ bk z-k k=0_________ M Σ ak z-k k=0 The difference equation for such a system is described by the following: M N Y(n)= bk x(n-k) ak y(n-k) k=0 k=1 M and N are order of the two polynomials bk and ak are the filter coefficients. These filter coefficients are generated using FDS (Filter Design software or Digital Filter design package). IIR filters can be expanded as infinite impulse response filters. In designing IIR filters, cutoff frequencies of the filters should be mentioned. The order of the filter can be estimated using butter worth polynomial. That’s why the filters are named as butter worth filters. Filter coefficients can be found and the response can be plotted. MATLAB CODE: clc; clear all; close all; disp('enter the IIR filter design specifications'); 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'); disp('Frequency response of IIR HPF is:'); [b,a]=butter(n,wn,'high','s'); w=0:.01:pi; [h,om]=freqs(b,a,w); m=20*log10(abs(h)); an=angle(h); figure,subplot(2,1,1);plot(om/pi,m); 51 title('magnitude response of IIR HP filter is:'); xlabel('(a) Normalized freq. -->'); ylabel('Gain in dB-->'); subplot(2,1,2);plot(om/pi,an); title('phase response of IIR HP filter is:'); xlabel('(b) Normalized freq. -->'); ylabel('Phase in radians-->'); OUTPUT: enter the IIR filter design specifications enter the passband ripple0.15 enter the stopband ripple60 enter the passband freq1500 enter the stopband freq3000 enter the sampling freq7000 Frequency response of IIR HPF is: GRAPHS: magnitude response of IIR HP filter is: 0 -200 -400 -600 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 (a) Normalized freq. --> phase response of IIR HP filter is: 0.8 0.9 1 0 0.1 0.2 0.3 0.8 0.9 1 4 Phase in radians--> Gain in dB--> 200 2 0 -2 -4 0.4 0.5 0.6 0.7 (b) Normalized freq. --> 52 INFERENCE: This program requires certain specifications about the pass band and stop band ripple & frequencies and the sampling frequency. Here we have used a function called ‘[n,wn]=buttord(w1,w2,rp,rs,'s')’ in order to find the lowest order N of digital butterworth filter that loses no more than ‘rp’ db in the pass band and has at least ‘rs’ db of attenuation in the stop band . w1 and w2 are the pass band and stop band edge frequencies, normalized from 0 to 1. The function ‘butter’ designs a Nth order high pass digital butterworth filter and returns the filter coefficients in length N+1 vectors B (numerator) and A (denominator). RESULT: The HP IIR Filter response for the given sequence is generated and the filter characteristics are plotted. 53 54 55 12. GENERATION OF DUAL TONE MULTIPLE FREQUENCY (DTMF) SIGNALS AIM: To generation of dual tone multiple frequency ( DTMF ) signals. SOFTWARE REQUIRED: MAT LAB 7.0 PROGRAM DESCRIPTION: In this program the Dual tone multiple frequency signal which is used in telephone systems is generated. A DTMF signal consists of a sum of two tones, with frequencies taken from two mutually exclusive groups of Preassigned frequencies. Each pair of such tones represents a unique number or a symbol. Decoding of a DTMF signal thus involves identifying the two tones in that signal and determining their corresponding number or symbol. PROGRAM: clc; clear all; close all; number=input('enter a phone number with no spaces:','s'); fs=8192; T=0.5; x=2*pi*[697 770 852 941]; y=2*pi*[1209 1336 1477 1602]; t=[0:1/fs:T]'; tx=[sin(x(1)*t),sin(x(2)*t),sin(x(3)*t),sin(x(4)*t)]/2; ty=[sin(y(1)*t),sin(y(2)*t),sin(y(3)*t),sin(y(4)*t)]/2; for k=1:length(number) switch number(k) case'1' tone=tx(:,1)+ty(:,1); sound(tone); plot(tone); case'2' tone=tx(:,1)+ty(:,2); sound(tone); plot(tone); case'3' tone=tx(:,1)+ty(:,3); sound(tone); plot(tone); case'A' tone=tx(:,1)+ty(:,4); 56 sound(tone); plot(tone); case'4' tone=tx(:,2)+ty(:,1); sound(tone); plot(tone); case'5' tone=tx(:,2)+ty(:,2); sound(tone); plot(tone); case'6' tone=tx(:,2)+ty(:,3); sound(tone); plot(tone); case'B' tone=tx(:,2)+ty(:,4); sound(tone); plot(tone); case'7' tone=tx(:,3)+ty(:,1); sound(tone); plot(tone); case'8' tone=tx(:,3)+ty(:,2); sound(tone); plot(tone); case'9' tone=tx(:,3)+ty(:,3); sound(tone); plot(tone); case'C' tone=tx(:,3)+ty(:,4); sound(tone); plot(tone); case'#' tone=tx(:,4)+ty(:,1); sound(tone); plot(tone); case'0' tone=tx(:,4)+ty(:,2); sound(tone); plot(tone); case'*' tone=tx(:,4)+ty(:,3); sound(tone); 57 plot(tone); case'D' tone=tx(:,4)+ty(:,4); sound(tone); plot(tone); otherwise disp('invalid number'); end; pause(0.75); end; OUTPUT: enter a phone number with no spaces: 936 GRAPHS: 1 0.8 0.6 0.4 0.2 0 -0.2 -0.4 -0.6 -0.8 -1 0 500 1000 500 1000 1500 2000 2500 3000 3500 4000 4500 1 0.8 0.6 0.4 0.2 0 -0.2 -0.4 -0.6 -0.8 -1 0 1500 2000 2500 3000 3500 4000 4500 58 1 0.8 0.6 0.4 0.2 0 -0.2 -0.4 -0.6 -0.8 -1 0 500 1000 1500 2000 2500 3000 3500 4000 4500 INFERENCE: In this program the two frequencies which are going to produce the dual tone when we press any button, that is why it is called Dual Tone Multiple Frequency (DTMF). The only constraint is if the number we pressed is not there in the list then it will generate the output as invalid number. But here the frequencies are fixed. If we want to generate different tone we have to change the frequencies every time. RESULT: Hence Dual Tone Multiple Frequency (DTMF) signals are generated and the output is verified. 59 60 61 13. PROGRAM TO VERIFY DECIMATION AIM: To verify Decimation and Interpolation of a given Sequences SOFTWARE REQUIRED: MAT LAB 7.0 PROGRAM DESCRIPTION: The sampling rate alteration that is employed to generate a new sequence with a sampling rate lower than that of a given sequence. Thus, if x[n] is a sequence with a sampling rate of FT Hz and it is used to generate another sequence y[n] with a desired sampling rate of FT' Hz, then the sampling rate alteration ratio is given by FT' / FT = R. If R < 1, the sampling rate is decreased by a process called decimation and it results in a sequence with a lower sampling rate. The decimation can be carried out by using the pre-defined commands decimate. MATLAB CODE: % DECIMATION clc; clear all; close all; disp('Let us take a sinusoidal sequence which has to be decimated: '); fm=input('Enter the signal frequency fm: '); fs=input('Enetr the sampling frequnecy fs: '); T=input('Enter the duration of the signal in seconds T: '); dt=1/fs; t=dt:dt:T M=length(t); m=cos(2*pi*fm*t); r=input('Enter the factor by which the sampling frequency has to be reduced r: '); md=decimate(m,r); figure(1); subplot(3,1,1); plot(t,m); grid; xlabel('t-->'); ylabel('Amplitude-->'); title('Sinusoidal signal before sampling'); subplot(3,1,2); stem(m); grid; xlabel('n-->'); ylabel('Amplitudes of m -->'); title('Sinusoidal signal after sampling before decimation'); subplot(3,1,3); stem(md); grid; title('Sinusoidal after decimation'); 62 xlabel('n/r-->'); ylabel('Amplitude of md-->'); OUTPUT: Let us take a sinusoidal sequence which has to be decimated: Enter the signal frequency fm: 2 Enetr the sampling frequnecy fs: 100 Enter the duration of the signal in seconds T: 1 Enter the factor by which the sampling frequency has to be reduced r: 2 GRAPHS: Amplitude of md--> Amplitudes of m --> Amplitude--> Sinusoidal signal before sampling 1 0 -1 0 0.1 0.2 0.3 0.4 0 0 0.5 0.6 0.7 0.8 t--> Sinusoidal signal after sampling before decimation 10 20 30 40 5 10 15 0.9 1 80 90 100 40 45 50 1 0 -1 50 60 70 n--> Sinusoidal after decimation 1 0 -1 20 25 n/r--> 30 35 INFERENCE : The only constraint about the program is that the factors of decimation or interpolation should be an integers. If we want to change the sampling frequency by a factor which is not an integer it can be done by using the command resample by which we can change the sampling rate by a factor I / D. For this we have to interpolate by an integer factor I and then decimate by an integer factor D RESULT : The Decimation of given sequences is verified and graphs are plotted. 63 64 65 14. PROGRAM TO VERIFY INTERPOLATION AIM: To verify Interpolation of a given Sequence. SOFTWARE REQUIRED: MAT LAB 7.0 PROGRAM DESCRIPTION: The sampling rate alteration that is employed to generate a new sequence with a sampling rate higher than that of a given sequence. Thus, if x[n] is a sequence with a sampling rate of FT Hz and it is used to generate another sequence y[n] with a desired sampling rate of FT' Hz, then the sampling rate alteration ratio is given by FT' / FT = R. If R > 1, the process is called interpolation and results in a sequence with a higher sampling rate. The interpolation can be carried out by using the pre-defined command interp respectively. MATLAB CODE: %INTERPOLATION clc; clear all; close all; disp('Let us take a sinusoidal sequence which has to be interpolated: '); fm=input('Enter the signal frequency fm: '); fs=input('Enetr the sampling frequnecy fs: '); T=input('Enter the duration of the signal in seconds T: '); dt=1/fs; t=dt:dt:T M=length(t); m=cos(2*pi*fm*t); r=input('Enter the factor by which the sampling frequency has to be increased r: '); md=interp(m,r); figure(1); subplot(3,1,1); plot(t,m); grid; xlabel('t-->'); ylabel('Amplitude-->'); title('Sinusoidal signal before sampling'); subplot(3,1,2); stem(m); grid; xlabel('n-->'); ylabel('Amplitudes of m -->'); title('Sinusoidal signal after sampling before interpolation'); subplot(3,1,3); stem(md); 66 grid; title('Sinusoidal after interpolation'); xlabel('n x r-->'); ylabel('Amplitude of md-->'); OUTPUT: Let us take a sinusoidal sequence which has to be interpolated: Enter the signal frequency fm: 2 Enetr the sampling frequnecy fs: 100 Enter the duration of the signal in seconds T: 1 Enter the factor by which the sampling frequency has to be increased r: 2 GRAPHS: Amplitude of md--> Amplitudes of m --> Amplitude--> Sinusoidal signal before sampling 1 0 -1 0 0.1 0.2 0.3 0.4 0 0 0.5 0.6 0.7 0.8 t--> Sinusoidal signal after sampling before interpolation 10 20 30 40 20 40 60 80 0.9 1 80 90 100 160 180 200 1 0 -1 50 60 70 n--> Sinusoidal after interpolation 2 0 -2 100 120 n x r--> 140 INFERENCE : The only constraint about the program is that the factors of decimation or interpolation should be an integers. If we want to change the sampling frequency by a factor which is not an integer it can be done by using the command resample by which we can change the sampling rate by a factor I / D. For this we have to interpolate by an integer factor I and then decimate by an integer factor D RESULT : The Interpolation of given sequences is verified and graphs are plotted. 67 68 69 70