0% found this document useful (0 votes)
53 views50 pages

Digital Signal Processing Lab MATLAB Guide

The document outlines the Digital Signal Processing Laboratory syllabus and includes various MATLAB experiments related to discrete-time signals, linear and circular convolutions, correlation, frequency analysis, and sampling effects. Each experiment includes aims, procedures, program codes, and expected results, demonstrating the application of MATLAB in signal processing tasks. The document serves as a comprehensive guide for students in the Electronics Engineering department to understand and implement key concepts in digital signal processing.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views50 pages

Digital Signal Processing Lab MATLAB Guide

The document outlines the Digital Signal Processing Laboratory syllabus and includes various MATLAB experiments related to discrete-time signals, linear and circular convolutions, correlation, frequency analysis, and sampling effects. Each experiment includes aims, procedures, program codes, and expected results, demonstrating the application of MATLAB in signal processing tasks. The document serves as a comprehensive guide for students in the Electronics Engineering department to understand and implement key concepts in digital signal processing.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

MUTHAYAMMAL ENGINEERING COLLEGE

(An Autonomous Institution)


(Approved by AICTE, New Delhi, Accredited by NAAC & Affiliated to Anna University)
Rasipuram – 637 408, Namakkal Dist., Tamil Nadu.

Department of Electronics Engineering -VLSI (Design & Technology)

23EVC25 - DIGITAL SIGNAL PROCESSING LABORATORY

LAB OBSERVATION

Prepared by,

[Link],AP/ECE
SYLLABUS

1 Generation of elementary Discrete-Time sequences in MATLAB


2 Linear and Circular convolutions in MATLAB
3 Auto correlation and Cross Correlation in MATLAB
[Link] Analysis of DFT in MATLAB
5 Sampling and effect of Aliasing in MATLAB
6 Implementation of sampling rate conversion by decimation, interpolation and a rational factor in MATLAB
[Link] of periodogram power spectral density in MATLAB
8 Implementations of Infinite Impulse Response (IIR) filter in MATLAB.
[Link] of finite Impulse Response (FIR) filter in MATLAB.
10 Any topic on recent areas of research in multirate Signal Processing
11 Solution of difference equations using z- Transform and Fourier tools,
12 Determination of RMS value Form factor and Zero crossing of signals
EXP DATE Name of the Experiment Marks Signature
NO of the staff
[Link]. : 1​ ​ GENERATION OF DISCRETE TIME SIGNALS USING MATLAB
Date:

AIM
Write a MATLAB program for the generation of Discrete time signals.

ALGORITHM
1. Initialize the value of t.
2. For each value of t find sine value and plot the sequence.
3. Similarly for each value of t find the cosine sequence and plot the sequence.
4. Find the exponential sequence for the given length and ‘a’ value and plot the sequence.
5. Enter the value of N for step sequence. Calculate its sequences and plot it.
6. Enter the length ramp sequence. Calculate its value and plot it.
7. Calculate the value for impulse sequence.

PROGRAM
%program for the generation of sine sequence

clc;
clear all;
close all;
t=0:0.01:pi;
y=sin(2*pi*t);
subplot(3,2,1);
stem(t,y);
ylabel('Amplitude…..>');
xlabel('time……->');
title('sine signal generation');
%Program for the generation of Cosine Sequence
t=0:0.01:pi;
y1=cos(2*pi*t);
subplot(3,2,2);
stem(t,y1);
ylabel('Amplitude…..>');
xlabel('time……>');
title('cosine signal generation');
%Program for the generation of Exponential Sequence
n=input('Enter the length of exponential sequence');
t1=0:n;
a=input('Enter the "a" value');
y2=exp(a*t1);
subplot(3,2,3);
stem(t1,y2);
ylabel('Amplitude-->');
xlabel('n-->');
title('exponential signal generation');
%Program for the generation of Unit step sequence
n1=input('Enter the N value');
t2=[Link]n1-1;
y3=ones(1,n1);
subplot(3,2,4);
stem(t2,y3);
ylabel('Amplitude…..>');
xlabel('time……>');
title('unit step signal generation');
%Program for the generation of Ramp sequence
subplot(3,2,5);
stem(t2,t2);
ylabel('Amplitude…..>');
xlabel('time……>');
title('unit ramp signal generation');

