You are on page 1of 29

Department of Electronics and Communication Engineering Digital Signal Processing Lab

1. Generation of sinusoidal waveform


Aim:- To generate the following signals using MATLAB 1. Sine signal 2. Cosine signal Program: Cosine signal clc; clear all; close all; disp('COSINE SIGNAL'); N=input('Enter Number of Samples : '); n=0:.1:N x=cos(n); stem(n,x); xlabel('Time'); ylabel('Amplitude'); title('Cosine Signal'); Output:- COSINE SIGNAL Enter Number of Samples : 16

1
TRR ENGINEERING COLLEGE

Department of Electronics and Communication Engineering Digital Signal Processing Lab

Sine signal clc; clear all; close all; disp('SINE SIGNAL'); N=input('Enter Number of Samples : '); n=0:.1:N x=sin(n) stem(n,x); xlabel('Time'); ylabel('Amplitude'); title('sine Signal'); Output:- SINE SIGNAL Enter Number of Samples : 16

2
TRR ENGINEERING COLLEGE

Department of Electronics and Communication Engineering Digital Signal Processing Lab

2. DISCRETE FOURIER TRANSFORM


Aim:- To find DFT of given DT sequence. Apparatus: Computer with MATLAB software. Program: clc; clear all; clf; xn=input('enter the input seq='); N=input('length of dft='); xk=ifft(xn,N); k=0:1:N-1; subplot(2,1,1); stem(k,abs(xk)); xlabel('k'); ylabel('|x(k)|'); title('magnitude response'); subplot(2,1,2); stem(k,angle(xk)); xlabel('x'); ylabel('arg(xk)'); title('phase response); Output:enter the input seq=[1 1 1 1 0 1 1 1] length of dft=8

3
TRR ENGINEERING COLLEGE

Department of Electronics and Communication Engineering Digital Signal Processing Lab

Result:magnitude response 1

|x(k)|

0.5

k phase response 4 3

arg(xk)

2 1 0

3 x

4
TRR ENGINEERING COLLEGE

Department of Electronics and Communication Engineering Digital Signal Processing Lab

3. Frequency Response of a given system in (Transfer Function/ Difference equation form)


Aim :- To find the frequency response of the following difference equation y(n) 5 y(n1) = x(n) + 4 x(n1) Apparatus:- System with MATLAB Program:b = [1, 4]; %Numerator coefficients a = [1, -5]; %Denominator coefficients w = -2*pi: pi/256: 2*pi; [h] = freqz(b, a, w); subplot(2, 1, 1), plot(w, abs(h)); xlabel('Frequency \omega'), ylabel('Magnitude'); grid subplot(2, 1, 2), plot(w, angle(h)); xlabel('Frequency \omega'), ylabel('Phase - Radians'); grid

5
TRR ENGINEERING COLLEGE

Department of Electronics and Communication Engineering Digital Signal Processing Lab

Output:-

6
TRR ENGINEERING COLLEGE

Department of Electronics and Communication Engineering Digital Signal Processing Lab

4. FAST FOURIER TRANSFORM


Aim:- To implement FFT of a given sequence. Apparatus:- System with MATLAB Program:%FFT of the given sequence clc; clear all; clf; x1=input('enter the sequence x1='); n=input('enter the value of n='); xk=fft(x1,n); subplot(2,2,1) n=0:1:length(xk)-1; stem(n,abs(xk)); xlabel('n'); ylabel('amplitude'); title('magnitude plot '); subplot(2,2,2); stem(n,angle(xk)); xlabel('n'); ylabel('amplitude'); title('phase plot');

7
TRR ENGINEERING COLLEGE

Department of Electronics and Communication Engineering Digital Signal Processing Lab

Result:Input:Enter the sequence x1=[1 1 1 1 1 1 1 1] Enter the value of N=8

Output:magnitude plot 8 6 1 0.5 phase plot

amplitude

4 2 0

amplitude
0 2 4 n 6 8

0 -0.5 -1

4 n

8
TRR ENGINEERING COLLEGE

Department of Electronics and Communication Engineering Digital Signal Processing Lab

5. Determination of Power Spectrum


Aim: To obtain power spectrum of given signal using MATLAB. Apparatus:- System with MATLAB. Theory: In statistical signal processing the power spectral density is a positive real function of a frequency variable associated with a stationary stochastic process, or a deterministic function of time, which has dimensions of power per Hz, or energy per Hz. It is often called simply the spectrum of the signal. Intuitively, the spectral density captures the frequency content of a stochastic process and helps identify periodicities. The PSD is the FT of autocorrelation function, R() of the signal if the signal can be treated as a wide-sense stationary random process. Program:t = 0:0.001:0.6; x = sin(2*pi*50*t)+sin(2*pi*120*t); y = x + 2*randn(size(t)); figure,plot(1000*t(1:50),y(1:50)); title('Signal Corrupted with Zero-Mean Random Noise') xlabel('time (milliseconds)'); Y = fft(y,512); Pyy = Y.* conj(Y) / 512; f = 1000*(0:256)/512; figure,plot(f,Pyy(1:257)) title('Frequency content of y'); xlabel('frequency (Hz)');

9
TRR ENGINEERING COLLEGE

Department of Electronics and Communication Engineering Digital Signal Processing Lab

Output:Signal Corrupted with Zero-Mean Random Noise 5 4 3 2 1 0 -1 -2 -3 -4 -5

10

15

20 25 30 time (milliseconds)

35

40

45

50

10
TRR ENGINEERING COLLEGE

Department of Electronics and Communication Engineering Digital Signal Processing Lab

Frequency content of y 80 70 60 50 40 30 20 10 0

50

100

150

200 250 300 frequency (Hz)

350

400

450

500

11
TRR ENGINEERING COLLEGE

Department of Electronics and Communication Engineering Digital Signal Processing Lab

6. IMPLEMENTATION OF LP FIR FILTER


Aim :- To Design FIR LP Filter using Rectangular/Triangular/kaiser Windowing Technique. Apparatus:- System with MATLAB . Algorithm:- 1) Enter the pass band ripple (rp) and stop band ripple (rs).
2) Enter the pass band frequency (fp) and stop band frequency (fs). 3) Get the sampling frequency (f), beta value. 4) Calculate the analog pass band edge frequencies, w1 and w2. w1 = 2*fp/f w2 = 2*fs/f 5) calculate the numerator and denominator 6)Use an If condition and ask the user to choose either Rectangular Window or Triangular window or Kaiser window.. 7)use rectwin,triang,kaiser commands 8) Calculate the magnitude of the frequency response in decibels (dB m=20*log10(abs(h)) 9) Plot the magnitude response [magnitude in dB Vs normalized frequency (om/pi) ] 10)Give relevant names to x and y axes and give an appropriate title for the plot. 11)Plot all the responses in a single figure window.[Make use of subplot].

