DSP CYCLE I & II

88
GENERATION OF SIGNALS AIM: To write a program to generate unit impulse, unit step, ramp, exponential signals, sine and cosine sequences. ALGORITHM: Step 1: Start the program Step 2: Input length of the sequence Step 3: Generate the time axis Step 4: Assign the sample values. Step 5: Plot the Waveform Step 6: Stop. PROGRAM: % Program for Unit impulse signal clc; clear all; close all; t=-2:1:2; y=[zeros(1,2),ones(1,1),zeros(1,2)]; subplot(2,2,1); stem(t,y); xlabel(‘Time’); ylabel('Amplitude'); title(‘UNIT IMPULSE SIGNAL'); % Program for Unit step signal clc; clear all; close all; n=input(‘Enter the N value’); t=0:n-1; y=ones(1,n); subplot(2,2,2); stem(t,y); xlabel(‘Time’); ylabel(‘Amplitude’); title(‘UNIT STEP SIGNAL'); Ex No: 1 Date :

description

lab manual

Transcript of DSP CYCLE I & II

  • GENERATION OF SIGNALS

    AIM: To write a program to generate unit impulse, unit step, ramp, exponential signals, sine and cosine sequences. ALGORITHM: Step 1: Start the program Step 2: Input length of the sequence Step 3: Generate the time axis Step 4: Assign the sample values. Step 5: Plot the Waveform Step 6: Stop.

    PROGRAM:

    % Program for Unit impulse signal clc; clear all; close all; t=-2:1:2; y=[zeros(1,2),ones(1,1),zeros(1,2)]; subplot(2,2,1); stem(t,y); xlabel(Time); ylabel('Amplitude'); title(UNIT IMPULSE SIGNAL');

    % Program for Unit step signal clc; clear all; close all; n=input(Enter the N value); t=0:n-1; y=ones(1,n); subplot(2,2,2); stem(t,y); xlabel(Time); ylabel(Amplitude); title(UNIT STEP SIGNAL');

    Ex No: 1 Date :

  • FLOWCHART

    INPUTS: For Unit Step Sequence: Enter the N value = 7

    For Exponential Sequence:

    Enter the length of exponential sequence = 5 Enter the a value = 1

    For Ramp Sequence:

    Enter the length of Ramp = 7

    START

    INPUT LENGTH OF THE SEQUENCE

    GENERATE THE TIME AXIS

    ASSIGN THE SAMPLE VALUES

    PLOT THE WAVEFORM

    STOP

  • % Ramp signal clc; clear all; close all; n1=input('enter the length of ramp sequence'); t=0:n1; subplot(2,2,3); stem(t,t); xlabel('Time'); ylabel('Amplitude'); title('RAMP SIGNAL');

    % Exponential signal clc; clear all; close all; n=input('Enter the length of exponential sequence'); t=0:n; a=input('Enter the a value'); y=exp(a*t); subplot(2,2,4); stem(t,y); ylabel('Amplitude'); xlabel('Time'); title('EXPONENTIAL SIGNALS');

    % Sine sequence clc; clear all; close all; t=0:0.01:pi; y=sin(2*pi*t) plot(t,y); xlabel('Time'); ylabel('Amplitude'); title('SINE SEQUENCE');

    % Cosine sequence clc; clear all; close all; t=0:0.01:pi; y=cos(2*pi*t) plot(t,y); xlabel('Time'); ylabel('Amplitude'); title('COSINE SEQUENCE');

  • OUTPUTS:

  • MATLAB FUNCTIONS:

    Zeros(m,n) zeros array It creates an M-by-N matrix of zeros

    Ones(m,n) ones array It creates an M-by-N matrix of ones

    Plot(x,y) linear plot It plots vector y versus vector x

    Stem(x,y) Discrete sequence orstemplot It plots the data sequence y at the values specified in x RESULT: Thus the representation of signals unit impulse, unit step, ramp, exponential, sine & cosine sequence was generated using MATLAB.

  • CONVOLUTION AIM: To write a MATLAB program for convolution of two sequences.

    LINEAR CONVOLUTION ALGORITHM:

    Step 1: Get the signals x(n) and h(n) in matrix form. Step 2: The co0volved signal is denoted by y(n) Step 3: The transformed signals is given by

    Y(n)= x(k) h(n-k) where k=0 to N-1

    k=- PROGRAM:

    % Program for Linear convolution clc; clear all; close all; x=input('Enter the first sequence'); h=input('Enter the second sequence'); y=conv(x,h); subplot(3,3,1); stem(x); xlabel('time'); ylabel('amplitude'); title('First Sequence'); subplot(3,3,2); stem(h); xlabel('time'); ylabel('amplitude'); title('Second Sequence'); subplot(3,3,3); stem(y); xlabel('time'); ylabel('amplitude'); title('LINEAR CONVOLUTION');

    Ex No: 2 Date :

  • FLOWCHART:

    INPUTS:

    Linear convolution

    Enter the first sequence = [ 1 2 4 ] Enter the second sequence = [ 1 2 ]

    Circular convolution

    Enter the first sequence = [ 1 2 4 0 ] Enter the second sequence = [ 1 2 0 0 ]

    START

    INPUT THE REQUIRED SEQUENCE

    FIND THE LENGTH OF SEQUENCE

    GENERATE THE TIME AXIS

    PLOT THE WAVEFORM

    STOP

    PERFORM CONVOLUTION USING MATLAB

    FUNCTIONS

  • Circular convolution ALGORITHM: step 1: Start the program step 2: The convolved signals is y(n) step 3: The y(n) is given by formula y(n)=y(n)+g(i)*h(j); PROGRAM:

    % program for circular convolution clc; clear all; close all;

    % get the input sequence

    g=input('Enter the first sequence'); h=input('Enter the second sequence');

    % calculate the circularly convolved sequence

    N1=length(g); N2=length(h);

    % generate the circularly convolved sequence

    N=max(N1,N2); N3=N1-N2; if(N3>=0) h=[h,zeros(1,N3)]; else g=[g,zeros(1,-N3)]; end for n=1:N y(n)=0; for i=1:N j=n-i+1; if(j

  • OUTPUTS:

    Linear convolution

    Circular convolution

  • % plot the signals subplot(2,3,1); stem(g); xlabel('Time'); ylabel('Amplitude'); title('First Sequence'); subplot(2,3,2); stem(h); xlabel('Time'); ylabel('Amplitude'); title('Second Sequence'); subplot(2,3,3); stem(y); xlabel('Time'); ylabel('Amplitude'); title('CIRCULAR CONVOLUTION'); MATLAB FUNCTIONS:

    1) subplot(m,n,p) --- creates axes in tiled positions It breaks the figure window into an m by n matrix of small axes, select the p-th axes for the current plot. The axes are counted along the top row of the figure window, then second row, etc., RESULT: Thus the convolution of two sequences was convolved using Linear and Circular convolution methods.

  • FLOWCHART:

    INPUT:

    FFT

    Enter the sequence = [ 1 0 1 0 1 0 1 0 ] Enter the length of sequence = 8

    IFFT

    Enter the sequence = [ 4 0 0 0 4 0 0 0 ] Enter the length of sequence = 8

    START

    INPUT THE REQUIRED SEQUENCE

    FIND THE LENGTH OF SEQUENCE

    GENERATE THE TIME AXIS

    PLOT THE WAVEFORM

    STOP

    PERFORM FFT USING MATLAB FUNCTIONS

  • CALCULATION OF FFT SIGNALS

    AIM: To write a MATLAB program for the calculation of FFT signals ALGORITHM:

    Step 1: Get the signals x(n) of the length N in matrix form Step 2: Get the N values. Step 3: The transformed signals is denoted as N-1

    X(K)= x(n) e-j2pikn/N where k=0 to N-1 n=0

    PROGRAM:

    % Program for calculation of FFT clc; clear all; close all; x=input('Enter the sequence'); n=input('Enter the length of sequence'); y=length(x); s=fft(x); stem(s); xlabel('Time'); ylabel('Amplitude'); title('FFT');

    % Program for calculation of IFFT clc; clear all; close all; x=input('Enter the sequence'); n=input('Enter the length of sequence'); y=length(x); s=ifft(x); stem(s); xlabel('Time'); ylabel('Amplitude'); title('IFFT');

    Ex No: 3 Date :

  • OUTPUT:

    FFT

    IFFT

  • MATLAB FUNCTIONS:

    1) subplot(m,n,p) It breaks the figure window into an m-by-n matrix of small axes,selects the pth axes of rthe current plkot the axes are counted along the top row figure window ,then the second row,etc.,

    2) disp(x) displays the array,without print\ing the name

    If X is a string,the text is displayed RESULT: Thus the calculation of FFT signals using MATLAB program was generated.

  • FIR FILTER DESIGN USING WINDOWS

    AIM:

    To write the MATLAB program for designing FIR filters using windows ALGORITHM:

    Step 1: Enter the order of the filter Step 2: Enter the cutoff frequency Step 3: Enter the beta value for Kaiser Window Step 4: Generate window for length N+1 Step 5: Generate filter co-efficients Step 6: Plot the magnitude response PROGRAM:

    % Program for Rectangular window clc; clear all; close all; rs=input('Enter the Stopband ripple'); rp=input('Enter the Passband ripple'); fp=input('Enter the Passband frequency'); fs=input('Enter the Stopband frequency'); f=input('Enter the Sampling frequency'); wp=2*fp/f; ws=2*fs/f; num=abs(-20*log10(sqrt(rp*rs))-13); den=14.6*(fs-fp)/f; n=ceil(num/den); n1=n+1; if(rem(n,2) ~=0) n1=n; n=n-1; end y=boxcar(n1);

    % Low pass filter b=fir1(n,wp,y); [h,o]=freqz(b,1,256); m=(20*log10(abs(h))); subplot(2,2,1); plot(o/pi,m); xlabel('Normalized freq'); ylabel('Gain in db'); title('LPF');

    Ex No: 4 Date :

  • FLOWCHART

    INPUTS: Enter the Stopband ripple = 0.04 Enter the Passband ripple = 0.05 Enter the Passband frequency = 1500 Enter the Stopband frequency = 2000 Enter the Sampling frequency = 9000 Enter the Beta value = 5.8

    START

    INPUT ORDER OF THE FILTER

    GENERATE THE LENGTH N+1

    GENERATE FILTER CO-EFFICIENT

    PLOT THE RESPONSE

    STOP

    INPUT THE CUTOFF FREQUENCY

    INPUT THE BETA VALUE FOR KAISER

    WINDOW

  • % High pass filter b=fir1(n,wp,'high',y); [h,o]=freqz(b,1,256); m=(20*log10(abs(h))); subplot(2,2,2); plot(o/pi,m); xlabel('Normalized freq'); ylabel('Gain in db'); title('HPF');

    % 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); xlabel('Normalized freq'); ylabel('Gain in db'); title('BPF');

    % Band stop filter wn=[wp,ws] 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); xlabel('Normalized freq'); ylabel('Gain in db'); title('BSF');

  • OUTPUTS:

    RECTANGULAR WINDOW

    HAMMING WINDOW

  • % Program for Hamming window clc; clear all; close all; rs=input('Enter the stopband ripple'); rp=input('Enter the passband ripple'); fp=input('Enter the passband frequency'); fs=input('Enter the stopband frequency'); f=input('Enter the sampling frequency'); wp=2*fp/f; ws=2*fs/f; num=abs(-20*log10(sqrt(rp*rs))-13); den=14.6*(fs-fp)/f; n=ceil(num/den); n1=n+1; if(rem(n,2)~=0) n1=n; n=n-1; end y=hamming(n1);

    % Low pass filter

    b=fir1(n,wp,y); [h,o]=freqz(b,1,256); m=(20*log10(abs(h))); subplot(2,2,1); plot(o/pi,m); xlabel('Normalized freq'); ylabel('Gain in db'); title('LPF');

    % High pass filter b=fir1(n,wp,'high',y); [h,o]=freqz(b,1,256); m=(20*log10(abs(h))); subplot(2,2,2); plot(o/pi,m); xlabel('Normalized freq'); ylabel('Gain in db'); title('HPF');

  • HANNING WINDOW

    KAISER WINDOW

  • % 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); xlabel('Normalized freq'); ylabel('Gain in db'); title('BPF');

    % Band stop filter

    wn=[wp,ws] 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); xlabel('Normalized freq'); ylabel('Gain in db'); title('BSF');

    % Program for Hanning window

    clc; clear all; close all; rs=input('Enter the Stopband ripple'); rp=input('Enter the Passband ripple'); fp=input('Enter the Passband frequency'); fs=input('Enter the Stopband frequency'); f=input('Enter the Sampling frequency'); wp=2*fp/f; ws=2*fs/f; num=abs(-20*log10(sqrt(rp*rs))-13); den=14.6*(fs-fp)/f; n=ceil(num/den); n1=n+1; if(rem(n,2)~=0) n1=n; n=n-1; end y=hanning(n1);

  • % Low pass filter b=fir1(n,wp,y); [h,o]=freqz(b,1,256); m=(20*log10(abs(h))); subplot(2,2,1); plot(o/pi,m); xlabel('Normalized freq'); ylabel('Gain in db'); title('LPF');

    % High pass filter

    b=fir1(n,wp,'high',y); [h,o]=freqz(b,1,256); m=(20*log10(abs(h))); subplot(2,2,2); plot(o/pi,m); xlabel('Normalized freq'); ylabel('Gain in db'); title('HPF');

    % 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); xlabel('Normalized freq'); ylabel('Gain in db'); title('BPF');

    % Band stop filter wn=[wp,ws] 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); xlabel('Normalized freq'); ylabel('Gain in db'); title('BSF');

  • % Program for Kaiser window clc; clear all; close all; rs=input('Enter the Stopband ripple'); rp=input('Enter the Passband ripple'); fp=input('Enter the Passband frequency'); fs=input('Enter the Stopband frequency'); f=input('Enter the Sampling frequency'); beta=input('Enter the Beta value'); wp=2*fp/f; ws=2*fs/f; num=abs(-20*log10(sqrt(rp*rs))-13); den=14.6*(fs-fp)/f; n=ceil(num/den); n1=n+1; if(rem(n,2)~=0) n1=n; n=n-1; end y=kaiser(n1, beta);

    % Low pass filter b=fir1(n,wp,y); [h,o]=freqz(b,1,256); m=(20*log10(abs(h))); subplot(2,2,1); plot(o/pi,m); xlabel('Normalized freq'); ylabel('Gain in db'); title('LPF');

    % High pass filter b=fir1(n,wp,'high',y); [h,o]=freqz(b,1,256); m=(20*log10(abs(h))); subplot(2,2,2); plot(o/pi,m); xlabel('Normalized freq'); ylabel('Gain in db'); title('HPF');

  • % 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); xlabel('Normalized freq'); ylabel('Gain in db'); title('BPF');

    % Band stop filter wn=[wp,ws] 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); xlabel('Normalized freq'); ylabel('Gain in db'); title('BSF');

  • MATLAB FUNCTIONS: 1)boxcar- returns the N-point rectangular window hamming(N) returns the N-point hamming window hanning(N) returns the N-point hanning window in a column vector Kaiser(N,beta) returns the beta-valued N-point Kaiser window 2)b=fir1(n,wn) designs an Nth order lowpass FIR filter and returns the filter co-efficients in length N+1 vector b the cutoff frequency wn must be between 0
  • FLOWCHART

    START

    ENTER THE RIPPLE, EDGE, SAMPLING

    FREQUENCIES

    STOP

    CALCULATE THE ORDER OF THE COEFFICIENT

    PLOT THE RESPONSE OF LOWPASS, HIGHPASS,

    BANDPASS & BANDSTOP FILTER

  • IIR FILTER DESIGN

    AIM: To write a MATLAB program for IIR filter design using

    1) Butterworth filter a) Bilinear transformation b) Impulse invariant 2) Chebyshev type-I

    ALGORITHM: Step 1 : Get the passband and stopband ripple Step 2 : Get the sampling freq Step 3 : Calculate the order of filter Step 4 : Find the window co-efficient Step 5 : To draw the magnitude response. PROGRAM:

    BUTTERWORTH FILTER clc; clear all; close all; rp=input('Enter the Passband ripple'); rs=input('Enter the Stopband ripple'); wp=input('Enter the Passband edge frequency'); ws=input('Enter the Stopband edge frequency'); fs=input('Enter the Sampling frequency'); w1=2*wp/fs; w2=2*ws/fs;

    % filter order

    [N,wn]=buttord(w1,w2,rp,rs);

    % Low pass filter

    [B,A]=butter(N,wn); [h,w]=freqz(B,A,100); T=0.001; hertz=w/(2*pi*T); subplot(2,2,1); plot(hertz,abs(h)); xlabel('Hertz'); ylabel('ABS(h)');

    Ex No: 5 Date :

  • INPUTS

    BUTTERWORTH /CHEBYSHEV

    Enter the Passband ripple = 5 Enter the Stopband ripple = 10 Enter the Passband edge frequency = 1200 Enter the Stopband edge frequency = 2000 Enter the Sampling frequency = 7800

    BILINEAR

    Enter the Passband ripple = 3 Enter the Stopband ripple = 15 Enter the Passband edge frequency = 1256.63 Enter the Stopband edge frequency = 2513.17 Enter the Sampling frequency = 2000

    IMPULSE INVARIANT

    Enter the Passband ripple = 5 Enter the Stopband ripple = 10 Enter the Passband edge frequency = 1200 Enter the Stopband edge frequency = 2000 Enter the Sampling frequency = 7800

  • title('LPF'); % High pass filter

    [B,A]=butter(N,wn,'high'); [h,w]=freqz(B,A,100); T=0.001; hertz=w/(2*pi*T); subplot(2,2,2); plot(hertz,abs(h)); xlabel('Hertz'); ylabel('ABS(h)'); title('HPF');

    % Band pass filter

    [B,A]=butter(N,[w1,w2]); [h,w]=freqz(B,A,100); T=0.001; hertz=w/(2*pi*T); subplot(2,2,3); plot(hertz,abs(h)); xlabel('Hertz'); ylabel('ABS(h)'); title('BPF');

    % Band stop filter

    [B,A]=butter(N,[w1,w2],'stop'); [h,w]=freqz(B,A,100); T=0.001; hertz=w/(2*pi*T); subplot(2,2,4); plot(hertz,abs(h)); xlabel('Hertz'); ylabel('ABS(h)'); title('BSF');

  • OUTPUTS BUTTERWORTH

    BILINEAR

    IMPULSE INVARIANT

  • BILINEAR TRANSFORMATION clc; clear all; close all; rp=input('Enter the Passband ripple'); rs=input('Enter the Stopband ripple'); wp=input('Enter the Passband edge frequency'); ws=input('Enter the Stopband edge frequency'); fs=input('Enter the Sampling frequency');

    % Filter order [N,wn]=buttord(wp,ws,rp,rs,'s'); disp(N); [num,den]=butter(N,wn,'s'); [b,a]=bilinear(num,den,fs); freqz(b,a,512,fs); xlabel('Frequency in Hertz'); ylabel('Gain in dB'); title('Bilinear');

    IMPULSE INVARIANT clc; clear all; close all; rp=input('Enter the Passband ripple'); rs=input('Enter the Stopband ripple'); wp=input('Enter the Passband edge frequency'); ws=input('Enter the Stopband edge frequency'); fs=input('Enter the Sampling frequency');

    % Filter order

    [N,wn]=buttord(wp,ws,rp,rs,'s'); [b,a]=butter(N,wn,'s'); [bz,az]=impinvar(b,a,fs); freqz(bz,az,512,fs); xlabel('Frequency in Hertz'); ylabel('Gain in dB'); title('Impulse Invariant');

  • CHEBYSHEV

  • PROGRAM:

    CHEBYSHEV FILTER clc; clear all; close all; rp=input('Enter the Passband ripple'); rs=input('Enter the Stopband ripple'); wp=input('Enter the Passband edge frequency'); ws=input('Enter the Stopband edge frequency'); fs=input('Enter the Sampling frequency'); w1=2*wp/fs; w2=2*ws/fs;

    % filter order

    [N,wn]=buttord(w1,w2,rp,rs);

    % Low pass filter [B,A]=butter(N,wn); [h,w]=freqz(B,A,100); T=0.001; hertz=w/(2*pi*T); subplot(2,2,1); plot(hertz,abs(h)); xlabel('Hertz'); ylabel('ABS(h)'); title('LPF');

    % High pass filter

    [B,A]=butter(N,wn,'high'); [h,w]=freqz(B,A,100); T=0.001; hertz=w/(2*pi*T); subplot(2,2,2); plot(hertz,abs(h)); xlabel('Hertz'); ylabel('ABS(h)'); title('HPF');

    % Band pass filter

    [B,A]=butter(N,[w1,w2]); [h,w]=freqz(B,A,100); T=0.001; hertz=w/(2*pi*T);

  • subplot(2,2,3); plot(hertz,abs(h)); xlabel('Hertz'); ylabel('ABS(h)'); title('BPF');

    % Band stop filter

    [B,A]=butter(N,[w1,w2],'stop'); [h,w]=freqz(B,A,100); T=0.001; hertz=w/(2*pi*T); subplot(2,2,4); plot(hertz,abs(h)); xlabel('Hertz'); ylabel('ABS(h)'); title('BSF');

  • MATLAB FUNCTIONS: 1)BUTTER Butterworth digital & analog filter design [b,a]=butter(N,wn) designs an Nth order lowpass digital butterworth filter and returns the filter co=efficient in length N+1 vectors B and A the cutt-off frequency wn must be 0.0
  • INPUT

    Enter the sampling frequency: 1200

    OUTPUT

  • POLYPHASE DECOMPOSITION AIM:

    To write a program to compute Convolution and m-fold decimation by Polyphase decomposition.

    ALGORITHM:

    Step 1: Get the input sequence. Step 2: Get the filter coefficients and also the decimation factor. Find the response by using convolution. Step 3: Plot the graph.

    PROGRAM: %Analog signal t=-0.005:0.00005:0.005; xa=exp(-1000*abs(t)); %Discrete time signal Fs=input('Enter the sampling frequency(Fs)= '); Ts=1/Fs; n=-25:1:25; xn=exp(-1000*abs(n*Ts)); %Discrete time Fourier transform N=500; k=0:1: N; w=(2*pi*k/N); X=xn*exp(-j*n'*w); X=abs(X); %omega range from -Wmax to Wmax W=[-fliplr(w),w(2:N+1)]; %X over -Wmax to Wmax interval X=[fliplr(X),X(2:N+1)]; subplot(2,1,1); plot(t*1000,xa,'k'); grid; hold on; stem(n*Ts*1000,xn,'k'); xlabel('time in sec');ylabel('x(n)'); title('discrete time signal'); gtext('Ts=1msec'); hold off;

    RESULT:

    Thus the MATLAB program for POLYPHASE DECOMPOSITION was designed and executed.

    Ex No: 6 Date :

  • INPUT: Enter the frequency f1=2.5 Enter the frequency f2=0.32 Enter the cut-off frequency =2.51 OUTPUTS: SAMPLING OF ANALOG SIGNAL

  • SAMPLING THEOREM

    AIM:

    To verify the sampling theorem using MATLAB.

    ALGORITHM:

    Step 1: Get the input frequency f1 and f2. Assign the value for n. Step 2: Get the cutoff frequency f c. Calculate the value of x. Step 3: Calculate the value of x a and x amp.

    Step 4: Plot the graph for input sequence X (n),X a(n), and X amp(n). PROGRAM:

    f1=input('Enter the frequency:'); f2=input('Enter the frequency:'); n=0:255; fc=input('Enter the cut-off frequency'); x=cos(2*pi*f1*n)+cos(2*pi*f2*n); xa=cos(2*pi*fc*n); xamp=x.*xa; subplot(2,2,1); plot(n,x); title('x(n)'); xlabel('n'); ylabel('amp'); subplot(2,2,2); plot(n,xa); title('xa(n)'); xlabel('n'); ylabel('amp'); subplot(2,2,3); plot(n,xamp); title('xamp(n)'); xlabel('n'); ylabel('amp'); RESULT: Thus sampling theorem was verified by using MATLAB.

    Ex No: 7 Date :

  • SAMPLING THEOREM

    AIM:

    To verify the sampling theorem using MATLAB.

    ALGORITHM:

    Step 1: Sampling frequency and time period is mentioned. Step 2: Message signal is given as addition of two signals.. Step 3: Calculate FFT of x .

    Step 4: Plot the graph for output sequence.

    PROGRAM: Nyquist Rate Sampling

    clc; clear all; close all; fs =1400; t=0:1/fs: 13/fs; x=cos(2*pi*400*t)+cos(2*pi*100*t); xm=abs (fft(x)); disp (xm); k=0: length (xm)-1; figure (1); stem (100*k, xm); xlabel (HZ); ylabel (Magnitude); title (NR Sampling);

    Under Sampling clc; clear all; close all; fs =1000; t=0:1/fs: 10/fs; x=cos(2*pi*400*t)+cos(2*pi*100*t); xm=abs (fft(x)); disp (xm); k=0: length (xm)-1; figure (1); stem (100*k, xm); xlabel (HZ); ylabel (Magnitude); title (NR Sampling);

    Ex No: 7a Date :

  • OUTPUTS: NYQUIST SAMPLING

    UNDER SAMPLING

    OVER SAMPLING

  • Over Sampling clc; clear all; close all; fs =2000; t=0:1/fs: 20/fs; x=cos(2*pi*400*t)+cos(2*pi*100*t); xm=abs (fft(x)); disp (xm); k=0: length (xm)-1; figure (1); stem (100*k, xm); xlabel (HZ); ylabel (Magnitude); title (NR Sampling);

    RESULT: Thus nyquist ,under & over sampling was verified by using MATLAB.

  • INPUT: Enter the input sequence=[0 1 2 3 4 5 6 7 8] OUTPUT:

  • Ex No: 8 Date:

    DISCRETE FOURIER TRANSFORM

    AIM:

    To find the DFT of the given sequence using MATLAB.

    ALGORITHM:

    Step 1: Get the sequence and length of sequence.

    Step 2: Perform DFT function. Step 3: Find absolute value and Phase of DFT sequence X(K). Step 4: Plot the input sequence and magnitude and phase of DFT

    PROGRAM: x=input('Enter the input sequence'); N=length(x); for k=1:N sum=0; for n=1:N sum=sum+(x(n)*exp(-j*2*pi*(n-1)*(k-1)/N)); end y(k)=sum; end subplot(2, 2, 1); stem(x); xlabel('n'); ylabel('x(n)'); title('input sequence'); subplot(2, 2, 2); stem(real(y)); xlabel('n'); ylabel('y(n)'); title('real(y)'); subplot(2, 2, 3); stem(imag(y)); xlabel('n'); ylabel('y(n)'); title('imag(y)'); disp(x); disp(real(y)); disp(imag(y)); RESULT: Thus the DFT of the given sequence was generated using MATLAB.

  • INPUT: Enter the input sequence=[0 1 2 3 4] OUTPUT:

  • INVERSE DISCRETE FOURIER TRANSFORM AIM:

    To find the IDFT of the given sequence using MATLAB.

    ALGORITHM: Step 1: Get the sequence. Step 2: Get the length of the sequence. Step 3: Initialise the scale for k and n. Step 4: Use the appropriate function to generate the required transform. add title to the transform.

    PROGRAM x=input ('Enter the input sequence'); N=length(x); for n=1:N Sum=0; for k=1:N sum=sum+(x(k)*exp(j*2*pi*(n-1)*(k-1)/N)); end y(n)=sum/N; end subplot(2,2,1); stem(x); xlabel('n'); ylabel('x(n)'); title('inputsequence'); subplot(2,2,2); stem(real(y)); xlabel('n'); ylabel('y(n)'); title('real(y)'); subplot(2, 2, 3); stem(imag(y)); xlabel('n'); ylabel('y(n)'); title('imag(y)'); disp(x); disp(real(y)); disp(imag(y)); RESULT: Thus the IDFT of the given sequence was generated using MATLAB.

    Ex No: 8a Date :

  • IMAGE PROCESSING USING INPUT TOOL BOX

    AIM: To write MATLAB programs for image processing using input tool box. ALGORITHM: STEP 1: Input the image STEP 2: Process the image STEP 3: Display the processed image PROGRAM:

    % Reading an image clc; clear all; close all; x=imread('cameraman.tif'); imshow(x);

    % Reading an Indexed image clc; clear all; close all; [x,map]=imread('flowers.tif'); imshow(x,map);

    % Resizing an image

    clc; clear all; close all; x=imread('rice.tif'); y=imresize(x,0.5,'bilinear'); imshow(x) figure,imshow(y)

    % Rotating an image clc; clear all; close all; x=imread('rice.tif'); y=imrotate(x,20,'bilinear'); imshow(x); figure,imshow(y)

    Ex No: 9 Date :

  • OUTPUTS:

    Reading an image

    Reading an Indexed image

    Resized Image

  • % Filtering the noise affected image clc; clear all; close all; x=imread('rice.tif'); y=imnoise(x,'salt and pepper',0.02); z=medfiltz(x); imshow(x),title('original image') figure,imshow(y),title('image corrupted by noise'); figure,imshow(z),title('filtered image');

    % Filtering the noise affected image

    clc; clear all; close all; x=imread('rice.tif'); y=imnoise(x,'gaussian',0,0.01); z=ordflt2(x,5,ones(3,3)); imshow(x),title('original image') figure,imshow(y),title('image corrupted by noise'); figure,imshow(z),title('filtered image');

    % Adjusting the intensity of an image

    clc; clear all; close all; i=imread('eight.tif'); j=imadjust(i,[0 1],[1 0]); imshow(i),figure,imshow(j)

    RESULT: Thus the MATLAB program image processing using image processing tool box was executed.

  • Rotating Image

    Filtering the Noise affected Image

  • Filtering the Noise affected Image

    Adjusting the Intensity of the Image

  • STUDY OF VARIOUS ADRESSING MODES AIM: To study about addressing modes in TMS320C5X debugger.

    APPARATUS REQUIRED:

    1. System with TMS 320C50 debugger software 2. TMS 320C50 Kit. 3. RS232 cable.

    ADDITION PROGRAM:

    INP1 .SET 0H INP2 .SET 1H OUT .SET 2H .mmregs .text START: LD #140H, DP RSBX CPL NOP NOP NOP NOP LD INP1, A ADD INP2, A STL A, OUT

    HLT: B HLT

    SUBTRACTION PROGRAM:

    INP1 .SET 0H INP2 .SET 1H OUT .SET 2H .mmregs .text START: LD #140H, DP RSBX CPL NOP NOP NOP

    Ex No: 10 Date :

  • ADDITION

    INPUT:

    Data Memory: A000h 0004h A001h 0004h

    OUTPUT:

    Data Memory: A002h 0008h

    SUBTRACTION INPUT:

    Data Memory: A000h 0004h A001h 0002h

    OUTPUT:

    Data Memory: A002h 0002h

    MULTIPLICATION

    OUTPUT:

    A002H 2H DIVISION

    INPUT: DATA MEMORY A000H 000AH A001H 0002H

    OUTPUT: A002H 0005H

  • NOP LD INP1, A SUB INP2, A STL A, OUT HLT: B HLT

    MULTIPLICATION PROGRAM: .mmregs .text START: STM #0140H, ST0 STM #40H, PMST STM #0A000H, AR0 ST #1H,*AR0 LD *AR0+, T ST #2H,*AR0 MPY *AR0+, A STL A,*AR0 HLT: B HLT

    DIVISION

    PROGRAM:

    DIVID .SET 0H DIVIS .SET 1H OUT .SET 2H .mmregs .text START: STM #140H, ST0 RSBX CPL RSBX FRCT NOP NOP NOP NOP LD DIVID, A RPT #0FH SUBC DIVIS, A STL A, OUT HLT: B HLT

    RESULT: Thus, the arithmetic operations using TMS320C5x was performed successfully.

  • CIRCULAR AND LINEAR CONVOLUTION

    AIM: To implement circular and linear convolution in TMS320C5x debugger.

    APPARATUS REQUIRED:

    1. System with TMS 320C5x debugger software 2. TMS 320C5x Kit. 3. RS232 cable.

    CIRCULAR CONVOLUTION FOR FOUR INPUTS

    PROGRAM: .mmregs .text

    START: STM #0140H,ST0 RSBX CPL RSBX FRCT NOP NOP NOP NOP STM #0A020H,AR2 RPT #4H ST #0H,*AR2+ STM #0A000H,AR0 STM #0A010H,AR1 STM #0A020H,AR2 STM #0A030H,AR3 STM #3H,AR4 CALL ROT1 CALL CONV NEXTY: CALL ROT2 CALL CONV BANZ NEXTY,*AR4-

    HLT: B HLT

    ROT1: STM #0A011H,AR0 STM #0A013H,AR1 LD *AR0,A LD *AR1,B STL A,*AR1 STL B,*AR0 RET

    Ex No: 11 Date :

  • ROT2: STM #0A013H,AR0 STM #0A012H,AR1 LD *AR0,A STM #2H,BRC RPTB ROT LD *AR1-,B ROT: STL B,*AR0- STM #0A010H,AR0 STL A,*AR0 STM #0H,BRC RET CONV: STM #0A000H,AR0 STM #0A010H,AR1 LD #0H,A STM #3H,BRC RPTB CON LD *AR0+,T

    CON: MAC *AR1+,A STL A,*AR3+ RET

    CONVOLUTION FOR FOUR INPUTS

    PROGRAM: .mmregs .text

    START: STM #40H,ST0 RSBX CPL RSBX FRCT NOP NOP NOP NOP STM #0A000H,AR0 STM #00100H,AR1 STM #0A020H,AR2

    LD #0H,A RPT #4H STL A,*AR2+ STM #0A004H,AR0

  • CIRCULAR CONVOLUTION FOR FOUR INPUTS

    INPUT: X1(n) DATA MEMORY

    0A000 0002 0A001 0001 0A002 0002 0A003 0001 INPUT: X2(n) DATA MEMORY 0A010 0001 0A011 0002 0A012 0003 0A013 0004 OUTPUT : Y(n) DATA MEMORY

    0A030 000E 0A031 0010 0A032 000E 0A033 0010

    CONVOLUTION FOR FOUR INPUTS

    INPUT: X(n) DATA MEMORY

    0A000 0001H 0A001 0003H 0A002 0001H 0A003 0003H

    INPUT: H(n) PROGRAM MEMORY

    00100 0000H ;h(n) 00101 0001H 00102 0002H 00103 0001H

    OUTPUT: Y(n) DATA MEMORY

    0A030 0001 0A031 0005 0A032 0008 0A034 0008 0A035 0007

  • LD #0H,A RPT #5H STL A,*AR0+ STM #0A000H,AR0 STM #0A020H,AR2 STM #0A030H,AR3 STM #6H,BRC RPTB CONV LD *AR0+,A STM #0A020H,AR2 STL A,*AR2 STM #0A023H,AR2 LD #0H,A RPT #3H MACD *AR2-,0100H,A CONV STL A,*AR3+

    HLT: B HLT

    RESULT: Thus the linear and circular convolution of two sequences is done successfully by using TMS320C5x.

  • SAMPLING OF ANALOG SIGNALS AIM: To implement sampling of analog signal in TMS320C5xdebugger.

    APPARATUS REQUIRED:

    1. System with TMS 320C5x debugger software 2. TMS 320C5x Kit. 3. RS232 cable.

    SAMPLING PROGRAM: .mmregs .text START: STM #01h, ST0 RSBX CPL RSBX FRCT NOP NOP NOP NOP *****loop to make x(n) zero initially***** STM #150H,AR1 LD #0H,A RPT #34H STL A,*AR1+ STM #3H,AR3 LOOP: LD #0H,A BANZ DEL0,*AR3- PORTR 04,0 LD 0,A AND #0FFFH,A XOR #0800H,A SUB #800H,A PORTR 06,0 STM #3H,AR3 B STORE DEL0: RPT #10 NOP *****filtering operation*****

    Ex No: 12 Date :

  • STORE: STM #150H,AR1 STL A,*AR1 STM #183H,AR2 LD #0H,A *****loop for convolution process***** RPT #33H MACD *AR2-,TABLE,A STH A,1,0H MPY 0H,#4H,A LD 0H,A ADD #800H,A STL A,1H PORTW 1H,04H B LOOP TABLE: .word 65H .word 0FF97H .word 0FED1H .word 0FE48H .word 0FE24H .word 0FE78H .word 0FF3CH .word 46H .word 15EH .word 23BH .word 29FH .word 25FH .word 174H .word 0H .word 0FE4CH .word 0FCBAH .word 0FBB9H .word 0FBAAH .word 0FCCFH .word 0FF37H .word 2BAH .word 6F9H .word 0B6FH .word 0F7FH .word 1297H .word 1443H

  • .word 1443H .word 1297H .word 0F7FH .word 0B6FH .word 6F9H .word 2BAH .word 0FF37H .word 0FCCFH .word 0FBAAH .word 0FBB9H .word 0FCBAH .word 0FE4CH .word 0H .word 174H .word 25FH .word 29FH .word 23BH .word 15EH .word 46H .word 0FF3CH .word 0FE78H .word 0FE24H .word 0FE48H .word 0FED1H .word 0FF97H .word 65H

    RESULT:

    Thus the sampling process is verified and executed using TMS320C5X.

  • WAVEFORM GENERATION AIM: To implement different waveforms in TMS320C5X debugger.

    APPARATUS REQUIRED:

    1. System with TMS 320C5X debugger software 2. TMS 320C5X Kit. 3. RS232 cable. 4. Function generator.

    SAWTOOTH WAVE GENERATION PROGRAM:

    DATA .SET 0H .mmregs .text START: STM #140H, ST0 RSBX CPL NOP NOP NOP NOP REP: ST #0H, DATA INC: LD DATA, A ADD #1H, A STL A, DATA PORTW DATA, 04H CMPM DATA, #0FFFH BC INC, NTC B REP

    SQUARE WAVE GENERATION PROGRAM:

    DATA .SET 0H .mmregs .text START: STM #140H,ST0 RSBX CPL NOP NOP NOP NOP

    Ex No: 13 Date :

  • REP: ST #0H,DATA CALL DELAY ST #0FFFH,DATA CALL DELAY B REP DELAY: STM #0FFFH,AR1 DEL1: PORTW DATA,04H BANZ DEL1,*AR1- RET

    TRIANGULAR WAVE GENERATION PROGRAM:

    DATA .SET 0H .mmregs .text START: STM #140H,ST0 RSBX CPL NOP NOP NOP NOP REP: ST #0H,DATA INC: LD DATA,A ADD #1H,A STL A,DATA PORTW DATA,04H CMPM DATA,#0FFFH BC INC,NTC DEC: LD DATA,A SUB #1H,A STL A,DATA PORTW DATA,04H CMPM DATA,#0H BC DEC,NTC B REP

    RESULT:

    Thus the waveforms were generated and executed using TMS320C5X.

  • FIR FILTER

    AIM: To implement FIR band pass filter in TMS320C5x debugger.

    APPARATUS REQUIRED:

    1. System with TMS 320C5x debugger software 2. TMS 320C5x Kit. 3. RS232 cable. 4. Function generator.

    BAND PASS FIR FILTER PROGRAM: .mmregs .text START: STM #01h,ST0 RSBX CPL RSBX FRCT NOP NOP *****loop to make all x(n) zero initially***** STM #150H,AR1 LD #0H,A RPT #34H STL A,*AR1+ *****to read the adc data and store it in x(0)***** LOOP: PORTR 06,0 CHK_BUSY: ;PORTR 07,0 ; BITF 0,#20H ; BC CHK_BUSY,TC PORTR 04,0 LD 0,A AND #0FFFH,A XOR #0800H,A SUB #800H,A STM #150H,AR1 STL A,*AR1 STM #183H,AR2 *****start of convolution***** LD #0H,A RPT #33H MACD *AR2-,TABLE,A STH A,1,0H LD 0H,A

    Ex No: 14 Date :

  • ADD #800H,A STL A,1H PORTW 1H,04H B LOOP

    TABLE: .word 208H .word 257H .word 218H .word 143H .word 0H .word 0FE9EH .word 0FD7AH .word 0FCE7H .word 0FD08H .word 0FDD1H .word 0FEECH .word 0FFE4H .word 3DH .word 0FFA1H .word 0FDFCH .word 0FB8FH .word 0F8ECH .word 0F6D4H .word 0F608H .word 0F713H .word 0FA21H .word 0FEE6H .word 4A7H .word 0A60H .word 0EF8H .word 1187H .word 1187H .word 0EF8H .word 0A60H .word 4A7H .word 0FEE6H .word 0FA21H .word 0F713H .word 0F608H .word 0F6D4H .word 0F8ECH .word 0FB8FH .word 0FDFCH .word 0FFA1H .word 3DH .word 0FFE4H .word 0FEECH .word 0FDD1H .word 0FD08H

  • .word 0FCE7H .word 0FD7AH .word 0FE9EH .word 0H .word 143H .word 218H .word 257H .word 208H

    RESULT:

    Thus the FIR band pass filter was executed successfully.