%Program for the generation of Unit Impulse sequence

t3=-[Link];
y4=[zeros(1,2),ones(1,1),zeros(1,2)];
subplot(3,2,6);
stem(t3,y4);
ylabel('Amplitude…..>');
xlabel('time……>');
title('unit impulse signal generation');
OUTPUT WAVEFORM:

RESULT

Thus the MATLAB program for the generation of discrete time sine, cosine, exponential, Unit step, Unit
Ramp and Impulse sequences were executed and the output sequences were plotted
[Link].: 2a​ ​ LINEAR CONVOLUTION USING MATLAB
Date:

AIM:
To Design and Perform the Linear Convolution between the two sequences by writing a program
using MATLAB
EQUIPMENTS:
Operating system – Windows XP
Constructor – Simulator
Software – MATLAB (R2016b)

THEORY:
Convolution is a formal mathematical operation, just as multiplication, addition, and integration.
Addition takes two numbers and produces a third number, while convolution takes two signals and
produces a third signal. Convolution is used in the mathematics of many fields, such as probability and
statistics. In linear systems, convolution is used to describe the relationship between three signals of
interest: the input signal, the impulse response, and the output signal.
​​ ​

In this equation, x1(k), x2(n-k) and y (n) represent the input to and output from the system at time n. Here
we could see that one of the input is shifted in time by a value every time it is multiplied with the other
input signal. Linear Convolution is quite often used as a method of implementing filters of various types.

PROCEDURE:
​ Start the MATLAB program.

​ Open new M-file

​ Type the program

​ Save in current directory

​ Compile and Run the program

​ If any error occurs in the program correct the error and run it again

​ For the output see command window\ Figure window

​ Stop the program.

PROGRAM CODING:
clc;
clear all;
close all;
x=input(‘enter the x value’);
y=input(‘enter the y value’);
z=conv(x,y);
subplot(3,1,1);
stem(x);
title(' inputs')
xlabel('time(s)')
ylabel('amplitude(v)')
subplot(3,1,3);
stem(z);
title(' linear convolution')
xlabel('time(s)')
ylabel('amplitude(v)')
disp(z)

MATLAB OUTPUT:

Enter the x value [1 2 3 4]


Enter the y value [1 2 3 4]
1 4 10 20 25 24
OUTPUT WAVEFORM:

RESULT:
Hence MATLAB Program for Linear Convolution is developed and executed for the verification of output
CIRCULAR CONVOLUTION USING MATLAB
[Link]. : 2b​
Date:

AIM:
To Design and Perform the Circular Convolution between the two sequences by writing a program using
MATLAB.

EQUIPMENTS:
●​ Operating system – Windows XP
●​ Constructor – Simulator
●​ Software – MATLAB (R2016b)

THEORY:
​ Circular convolution is another way of finding the convolution sum of two input signals. It resembles the
linear convolution, except that the sample values of one of the input signals is folded and right shifted
before the convolution sum is found. Also note that circular convolution could also be found by taking the
DFT of the two input signals and finding the product of the two frequency domain signals.
The Inverse DFT of the product would give the output of the signal in the time domain which is the
circular convolution output. The two input signals could have been of varying sample lengths. But we take
the DFT of higher point, which ever signals levels to. For eg. If one of the signal is of length 256 and the
other spans 51 samples, then we could only take 256 point DFT.
So the output of IDFT would be containing 256 samples instead of 306 samples, which follows N1+N2 – 1
where N1 & N2 are the lengths 256 and 51 respectively of the two inputs. Thus the output which should
have been 306 samples long is fitted into 256 samples. The 256 points end up being a distorted version of
the correct signal. This process is called circular convolution.

PROCEDURE:
​ Start the MATLA B program.

​ Open new M-file

​ Type the program

​ Save in current directory

​ Compile and Run the program

​ If any error occurs in the program correct the error and run it again

​ For the output see command window\ Figure window