Program:%FIR Filter design window techniques 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= '); beta=input('enter beta value=); 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) y=rectwin(n1); disp('Rectangular window filter response'); end

12
TRR ENGINEERING COLLEGE

Department of Electronics and Communication Engineering Digital Signal Processing Lab

if (c==2) y=triang(n1); disp('Triangular window filter response'); end if(c==3) y=kaiser(n1,beta); disp('kaiser window filter response'); end b=fir1(n,wp,y); [h,o]=freqz(b,1,256); m=20*log10(abs(h)); plot(o/pi,m); title('LPF'); ylabel('Gain in dB-->'); xlabel('(a) Normalized frequency-->');

Output:enter passband ripple 0.02 enter the stopband ripple 0.01 enter passband freq 1000 enter stopband freq 1500 enter sampling freq 10000 enter beta value 5 enter your choice of window function 1. rectangular 2. triangular 3.kaiser: 1

Rectangular window filter response

13
TRR ENGINEERING COLLEGE

Department of Electronics and Communication Engineering Digital Signal Processing Lab

2 triangular window filter response

3 kaiser window filter response

14
TRR ENGINEERING COLLEGE

Department of Electronics and Communication Engineering Digital Signal Processing Lab

15
TRR ENGINEERING COLLEGE

Department of Electronics and Communication Engineering Digital Signal Processing Lab

7. FIR HIGH PASS FILTER DESIGN