​ Stop the program.


PROGRAM CODING:
clear all;
Xn = [1,2,1,1];
Hn = [1,1,1];
x=length(Xn);
h = length(Hn);
N = max(x,h);
Yn = cconv(Xn,Hn,N);
subplot(2,2,1);
stem(Xn);
title('First Input Sequence');
xlabel('Length of First Input Sequence');
subplot(2,2,2);
stem(Hn);
title('Second Input Sequence');
xlabel('Length of Second Input Sequence');
ylabel('Input Value');
subplot(2,2,3);
stem(Yn);
title('Circular Convolution Output Sequence');
xlabel('Length of Output Sequence');
ylabel('Output Value');

OUPUT:
13 14 11 12
OUTPUT WAVEFORM:

RESULT:
Hence MATLAB Program for circular Convolution is developed and executed for the verification of
output.
[Link]. : 3​ ​ CORRELATION OF SEQUENCES USING MATLAB
Date:

AIM:
​ To write a program and implement auto-correlation and cross-correlation functions using MATLAB.

EQUIPMENTS:
●​ Operating system – Windows XP
●​ Constructor – Simulator
●​ Software – MATLAB (R2016b)

PROCEDURE:
1.​ Start the MATLAB program.
2.​ Open new M-file
3.​ Type the program
4.​ Save in current directory
5.​ Compile and Run the program
6.​ If any error occurs in the program correct the error and run it again
7.​ For the output see command window\ Figure window
8.​ Stop the program.

Formulae:

AUTO CORRELATION

.
CROSS CORRELATION

.
PROGRAM: (Auto Correlation Function)
clc;
close all;
clear all;
x=input('Enter the sequence 1: ');
y=xcorr(x,x);
figure;
subplot(2,1,1);
stem(x);
ylabel('Amplitude->');
xlabel('n->');
title('Input sequence');
subplot(2,1,2);
stem(fliplr(y));
ylabel('amplitude');
xlabel('n->');
title('Output sequence');
disp('the resultant is ');
fliplr(y);

PROGRAM: (Cross-Correlation of the Sequences)


clc;
clear all;
close all;
x=input('Enter the sequence 1: ');
h=input('Enter the sequence 2: ');
y=xcorr(x,h);
figure;
subplot(3,1,1); stem(x);
xlabel('n->');
ylabel('Amplitude->');
title('Input sequence 1');
subplot(3,1,2);
stem(fliplr(y));
stem(h);
xlabel('n->');
ylabel('Amplitude->');
title('Input sequence 2');
subplot(3,1,3);
stem(fliplr(y));
xlabel('n->');
ylabel('Amplitude->');
title('Output sequence');
disp('The resultant is');
fliplr(y);

OUTPUT: (Auto-Correlation of the Sequence)


Enter the sequence [1 2 3 4]
The Resultant is [4 11 20 30 20 11 4]

OUTPUT WAVEFORM:

OUTPUT: (Cross-Correlation of the Sequences)


Enter the sequence 1: [1 3 5 7]
Enter the sequence 2: [2 4 6 8]
The Resultant is : [8 30 62 100 68 38 14]

RESULT:
Thus the implementation of correlation of sequences is done by using MATLAB.
[Link]. : 4​ ​ FREQUENCY ANALYSIS OF DFT USING MATLAB
Date:

AIM:
​​ To Calculate the values of DFT by writing a program using MATLAB. .

EQUIPMENTS:
Operating system – Windows XP
Constructor – Simulator
Software – MATLAB (R2016b)

THEORY:
​​ The discrete-time Fourier transform of a sequence is periodic, and we are interested in frequency
range 0 to 2π. There are infinitely in this range. If we use a digital computer to compute N equally

spaced points over the interval 0 <2 ,then the N points should be located a k=0,1…….N-1

These N equally spaced frequency samples of the DTFT is known as DFT denoted by X(K) is
​​
PROCEDURE:
​ Start the MATLABprogram.

​ Open newM-file

​ Type the program

​ Save in current directory

​ Compile and Run the program

​ If any error occurs in the program correct the error and run it again

​ For the output see command window\ Figure Window

​ Stop the program.

PROGRAM CODING:
clc;
xn=input(‘enter the xn value’);
N=4;
L=length(xn);
if (N<1);
error ('N must be greater than or equal to L');
end
x1=[xn,zeros(1,N-L)];
for k=0:N-1,
for n=[Link]N-1;
p=exp(-i*2*pi*n*(k/N));
x(k+1,n+1)=p;
end
end
xk=x1*x;
magxk=abs(xk);
angxk=angle(xk);
k=0:N-1;
Subplot (2,1,1);
stem(k,magxk);
title ('amplitude');
xlabel('k');
ylabel('MOD x(K)');
subplot(2,1,2);
stem(k,angxk);
title('phase');
xlabel('phase');
ylabel('ANG x(k)');
disp('magxk=');
disp(magxk);
disp('angxk=');
disp(angxk);
MATLAB:
magxk= 6.0000 2.8284 2.0000 2.8284
angxk= 0 -2.3562 0.0000 2.3562

OUTPUT WAVEFORM:

RESULT:
Hence DFT values are calculated manually and compared successfully with MATLAB program output
values and prove
[Link]. : 5​ SAMPLING AND EFFECT OF ALIASING USING MATLAB

AIM​ :

​ Write a Matlab program to sample the given Sinusoidal signal and plot the sampled output with and
without aliasing.

THEORY
Suppose we sample a signal, such as the one in Figure 1, which is band-limited to frequencies between 0
Hz and fn Hz. If we want to reconstruct the signal later, we must ensure that the sample rate, fs, is strictly
greater than 2*fn. A signal sampled at fs = 2*fn is said to be Nyquist sampled, and fs = 2*fn is called the
Nyquist frequency.
Note that information may be lost if a signal is sampled exactly at the Nyquist frequency. For example, the
sine wave in Figure 1 has a frequency of 1/2 Hz. The Nyquist frequency is therefore 1 Hz. If we sample
the sine wave at a rate of 1 Hz, say at t=0, t=1, t=2, and so on, all the sample values will be 0. The signal
will look is if it were identically 0, and no reconstruction method will be able to recreate the 1/2 Hz sine
wave. This is why fs must be strictly greater than 2*fn.

ALGORITHM:

1. Generate the Sinusoidal signal to be sampled.


2. Generate the pulse signal having the frequency more than the signal to be sampled.
3. Multiply both the signal and plot the waveforms.
4. Generate the pulse signal having the frequency which will not satisfy the Nyquist
theorem.
5. Multiply both the signal and plot the waveforms with aliasing.

PROGRAM
clc;

clear all;

close all;

t=0:0.01:2;

a=2;

fn=1.0;

sig=a*sin(2*pi*fn*t);

fs=24;

sampler=square(2*pi*fs*t); ​ ​ ​ % Generating Pulses

%// Shift the Sampling Signal to All Positive values

for​ i=1:length(sampler)

​ sampler(sampler==-1)= 0

end; ​ ​ ​ ​ ​ ​ % end for

sampled_sig = sampler.* sig; ​ ​ ​ % Sample the Sine Wave (Signal)

figure;
subplot(3,1,1)

plot(t,sig);

xlabel('time (sec)');

ylabel('signal amplitude');

title('sine signal: fn = 1.0 Hz, A = 2');

% Subplot the sampled signal

subplot(3,1,2)

plot(t,sampler,'g-');

xlabel('time (sec)');

ylabel('sampling signal magnitude');

title('square signal: fs =24 Hz');

subplot(3,1,3);

plot(t,sampled_sig,'m-');

xlabel('time (sec)');

ylabel('sampling value');

title('sampled signal');

grid;

fs=2;

sampler=square(2*pi*fs*t); ​ ​ ​ % Generating Pulses

%// Shift the Sampling Signal to All Positive values

for​ i=1:length(sampler)

​ sampler(sampler==-1)= 0

end; ​ ​ ​ ​ ​ ​ % end for

sampled_sig = sampler.* sig; ​ ​ ​ % Sample the Sine Wave (Signal)