Aim :- To Design FIR HP Filter using Rectangular/Triangular/Kaiser Windowing Technique. Apparatus :- System with MATLAB . Algorithm:1) Enter the pass band ripple (rp) and stop band ripple (rs). 2) Enter the pass band frequency (fp) and stop band frequency (fs). 3) Get the sampling frequency (f), beta value. 4) Calculate the analog pass band edge frequencies, w1 and w2. w1 = 2*fp/f w2 = 2*fs/f 5) Calculate the numerator and denominator 6) Use an If condition and ask the user to choose either Rectangular Window or Triangular window or Kaiser window. 7) Use rectwin,triang,kaiser commands 8) Calculate the magnitude of the frequency response in decibels (dB m=20*log10(abs(h)) 9) Plot the magnitude response [magnitude in dB Vs normalized frequency (om/pi)] 10) Give relevant names to x and y axes and give an appropriate title for the plot. 11) Plot all the responses in a single figure window.[Make use of subplot].

Program: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= '); beta=input('enter beta value='); 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;

16
TRR ENGINEERING COLLEGE

Department of Electronics and Communication Engineering Digital Signal Processing Lab

end c=input('enter your choice of window function 1. rectangular 2. triangular 3.kaiser: \n '); if(c==1) 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,beta); disp('kaiser window filter response'); end b=fir1(n,wp,'high',y); [h,o]=freqz(b,1,256); m=20*log10(abs(h)); plot(o/pi,m); title('HPF'); ylabel('Gain in dB-->'); xlabel('(b) Normalized frequency-->');

Output:enter passband ripple 0.02 enter the stopband ripple 0.01 enter passband freq 1000 enter stopband freq 1500 enter sampling freq 10000 enter beta value 5 enter your choice of window function 1. rectangular 2. triangular 3.kaiser: 1

17
TRR ENGINEERING COLLEGE

Department of Electronics and Communication Engineering Digital Signal Processing Lab

Rectangular Window:

2.Triangular Window

18
TRR ENGINEERING COLLEGE

Department of Electronics and Communication Engineering Digital Signal Processing Lab

3 Kaiser Window

19
TRR ENGINEERING COLLEGE

Department of Electronics and Communication Engineering Digital Signal Processing Lab

8. IIR LOWPASS FILTER DESIGN


Aim:-To perform the IIR Butterworth LPF filter functions on the given specifications and plot
the magnitude and phase response.

Apparatus:-Personal computer with MATLAB software. Program:clc; clear all; clf; ap=4;%pass band attenuation in db as=30;%stop band attenuation in db fp=400;%stop band frequency in hz fs=800;%stop band frequency in hz f=2000;%the sampling frequency in hz omp=2*fp/f; oms=2*fs/f; [n,wn]=buttord(omp,oms,ap,as); [b,a]=butter(n,wn,'low'); w=0:0.01:pi; [h,om]=freqs(b,a,w); m=20*log10(abs(h)); [h,om]=freqs(b,a,w); m=20*log10(abs(h)); an=angle(h); subplot(2,2,1); plot(om/pi,m); grid; ylabel('gain in db'); xlabel('normalised frequency'); title('magnitude response'); subplot(2,2,2); plot(om/pi,an); grid; ylabel('phase in radians'); xlabel('normalized frequency'); title('phase response');

20
TRR ENGINEERING COLLEGE

Department of Electronics and Communication Engineering Digital Signal Processing Lab

Output:-

magnitude response 40 4

phase response

phase in radians
0 0.5 normalised frequency 1

gain in db

20

2 0 -2 -4

-20

0.5 normalized frequency

21
TRR ENGINEERING COLLEGE

Department of Electronics and Communication Engineering Digital Signal Processing Lab

9. IIR HIGH PASS FILTER DESIGN


Aim:- To perform the IIR Butterworth HPF filter functions on the given specifications and plot
the magnitude and phase response.