figure;

subplot(3,1,1)

plot(t,sig);

xlabel('time (sec)');

ylabel('signal amplitude');

title('sine signal: fn = 1.0 Hz, A = 2');

% Subplot the sampled signal

subplot(3,1,2)
plot(t,sampler,'g-');

xlabel('time (sec)');

ylabel('sampling signal magnitude');

title('square signal: fs =24 Hz');

subplot(3,1,3);

plot(t,sampled_sig,'m-');

xlabel('time (sec)');

ylabel('sampling value');

title('sampled signal');

OUTPUT WAVEFORM:
RESULT:
Thus the sampled waveforms with and without aliasing are plotted.
Exp .No: 6. DECIMATION AND INTERPOLATION
Date:​

AIM:

To write a MATLAB program to decimation and interpolation of a give sequence

EQUIPMENTS:
●​ Operating system – Windows XP
●​ Constructor – Simulator
●​ Software – MATLAB (R2016b)
PROCEDURE:

●​ Open MATLAB
●​ Open new M-file
●​ Type the program
●​ Save in current directory
●​ Compile and Run the program
●​ For the output see command window\ Figure window

PROGRAM INTERPOLATION:
clc;
clear all;
close all;
L=input('enter the upsampling factor');
N=input('enter the length of the input signal');
% Length should be greater than 8
f1=input('enter the frequency of first sinusodal');
f2=input('enter the frequency of second sinusodal');
n=0:N-1;
x=sin(2*pi*f1*n)+sin(2*pi*f2*n);
y=interp(x,L);
subplot(2,1,1)
stem(n,x(1:N))
title('input sequence');
xlabel('time(n)');
ylabel('amplitude');
subplot(2,1,2)
m=0:N*L-1;
stem(m,y(1:N*L))
title('output sequence ');
xlabel('time(n)');
ylabel('amplitude');

INPUT:

enter the upsampling factor = 5


enter the length of the input signal = 9
enter the frequency of first sinusoidal = 0.1
enter the frequency of second sinusoidal = 0.3
Output waveform:

PROGRAM DECIMATION
clc;
close all;
clear all;
M = input('enter Down-sampling factor : ');
N = input('enter number of samples :');
n = 0:N-1;
x = sin(2*pi*0.043*n) + sin(2*pi*0.031*n);
y = decimate(x,M,'fir');
subplot(2,1,1);
stem(n,x(1:N));
title('Input Sequence');
xlabel('Time index n');
ylabel('Amplitude');
subplot(2,1,2);
m = 0:(N/M)-1;
stem(m,y(1:N/M));
title('Output Sequence');
xlabel('Time index n');
ylabel('Amplitude');
INPUT:
enter Down-sampling factor : 3
enter number of samples :100
Output waveform:

PROGRAM FOR CONVERSION OF SAMPLING RATE


clc;
clear all;
close all;
L=input('enter the upsampling factor');
N=input('enter the length of the input signal');
% Length should be greater than 8
f1=input('enter the frequency of first sinusodal');
f2=input('enter the frequency of second sinusodal');
n = 0:N-1;
x = sin(2*pi*0.043*n) + sin(2*pi*0.031*n);
y=resample(x,L,D);
subplot(2,1,1);
stem(n,x(1:N));
title('Input Sequence');
xlabel('Time index n');
ylabel('Amplitude');
subplot(2,1,2);
m = 0:(N/M)-1;
stem(m,y(1:N/M));
title('Output Sequence');
xlabel('Time index n');
ylabel('Amplitude');

Input:

Enter the up sampling factor =5


M = input ('enter Down-sampling factor: ');
Enter Down-sampling factor: 2
Enter the length of the input signal =40
Enter the frequency of first sinusoidal =0.01
Enter the frequency of second sinusoidal =0.03

Output waveform:
RESULT:
Thus the program for Decimation and Interpolation using MATLAB was successfully executed.
[Link]​ PERIODOGRAM POWER SPECTRAL DENSITY USING MATLAB
Date:

AIM:
​ To write a program and implement periodogram power spectral density using MATLAB.
EQUIPMENTS:
●​ Operating system – Windows XP
●​ Constructor – Simulator
●​ Software – MATLAB (R2016b)

PROCEDURE:
1.​ Start the MATLAB program.
2.​ Open new M-file
3.​ Type the program
4.​ Save in current directory
5.​ Compile and Run the program
6.​ If any error occurs in the program correct the error and run it again
7.​ For the output see command window\ Figure window
8.​ Stop the program.

PROGRAM:
Clc;
Close all;
Fs = 1000;
T = 0:1/fs:1-1/fs;
X = cos(2*pi*100*t) + randn(size(t));
N = length(x);
Xdft = fft(x);
Xdft = xdft(1:N/2+1);
Psdx = (1/(fs*N)) * abs(xdft).^2;
Psdx(2:end-1) = 2*psdx(2:end-1);
Freq = 0:fs/length(x):fs/2;
Plot(freq,pow2db(psdx))
Grid on
Title(‘Periodogram Using FFT’)
Xlabel(‘Frequency (Hz)’)
Ylabel(‘Power/Frequency (dB/Hz)’
OUTPUT WAVEFORM:

RESULT :

Thus the program for Periodogram power spectral density using MATLAB was successfully
executed.
[Link]. : 8​ DESIGN OF IIR FILTERS USING MATLAB
Date:

AIM:
​​ To write a program to design the IIR Filter (LPF/HPF/BPF/BSF) by using MATLAB.
EQUIPMENTS:
Operating system – Windows XP
Constructor – Simulator
Software – MATLAB (R2016b)

PROCEDURE:
​ Start the MATLAB program.

​ Open new M-file

​ Type the program

​ Save in current directory

​ Compile and Run the program

​ If any error occurs in the program correct the error and run it again

​ For the output see command window\ Figure window

​ Stop the program.

Program:

Low Pass IIR Filter


Clc;
close all;
clear all;
Format long
Rp=input(‘enter the passband ripple’);
rs=input(‘enter stopband ripple’);
wp=input(‘enter passband freq’);
ws=input(‘enter stopband freq’);
fs=input(‘enter sampling freq’); w1=2*wp/fs;
W2=2*ws/fs;
%Analog LPF
[n,wn]= buttord(w1,w2,rp,rs);
[b,a]=butter(n,wn,’s’); w=0:.01:pi;
[h,om]=freqs(b,a,w); m=20*log10(abs(h)); an=angle(h); figure(3)
Plot(om/pi,m);
Title(‘**** Analog Output Magnitude *****’);
ylabel(‘gain in db…>’);
Xlabel(‘normalised freq..>’); figure(2)
Plot(om/pi,an);
Title(‘**** Analog Output Phase ****’);
xlabel(‘normalised freq..>’);
ylabel(‘phase in radians…>’);
N wn
%Digital LPF
[n,wn]= buttord(w1,w2,rp,rs);
[b,a]=butter(n,wn); w=0:.01:pi;
[h,om]=freqz(b,a,w); m=20*log10(abs(h)); an=angle(h); figure(1) plot(om/pi,m);
Title(‘**** Digital Output Magnitude *****’); ylabel(‘gain in db…>’);
Xlabel(‘normalised freq..>’); figure(4)
Plot(om/pi,an);
Title(‘**** Digital Output Phase ****’); xlabel(‘normalised freq..>’); ylabel(‘phase in radians…>’);
N
Wn

INPUT:
Rp = 0.500
Rs = 100
Wp = 1500
Ws = 3000
Fs = 10000
Output:
N = 13
Wn = 0.32870936151976

OUTPUT WAVEFORM - LOW PASS IIR FILTER

PROGRAM – HIGH PASS IIR FILTER


Clc;
close all;
clear all;
Format long
Rp=input(‘enter the passband ripple’);
rs=input(‘enter stopband ripple’);
wp=input(‘enter passband freq’);
ws=input(‘enter stopband freq’);
fs=input(‘enter sampling freq’);
w1=2*wp/fs;
W2=2*ws/fs;
%Analog HPF
[n,wn]= buttord(w1,w2,rp,rs); [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(1) plot(om/pi,m);
Title(‘**** Analog Output Magnitude *****’); ylabel(‘gain in db…>’);
Xlabel(‘normalised freq..>’); figure(2)
Plot(om/pi,an);
Title(‘**** Analog Output Phase ****’); xlabel(‘normalised freq..>’); ylabel(‘phase in radians…>’);
N wn
%Digital HPF
[n,wn]= buttord(w1,w2,rp,rs);
[b,a]=butter(n,wn,’high’); w=0:.01:pi;
[h,om]=freqz(b,a,w); m=20*log10(abs(h));
An=angle(h); figure(3) plot(om/pi,m);
Title(‘**** Digital Output Magnitude *****’); ylabel(‘gain in db…>’);
Xlabel(‘normalised freq..>’); figure(4)
Plot(om/pi,an);
Title(‘**** Digital Output Phase ****’); xlabel(‘normalised freq..>’); ylabel(‘phase in radians…>’);
N wn

Input:
Rp = 0.5000 rs = 100
Wp = 1200 ws = 2400 fs = 8000
Output:
N = 13
Wn = 0.32870936151976

OUTPUT WAVEFORM - HIGH PASS IIR FILTER


PROGRAM – BANDPASS IIR FILTER
Clc;
Close all;
clear all;
format long
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]=buttord(w1,w2,rp,rs);
wn=[w1 w2];
[b,a]=butter(n,wn,’bandpass,s’);
w=0:.01:pi;
[h,om]=freqs(b,a,w);
m=20*log10(abs(h));
an=angle(h);
subplot(2,1,1);
plot(om/pi,m);
Ylabel(‘Gain in dB --.’);
Xlabel(‘(a) Normalised frequency --.’); subplot(2,1,2);
Plot(om/pi,an);
Xlabel(‘(b) Normalised frequency --.’); ylabel(‘Phase in radians --.’);

OUTPUT:

Enter the passband ripple… 0.36


enter the stopband ripple… 36
enter the passband freq…1500
enter the stopband freq… 2000\
OUTPUT WAVEFORM:

PROGRAM - BAND STOP IIR FILTER


clc;
Close all;
clear all;
format long
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]=buttord(w1,w2,rp,rs,’s’);
wn=[w1 w2];
[b,a]=butter(n,wn,’stop’,’s’);
w=0:.01:pi;
[h,om]=freqs(b,a,w);
m=20*log10(abs(h));
an=angle(h);
subplot(2,1,1);
plot(om/pi,m);
ylabel(‘Gain in dB --.’);
Xlabel(‘(a) Normalised frequency --.’);
subplot(2,1,2);
plot(om/pi,an);
xlabel(‘(b) Normalised frequency --.’);
Ylabel(‘Phase in radians --.’);