Apparatus:-Personal computer with MATLAB software. Program:clc; clear all; ap=0.4;%pass band attenuation in db as=30;%stop band attenuation in db fp=400;%stop band frequency in hz fs=800;%stop band frequency in hz f=2000;%the sampling frequency in hz wp=2*fp/f; ws=2*fs/f; %to find cutoff frequency and order of the filter [n,wn]=buttord(wp,ws,ap,as); %system function of the filter [b,a]=butter(n,wn,'high'); w=0:0.01:pi; [h,om]=freqs(b,a,w); m=20*log10(abs(h)); [h,om]=freqs(b,a,w); m=20*log10(abs(h)); an=angle(h); subplot(2,2,1); plot(om/pi,m); grid; ylabel('gain in db'); xlabel('normalised frequency'); title('magnitude response'); subplot(2,2,2); plot(om/pi,an); grid; ylabel('phase in radians'); xlabel('normalized frequency'); title('phase response');

22
TRR ENGINEERING COLLEGE

Department of Electronics and Communication Engineering Digital Signal Processing Lab

Output:-

magnitude response 10 0 4

phase response

phase in radians
0 0.5 normalised frequency 1

2 0 -2 -4

gain in db

-10 -20 -30

0.5 normalized frequency

23
TRR ENGINEERING COLLEGE

Department of Electronics and Communication Engineering Digital Signal Processing Lab

10. IMPLEMENTATION OF DECIMATION PROCESS


Aim:-To perform Decimation process using MATLAB. Apparatus:-System with MATLAB Program:clear all; N=50;%sequence length n=0:1:N-1; x=sin(2*pi*n/20)+sin(2*pi*n/15);%input sequence M=2;%Downsampling factor x1=x(1:M:N); n1=1:1:N/M; subplot(2,1,1); stem(n,x); xlabel('n'); ylabel('x'); title('input sequence'); subplot(2,1,2); stem(n1-1,x1); xlabel('n'); ylabel('x1'); title('downsampled sequence');

24
TRR ENGINEERING COLLEGE

Department of Electronics and Communication Engineering Digital Signal Processing Lab

Output:input sequence 2 1 0 -1 -2

10

15

25 30 35 n downsampled sequence

20

40

45

50

2 1

x1

0 -1 -2

10 n

15

20

25

25
TRR ENGINEERING COLLEGE

Department of Electronics and Communication Engineering Digital Signal Processing Lab

11. IMPLEMENTATION OF INTERPOLATION PROCESS


Aim:-To perform Interpolation process using MATLAB. Apparatus:-System with MATLAB Program:clear all; N=10;%sequence length n=0:1:N-1; x=sin(2*pi*n/10)+sin(2*pi*n/5);%input sequence L=3;%Upsampling factor x1=[zeros(1,L*N)]; n1=1:1:L*N; j=1:L:L*N; x1(j)=x; subplot(2,1,1); stem(n,x); xlabel('n'); ylabel('x'); title('input sequence'); subplot(2,1,2); stem(n1,x1); xlabel('n'); ylabel('x1'); title('upsampled sequence');

26
TRR ENGINEERING COLLEGE

Department of Electronics and Communication Engineering Digital Signal Processing Lab

Output:-

input sequence 2 1 0 -1 -2

n upsampled sequence 2 1

x1

0 -1 -2

10

15 n

20

25

30

27
TRR ENGINEERING COLLEGE

Department of Electronics and Communication Engineering Digital Signal Processing Lab

12. Implementation of I/D Sampling Rate Converters


Aim:-To study sampling rate conversion by rational form using MATLAB. Apparatus:-System with MATLAB. Program:clc; close all; clear all; L=input(Enter Up-Sampling factor); M=input(Enter Down-Sampling factor); N=input(Enter number of samples); n=0:N-1; x=sin(2*pi*0.43*n)+sin(2*pi*0.31*n); y=resample(x,L,M); subplot(2,1,1); stem(n,x(1,N)); axis([0 29 -2.2 2.2]); title(input sequence); xlabel(Time Index n); ylabel(Amplitude); subplot(2,1,2); m=0:(N*L/M)-1; stem(m,y(1:N*L/M)); axis([0 (N*L/M)-1 -2.2 2.2]); title(Output sequence); xlabel(Time Index n);

28
TRR ENGINEERING COLLEGE

Department of Electronics and Communication Engineering Digital Signal Processing Lab

ylabel(Amplitude);

Output:-

29
TRR ENGINEERING COLLEGE

You might also like