OUTPUT:
Enter the passband ripple… 0.28
enter the stopband ripple… 28
enter the passband freq… 1000
enter the stopband freq… 1400
enter the sampling freq… 5000

OUTPUT WAVEFORM:
RESULT:
Thus the program to design IIR Filter (LPF/HPF/BPF/BSF) by using MATLAB was executed
[Link]. : 9​ FIR FILTER USING WINDOWS USING MATLAB
Date:

Aim:
To write a program to design the FIR Filters (Rectangular Window and Hanning Window)
(LPF/HPF/BPF/BSF) by using MATLAB.
Equipments:
●​ Operating system – Windows XP
●​ Constructor – Simulator
●​ Software – MATLAB (R2016b)

Theory:
​ ​ In this technique we have some oscillations in the passband and stopband. These oscillations are due
to the truncation of the Fourier series

n=±

where, N is the length of the sequence.


Formulae:
RECTANGULAR WINDOW

WR(n)=1 for ≤n≤

HANNING WINDOW

WH(n)=0.50 + 0.50 for ≤n≤

PROCEDURE:
​ Start the MATLABprogram.

​ Open newM-file

​ Type the program

​ Save in current directory

​ Compile and Run the program

​ If any error occurs in the program correct the error and run it again

​ For the output see command window\ Figure Window

​ Stop the program.


PROGRAM (Rectangular Window)
%program for the design of FIR low pass, high pass, band pass and band stop
filter using rectangular window
clc;
clear all;
close all;
rp=input('enter the passband ripple');
rs=input('enter the stopband 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=-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;
y=boxcar(n1);

%lowpass 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);
ylabel('gain in db....>');
xlabel('(a)normalized frequency.....>');
%highpass 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);
ylabel('gain in db......>');
xlabel('(b)normalized frequency......>');

%bandpass filter
wn=[wp ws];0
b=fir1(n,wn,y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,3);
plot(o/pi,m);
ylabel('gain in db....>');
xlabel('(c)normalized frequency....>');

%bandstop filter
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);
ylabel('gain in db....>');
xlabel('(d)normalized frequency.....>')
OUTPUT: (Rectangular Window)
Enter the pass band ripple 0.03
Enter the stop band ripple 0.01
Enter the pass band frequency 1400
Enter the stop band frequency 2000
Enter the sampling frequency 8000

OUTPUT WAVEFORM - RECTANGULAR WINDOW

PROGRAM: (Hanning Window)


%program for the design of FIR lowpass, high pass, band pass, band stop filter
using hanning window
clc;
clear all;
close all;
rp=input('enter the passband ripple');
rs=input('enter the stopband 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=-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;
Y=hanning(n1);
%lowpass 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);
ylabel('gain in db....>');
xlabel('(a)normalized frequency');
%highpass 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);
ylabel('gain in db...>');
xlabel('(b)normalized frequency...>');
%bandpass 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);
ylabel('gain in db.....>');
xlabel('(c)normalized frequency....>');
%bandstop filter
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);
ylabel('gain in db...>');
xlabel('(d)normalized frequency....>')

OUTPUT WAVEFORM - HANNING WINDOW

RESULT:
Thus the program to design the FIR Filters (Rectangular Window and Hanning Window)
(LPF/HPF/BPF/BSF) by using MATLAB was executed.
[Link]. : 10 RMS Value Form Factor and Zero Crossing Signals
Date:

AIM:
​ ​ To write a program to design [Link] Value Form Factor and Zero Crossing Signals by
using MATLAB.

EQUIPMENTS:

●​ Operating system – Windows XP


●​ Constructor – Simulator
●​ Software – MATLAB (R2016b)

PROCEDURE:

​ Start the MATLAB program.


​ Open new M-file
​ Type the program
​ Save in current directory
​ Compile and Run the program
​ If any error occurs in the program correct the error and run it again
​ For the output see command window\ Figure window
​ Stop the program.

PROGRAM:
M= rand (3,100);
[rows, columns) = size (M);
Cal_rms = zeros(rows, 1);
for row = l:size (M,1)
Cal_rms (row) = sqrt(sum (M(row,:).^2) / columns);
end
Cal_rms
Cal rms = 3*1
End
0.5737
0.5854
0.5894

% Program for waveform of RMS %

A=[2 4 7 10 28]; %first


B=[1 3.6 8 11 27];%seccond
C=[0.5 5 9.5 13 32];%third
M=[A.', B.', C.'];
[rows, columns] = size(M);
MEAN=zeros(rows,1);
for row = 1 : rows
MEAN(row) = mean(M(row, :));
cal_rms(row) = sqrt(sum((MEAN(row)-M(row,:)).^2)/columns);
end
plot(cal_rms)

OUTPUT WAVEFORM:
%Program For Zero Crossing Signals %
clc;
t = [1:0.01:5];
y = -2+2.*sin(2*pi*t);
zci = @(v) find(v(:).*circshift(v(:), [-1 0]) <= 0);
zx = zci(y);
figure(1)
plot(t, y, '-r')
hold on
plot(t(zx), y(zx), 'bp')
hold off
grid
legend('Signal', 'Approximate Zero-Crossings')

OUTPUT WAVEFORM :

RESULT :
Thus the program for RMS Value Form Factor and Zero Crossing Signals
using MATLAB was successfully executed.

You might also like