0% found this document useful (0 votes)
11 views92 pages

Experiments

The document outlines the creation of MATLAB scripts for generating basic signals, performing linear and circular convolutions, and computing autocorrelation and cross-correlation for given sequences. It includes detailed algorithms, source codes, and expected outputs for each task, along with explanations of key concepts and viva questions. The results of the MATLAB programs are verified through manual calculations.

Uploaded by

IG VIPER YT
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)
11 views92 pages

Experiments

The document outlines the creation of MATLAB scripts for generating basic signals, performing linear and circular convolutions, and computing autocorrelation and cross-correlation for given sequences. It includes detailed algorithms, source codes, and expected outputs for each task, along with explanations of key concepts and viva questions. The results of the MATLAB programs are verified through manual calculations.

Uploaded by

IG VIPER YT
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
You are on page 1/ 92

AIM:

To write a MATLAB Script to perform generation of various basic signals for the given
sequences.

COMPONENTS REQUIRED:
PC, MATLAB software

ALGORITHM/PROCEDURE:

1. Click on the MATLAB icon on the desktop (or go to Start - All Programs and click on
MATLAB) to get into the Command Window
2. Type ‘edit’ in the MATLAB prompt ‘>>’ that appears in
the Command window.
3. Write the program in the ‘Edit’ window and save it as ‘m-file’
4. Run the program
5. Enter the input in the command window
6. The result is displayed in the Command window and the graphical output is displayed
in the Figure Window

PROGRAM:
clc;
clear all;
close all;
figure(1);

%UNIT IMPULSE SEQUENCE


s=0;
d=1;
subplot(3,3,1);
stem(s,d);
grid on;
xlabel('Time');
ylabel('Amplitude');
title('UNIT IMPULSE SEQUENCE');
%UNIT STEP SEQUENCE
N=15;
n=0:1:N-1;
s = ones(1,N);
subplot(3,3,3);
stem(n,s);
grid on;
xlabel('Time');
ylabel('Amplitude');
title('UNIT STEP SEQUENCE');

%UNIT RAMP SEQUENCE


n=0:1:20;
subplot(3,3,5);
stem(n,n);
grid on;
xlabel('Time');
ylabel('Amplitude');
title('UNIT RAMP SEQUENCE');

%GROWING EXPONENTIAL SEQUENCE


n=0:0.1:1;
r = exp(n);
subplot(3,3,7);
stem(n,r);
grid on;
xlabel('Time');
ylabel('Amplitude');
title('GROWING EXPONENTIAL SEQUENCE');

%DECAYING EXPONENTIAL SEQUENCE


n=0:0.1:1;
X=exp(-n);
subplot(3,3,9);
stem(n,X);
grid on;
xlabel('Time');
ylabel('Amplitude');
title('DECAYING EXPONENTIAL SEQUENCE');
OUTPUT:
%SINE WAVE
n = 0:0.5:10;
s=sin(-n);
subplot(3,3,6);
stem(n,s);
grid on;
xlabel('Time');
ylabel('Amplitude');
title('SINE WAVE');

%COSINE WAVE
n = 0:0.5:10;
s = cos(n);
subplot(3,3,4);
stem(n,s);
grid on;
xlabel('Time');
ylabel('Amplitude');
title('COSINE WAVE');

RESULT:
The generation of various signals are performed by using MATLAB script and the program
results are verified.
VIVA QUESTIONS:

1.Why did you use stem() instead of plot()?


Because we are dealing with discrete signals. stem() represents samples as impulses.

2. What is the purpose of subplot() in MATLAB?


It allows multiple plots in a single figure window for comparison.

3. Why do we use grid on?


To improve visualization and accurately locate signal values.

4. What does n=0:1:N-1; represent?


It defines the sample index vector for discrete-time signals.

5. What is the difference between exp(n) and exp(-n) in your code?


exp(n) produces a growing exponential, exp(-n) produces a decaying exponential.

6. What is the unit impulse sequence δ[n]?


A sequence equal to 1 at n=0 and 0 elsewhere.

7. What is the unit step sequence u[n]?


A sequence equal to 1 for n ≥ 0, and 0 for n < 0.

8. How is the ramp sequence defined?


r[n] = n for n ≥ 0, 0 for n < 0. (Plotted as a straight line in discrete steps).

9. How are sine and cosine signals different?


Sine starts at 0, cosine starts at 1 at n=0; they are phase-shifted by 90°.

10. Where do exponential signals appear in real systems?


In natural growth/decay, charging/discharging of capacitors, and system responses.
AIM:
To write a MATLAB Script to perform discrete convolution (Linear and Circular) for the given
two sequences.

COMPONENTS REQUIRED:
PC, MATLAB software.

ALGORITHM/PROCEDURE:
1. Click on the MATLAB icon on the desktop (or go to Start - All Programs and click
on MATLAB) to get into the Command Window
2. Type ‘edit’ in the MATLAB prompt ‘&gt;&gt;’ that appears in the Command
window.
3. Write the program in the ‘Edit’ window and save it as ‘m-file’
4. Run the program
5. Enter the input in the command window
6. The result is displayed in the Command window and the graphical output is
displayed in the Figure Window.

LINEAR CONVOLUTION:
1. Enter the sequences (Input x[n] and the Impulse response h[n])
2. Perform the linear convolution between x[k] and h[k] and obtain y[n].
3. Find the FFT of x[n] & h[n].Obtain X and H
4. Multiply X and H to obtain Y
5. Find the IFFT of Y to obtain y’[n]
6. Compute error in time domain e=y[n]-y’[n]
7. Plot the Results
OUTPUT WAVEFORMS
LINEAR CONVOLUTION

Input: Enter the first sequence to be convoluted:[1,2,3,4]


Enter the second sequence to be convoluted:[2,3,4]

Output

The Linear convoluted sequence is


2 7 16 25 24 16

Output Waveforms
CIRCULAR CONVOLUTION
1. Enter the sequences (input x[n] and the impulse response h[n])
2. Make the length of the sequences equal by padding zeros to the
smaller length sequence.
3. Perform the circular convolution between x[k] and h[k]and obtain y[n].
4. Find the FFT of x[n] & h[n].Obtain X and H
5. Multiply X and H to obtain Y
6. Find the IFFT of Y to obtain y’[n]
7. Compute error in time domain e=y[n]-y’[n]. Plot the Results

SOURCE CODE 1 – LINEAR CONVOLUTION

clc;
clear all;
close all;
%Program to perform Linear Convolution
x1=input('Enter the first sequence to be convoluted:');
subplot(3,1,1);
stem(x1);
xlabel('Time');
ylabel('Amplitude');
title('First sequence');
x2=input('Enter the second sequence to be convoluted:');
subplot(3,1,2);
stem(x2);
xlabel('Time');
ylabel('Amplitude');
title('Second sequence');
f=conv(x1,x2);
disp('The Linear convoluted sequence is');
disp(f);
subplot(3,1,3);
stem(f);
xlabel('Time');
ylabel('Amplitude');
title('Linear Convoluted sequence');
CIRCULAR CONVOLUTION

Input: Enter the first sequence to be convoluted:[1,2,3,4]


Enter the second sequence to be convoluted:[2,3,4]

Output

The Circular convoluted sequence is


Columns 1 through 5

2.0000 7.0000 16.0000 25.0000 24.0000

Columns 6 through 7
16.0000 0.0000

Output Waveforms
SOURCE CODE 2 – CIRCULAR CONVOLUTION
clc;
clear all;
close all;
%Program to perform Circular Convolution
x1=input('Enter the first sequence to be convoluted:');
subplot(3,1,1);
l1=length(x1); stem(x1);
xlabel('Time');
ylabel('Amplitude');
title('First sequence');
x2=input('Enter the second sequence to be convoluted:');
subplot(3,1,2);
l2=length(x2); stem(x2);
xlabel('Time');
ylabel('Amplitude');
title('Second sequence');
if l1>l2
l3=l1-l2;
x2=[x2,zeros(1,l3)];
elseifl2>l1
l3 = l2-l1;
x1=[x1,zeros(1,l3)];
end
f=cconv(x1,x2);
disp('The Circular convoluted sequence is');
disp(f);
subplot(3,1,3);
stem(f);
xlabel('Time');
ylabel('Amplitude');
title('Circular Convoluted sequence');

RESULT:
The linear and circular convolutions of two signals are performed by using MATLAB script and
the program results are verified by manual calculation.
VIVA QUESTIONS:

1. What is convolution?
Convolution is a mathematical operation used to determine the output of an LTI (Linear Time-
Invariant) system when the input and system’s impulse response are known.

2. Difference between Linear and Circular Convolution?


Linear convolution gives the actual output of an LTI system, while circular convolution is
mainly used in discrete Fourier transform (DFT) computations due to periodicity.

3. What is the length of the linear convolution output?


For two sequences of length L and M, the output length is L + M – 1.

4. What is the length of the circular convolution output?


It is always equal to max(L, M) after equalizing sequence lengths using zero-padding.

5. Why do we need zero-padding in circular convolution?


To make both sequences of equal length before applying the circular convolution formula.

6. What does conv(x1,x2) do in MATLAB?


It performs linear convolution of two sequences.

7. What does cconv(x1,x2) do in MATLAB?


It performs circular convolution of two sequences.

8. Why do we use stem() in plotting the sequences?


Because convolution deals with discrete signals, which are represented by stem plots instead of
continuous lines.

9. Why do we write disp(f) in your code?


To display the convolution result sequence in the MATLAB command window.

10. What is the role of subplot() in your program?


It is used to plot multiple sequences (input signals and output) in one figure window for
comparison.
AIM:
To write a MATLAB program to compute autocorrelation for the given sequence and cross
correlation between two signals.

COMPONENTS REQUIRED:
PC, MATLAB software

SOURCE CODE:

clc;
clear;
close all;
% Input signal 1
x = input('Enter the first signal (x[n]): ');
% Input signal 2
y = input('Enter the second signal (y[n]): ');
% Compute Auto-correlation of x[n]
auto_corr_x = xcorr(x, x);
% Compute Auto-correlation of y[n]
auto_corr_y = xcorr(y, y);
% Compute Cross-correlation between x[n] and y[n]
cross_corr = xcorr(x, y);
% Display Results
disp('Auto-correlation of x[n]:');
disp(auto_corr_x);
disp('Auto-correlation of y[n]:');
disp(auto_corr_y);
disp('Cross-correlation between x[n] and y[n]:');
disp(cross_corr);
% Plot Results
figure;
% Auto-correlation of x[n]
subplot(3, 1, 1);
stem(-length(x)+1:length(x)-1, auto_corr_x, 'r', 'LineWidth', 1.5);
OUTPUT:
Enter the first signal (x[n]): [1,2,3,4]
Enter the second signal (y[n]): [2,1,0,1]
Auto-correlation of x[n]:
4.0000 11.0000 20.0000 30.0000 20.0000 11.0000 4.0000
Auto-correlation of y[n]:
2 1 2 6 2 1 2
Cross-correlation between x[n] and y[n]:
1.0000 2.0000 4.0000 8.0000 7.0000 10.0000 8.0000
xlabel('Lag');
ylabel('Amplitude');
title('Auto-correlation of x[n]');
grid on;
% Auto-correlation of y[n]
subplot(3, 1, 2);
stem(-length(y)+1:length(y)-1, auto_corr_y, 'b', 'LineWidth', 1.5);
xlabel('Lag');
ylabel('Amplitude');
title('Auto-correlation of y[n]');
grid on;
% Cross-correlation of x[n] and y[n]
subplot(3, 1, 3);
stem(-max(length(x), length(y))+1:max(length(x), length(y))-1, cross_corr, 'g',
'LineWidth', 1.5);
xlabel('Lag');
ylabel('Amplitude');
title('Cross-correlation between x[n] and y[n]');
grid on;

RESULT:
The auto correlation and cross correlation of two signals are performed by using MATLAB
script and the program results are verified by manual calculation.
VIVA QUESTIONS:

1. What is correlation?
Correlation is a measure of similarity between two signals as a function of time-lag
applied to one of them.

2. What is auto-correlation?
Auto-correlation is the correlation of a signal with a delayed version of itself.

3. What is cross-correlation?
Cross-correlation is the correlation between two different signals.

4. What is the difference between correlation and convolution?


Convolution involves time-reversal and shifting, while correlation involves only shifting
(no reversal).

5. What is the significance of auto-correlation?


It helps identify repeating patterns, periodicity, and signal energy.

6. What is the maximum value of the auto-correlation function?


It occurs at zero lag (when the signal is aligned with itself).

7. What does the symmetry property of auto-correlation state?


Auto-correlation is always an even function:

Rxx[n]=Rxx[−n]R_{xx}[n] = R_{xx}[-n]Rxx[n]=Rxx[−n]

8. Is cross-correlation always symmetric?


No, cross-correlation is not necessarily symmetric.

9. What is the relation between correlation and energy of a signal?


For an energy signal, the energy is equal to the value of the auto-correlation at zero lag.

10. How is correlation related to Fourier transform?


The Fourier transform of auto-correlation gives the Power Spectral Density (PSD) of the
signal.
AIM:
To write a MATLAB program to perform the Discrete Fourier Transform/Fast Fourier Transform
for the given sequences.

COMPONENTS REQUIRED:
PC, MATLAB software

ALGORITHM/PROCEDURE:
1. Click on the MATLAB icon on the desktop (or go to Start - All
Programs and click on MATLAB) to get into the Command Window
2. Type ‘edit’ in the MATLAB prompt ‘>>’ that appears in the Command window.
3. Write the program in the ‘Edit’ window and save it as ‘m-file’
4. Run the program
5. Enter the input in the command window
6. The result is displayed in the Command window and the
graphical output is displayed in the Figure Window
Source Code :1
clc;
clear all;
close all;
%Get the sequence from user
disp('The sequence from the user:');
xn=input('Enter the input sequence x(n):');

% To find the length of the sequence


N=length(xn);

%To initilise an array of same size as that of input sequence


Xk=zeros(1,N);
iXk=zeros(1,N);

%code block to find the DFT of the sequence


for k=0:N-1
for n=0:N-1
Xk(k+1)=Xk(k+1)+(xn(n+1)*exp((-i)*2*pi*k*n/N));
Input:
The sequence from the user:
Enter the input sequence x(n) :[1,2,3,4]
The discrete fourier transform of x(n) :
10.0000 -2.0000 + 2.000i -2.0000 – 0.0000i -2.0000 – 2.0000i

The magnitude response of X(k) :


10.0000 2.8284 2.0000 2.8284

The phase response of X(k) :

0 2.3562 -3.1416 -2.3562


end
end

%code block to plot the input sequence


t=0:N-1;
subplot(3,2,1);
stem(t,xn);
ylabel('Amplitude');
xlabel('Time Index');
title('Input Sequence');

%code block to plot the X(k)


disp('The discrete fourier transform of x(n):');
disp(Xk);
t=0:N-1;
subplot(3,2,2);
stem(t,Xk);
ylabel('Amplitude');
xlabel('Time Index');
title('X(k)');

% To find the magnitudes of individual DFT points


magnitude=abs(Xk);

%code block to plot the magnitude response


disp('The magnitude response of X(k):');
disp(magnitude);
t=0:N-1;
subplot(3,2,3);
stem(t,magnitude);
ylabel('Amplitude');
xlabel('K');
title('Magnitude Response');

%To find the phases of individual DFT points


phase=angle(Xk);

%code block to plot the phase response


disp('The phase response of X(k):');
disp(phase);
t=0:N-1;
subplot(3,2,4);
stem(t,phase);
xlabel('K');
title('Phase Response');
Output of Spectrum Analysis with the FFT:
% Code block to find the IDFT of the sequence
for n=0:N-1
for k=0:N-1
iXk(n+1)=iXk(n+1)+(Xk(k+1)*exp(i*2*pi*k*n/N));
end
end
iXk = iXk/N;
%code block to plot the output sequence
t=0:N-1;
subplot(3,2,5);
stem(t,xn);
ylabel ('Amplitude');
xlabel ('Time Index');
title ('IDFT sequence');

%code block to plot the FFT of input sequence using inbuilt function
x2=fft(xn);
subplot(3,2,6);
stem(t,x2);
ylabel ('Amplitude');

xlabel ('Time Index');


title ('FFT of input sequence');

% Spectrum Analysis with the FFT


n = [0:149];
x1 = cos(2*pi*n/10);
N = 2048;
X = abs(fft(x1,N));
X = fftshift(X);
F = [-N/2:N/2-1]/N;
figure(2):
plot(F,X);
xlabel('frequency / f s') ;
ylabel('Magnitude')
OUTPUT 2:
Source Code: 2

% Spectrum Analysis with the FFT with noise


clc;
clear all;
close all;
fs = 100; % sample frequency (Hz)
t = 0:1/fs:10-1/fs;% 10 second span time vector
x = (1.3)*sin(2*pi*15*t) ...% 15 Hz component
+ (1.7)*sin(2*pi*40*(t-2)) ...% 40 Hz component
+ 2.5*gallery('normaldata',size(t),4); % Gaussian noise;
y = fft(x);
n = length(x); % number of samples
f = (0:n-1)*(fs/n); % frequency range
power = abs(y).^2/n; % power of the DFT
plot(f,power);
xlabel('Frequency');
ylabel('Power');
y0 = fftshift(y); % shift y values
f0 = (-n/2:n/2-1)*(fs/n); % 0-centered frequency range
power0 = abs(y0).^2/n; % 0-centered power
plot(f0,power0);
xlabel('Frequency');
ylabel('Power');

RESULT:
The program for frequency analysis using DFT/FFT are performed by using MATLAB
script and the program results are verified by manual calculation.
VIVA QUESTIONS:

1. What is the Discrete Fourier Transform (DFT)?


The DFT converts a finite-length discrete-time signal into its frequency-domain
representation.

2. What is the Fast Fourier Transform (FFT)?


FFT is an efficient algorithm to compute the DFT with reduced computational
complexity.

3. What is the computational advantage of FFT over DFT?

DFT requires N2N^2N2 operations, while FFT reduces it to Nlog⁡2NN \log_2 NNlog2N.

4. Why do we use fft(xn) in MATLAB?


To compute the DFT of a sequence quickly using the FFT algorithm.

5. What is fftshift() used for in MATLAB?


It rearranges FFT output so that zero frequency is at the center of the spectrum.

6. Why do we add Gaussian noise in spectrum analysis?


To simulate real-world signals and observe how noise affects the frequency spectrum.

7. What is the difference between DTFT and DFT?


DTFT is continuous in frequency and infinite-length, while DFT is discrete in frequency
and finite-length.

8. What is the length of the DFT output?


Always equal to the input sequence length NNN.

9. What is the magnitude spectrum of a signal?


It shows the absolute value of DFT coefficients, representing the strength of frequency
components.

10. What is the phase spectrum of a signal?


It represents the phase angle of DFT coefficients.
AIM:
To write a MATLAB program to perform the Discrete Fourier Transform/Fast Fourier Transform
for the given sequences.

COMPONENTS REQUIRED:
PC, MATLAB software

ALGORITHM/PROCEDURE:
1. Click on the MATLAB icon on the desktop (or go to Start - All
Programs and click on MATLAB) to get into the Command Window
2. Type ‘edit’ in the MATLAB prompt ‘>>’ that appears in the Command window.
3. Write the program in the ‘Edit’ window and save it as ‘m-file’
4. Run the program
5. Enter the input in the command window
6. The result is displayed in the Command window and the
graphical output is displayed in the Figure Window
Steps in DIF-FFT for N=4

1. Input Validation:
o N=4, which is a power of 2.
2. Butterfly Computation (Stage 1):
o Combine elements with sums and differences in groups of 2:
▪ x[0]= x[0]+x[2]
▪ x[1]= x[1]+x[3]
▪ x[2]=x[0]−x[2]
▪ x[3]= x[1]−x[3]
3. Twiddle Factors:
o Twiddle factors are applied in the final stages:
▪ WN=e−j2πkNW_N = e^{-j \frac{2\pi k}{N}}WN=e−jN2πk.
4. Final Combination:
o Combine results using sums and differences again.
Source Code : DIF-FFT

clc;
clear;
close all;
% Input sequence length
N = 4; % Fixed length of the sequence
disp('DIF-FFT for N = 4');
disp('Enter the input sequence (real and imaginary parts):'); % Input sequence
re = zeros(1, N); % Real part
im = zeros(1, N); % Imaginary part
for i = 1:N
re(i) = input(['Real part at index ', num2str(i-1), ': ']);
im(i) = input(['Imaginary part at index ', num2str(i-1), ': ']);
end
% Combine real and imaginary parts into a complex sequence
x = re + 1j * im; % Stage 1: Butterfly computation
x(1:2) = x(1:2) + x(3:4); % Top half: sums
x(3:4) = x(1:2) - 2 * x(3:4); % Bottom half: differences
% Twiddle factor for stage 2
W_N2 = exp(-2j * pi * (0:N/4-1) / N);
% Stage 2: Twiddle factor multiplication for bottom half
x(3) = x(3) * W_N2(1);
x(4) = x(4) * W_N2(1);
% Stage 3: Combine
X = zeros(1, N);
X(1) = x(1) + x(2);
X(2) = x(1) - x(2);
X(3) = x(3) + x(4);
X(4) = x(3) - x(4);
% Extract real and imaginary parts
re_out = real(X);
im_out = imag(X);
% Display the results
disp('Output Real Part:');
disp(re_out);
disp('Output Imaginary Part:');
Input

DIF-FFT for N = 4
Enter the input sequence (real and imaginary parts):
Real part at index 0: 1
Imaginary part at index 0: 0
Real part at index 1: 2
Imaginary part at index 1: 0
Real part at index 2: 3
Imaginary part at index 2: 0
Real part at index 3: 4
Imaginary part at index 3: 0
Output Real Part:
10 -2 -4 0
Output Imaginary Part:
0 0 0 0
disp(im_out);
% Plot results
figure;
subplot(2, 1, 1);
stem(0:N-1, re_out, 'r', 'LineWidth', 1.5);
xlabel('Frequency Index');
ylabel('Amplitude');
title('Output Real Part');
grid on;
subplot(2, 1, 2);
stem(0:N-1, im_out, 'b', 'LineWidth', 1.5);
xlabel('Frequency Index');
ylabel('Amplitude');
title('Output Imaginary Part');
grid on;
Source Code : DIT-FFT
clc;
clear;
close all;
% Length of the sequence
N = 4;
disp('DIT-FFT for N = 4');
disp('Enter the input sequence (real and imaginary parts):');
% Input sequence
re = zeros(1, N); % Real part
im = zeros(1, N); % Imaginary part
for i = 1:N
re(i) = input(['Real part at index ', num2str(i-1), ': ']);
im(i) = input(['Imaginary part at index ', num2str(i-1), ': ']);
end
% Combine real and imaginary parts into a complex sequence
x = re + 1j * im;
% Twiddle factors
W_N4 = exp(-2j * pi * (0:N/2-1) / N); % Twiddle factors for N=4
% Stage 1: Divide into even and odd
x_even = x(1:2:end); % [x0, x2]
x_odd = x(2:2:end); % [x1, x3]
% Apply butterfly operation for stage 1
x_even_out = x_even + x_odd; % Top half: sums
x_odd_out = x_even - x_odd; % Bottom half: differences
% Stage 2: Apply twiddle factors to the odd part
x_odd_out(1) = x_odd_out(1) * W_N4(1); % W0
x_odd_out(2) = x_odd_out(2) * W_N4(2); % W1
% Stage 3: Final output computation
X = zeros(1, N);
X(1) = x_even_out(1) + x_even_out(2);
X(2) = x_even_out(1) - x_even_out(2);
X(3) = x_odd_out(1) + x_odd_out(2);
X(4) = x_odd_out(1) - x_odd_out(2);
% Extract real and imaginary parts of the FFT result
re_out = real(X);
im_out = imag(X);
% Display results
Input
DIT-FFT for N = 4
Enter the input sequence (real and imaginary parts):
Real part at index 0: 1
Imaginary part at index 0: 0
Real part at index 1: 2
Imaginary part at index 1: 0
Real part at index 2: 3
Imaginary part at index 2: 0
Real part at index 3: 4
Imaginary part at index 3: 0

Output Real Part:


10.0000 -4.0000 -1.0000 -1.0000
Output Imaginary Part:
0 0 1 -1
disp('Output Real Part:');
disp(re_out);
disp('Output Imaginary Part:');
disp(im_out);
% Plot results
figure;
subplot(2, 1, 1);
stem(0:N-1, re_out, 'r', 'LineWidth', 1.5);
xlabel('Frequency Index');
ylabel('Amplitude');
title('Output Real Part');
grid on;
subplot(2, 1, 2);
stem(0:N-1, im_out, 'b', 'LineWidth', 1.5);
xlabel('Frequency Index');
ylabel('Amplitude');
title('Output Imaginary Part');
grid on;
SOURCE CODE :DIF and DIT-FFT
clc;
clear;
close all;
% Length of the sequence
N = 4;
disp('DIF and DIT FFT for N = 4');
disp('Enter the input sequence (real and imaginary parts):');
% Input sequence
re = zeros(1, N); % Real part
im = zeros(1, N); % Imaginary part
for i = 1:N
re(i) = input(['Real part at index ', num2str(i-1), ': ']);
im(i) = input(['Imaginary part at index ', num2str(i-1), ': ']);
end
% Combine real and imaginary parts into a complex sequence
x = re + 1j * im;
% =============================================================
% DIF-FFT Implementation
% =============================================================

% Twiddle factors for DIF


W_N4_DIF = exp(-2j * pi * (0:N/2-1) / N);
% Stage 1: Combine halves
dif_stage1 = x;
dif_stage1(1:2) = x(1:2) + x(3:4); % Top half: sums
dif_stage1(3:4) = x(1:2) - x(3:4); % Bottom half: differences
% Stage 2: Twiddle factors
dif_stage1(3) = dif_stage1(3) * W_N4_DIF(1);
dif_stage1(4) = dif_stage1(4) * W_N4_DIF(2);
% Stage 3: Final butterfly
dif_output = zeros(1, N);
dif_output(1) = dif_stage1(1) + dif_stage1(2);
dif_output(2) = dif_stage1(1) - dif_stage1(2);
dif_output(3) = dif_stage1(3) + dif_stage1(4);
dif_output(4) = dif_stage1(3) - dif_stage1(4);
% =============================================================
% DIT-FFT Implementation
% =============================================================

% Twiddle factors for DIT


W_N4_DIT = exp(-2j * pi * (0:N/2-1) / N);
% Stage 1: Split into even and odd
x_even = x(1:2:end); % Even-indexed elements
x_odd = x(2:2:end); % Odd-indexed elements
% Combine even and odd with butterfly
dit_stage1_even = x_even + x_odd; % Top half: sums
dit_stage1_odd = x_even - x_odd; % Bottom half: differences
% Apply twiddle factors
dit_stage1_odd(1) = dit_stage1_odd(1) * W_N4_DIT(1);
dit_stage1_odd(2) = dit_stage1_odd(2) * W_N4_DIT(2);
% Final butterfly for DIT
dit_output = zeros(1, N);
dit_output(1) = dit_stage1_even(1) + dit_stage1_even(2);
dit_output(2) = dit_stage1_even(1) - dit_stage1_even(2);
dit_output(3) = dit_stage1_odd(1) + dit_stage1_odd(2);
dit_output(4) = dit_stage1_odd(1) - dit_stage1_odd(2);

% =============================================================
% Output Results
% =============================================================

% Display Results
disp('DIF-FFT Output (Real and Imaginary Parts):');
disp(real(dif_output));
disp(imag(dif_output));
disp('DIT-FFT Output (Real and Imaginary Parts):');
disp(real(dit_output));
disp(imag(dit_output));
% Plot Results
figure;
% DIF-FFT Real Part
subplot(2, 2, 1);
DIF and DIT FFT for N = 4
Enter the input sequence (real and imaginary parts):
Real part at index 0: 1
Imaginary part at index 0: 0
Real part at index 1: 2
Imaginary part at index 1: 0
Real part at index 2: 3
Imaginary part at index 2: 0
Real part at index 3: 4
Imaginary part at index 3: 0
DIF-FFT Output (Real and Imaginary Parts):
10.0000 -2.0000 -2.0000 -2.0000
0 0 2 -2
DIT-FFT Output (Real and Imaginary Parts):
10.0000 -4.0000 -1.0000 -1.0000
0 0 1 -1
stem(0:N-1, real(dif_output), 'r', 'LineWidth', 1.5);
xlabel('Frequency Index');
ylabel('Amplitude');
title('DIF-FFT Real Part');
grid on;
% DIF-FFT Imaginary Part
subplot(2, 2, 2);
stem(0:N-1, imag(dif_output), 'b', 'LineWidth', 1.5);
xlabel('Frequency Index');
ylabel('Amplitude');
title('DIF-FFT Imaginary Part');
grid on;
% DIT-FFT Real Part
subplot(2, 2, 3);
stem(0:N-1, real(dit_output), 'r', 'LineWidth', 1.5);
xlabel('Frequency Index');
ylabel('Amplitude');
title('DIT-FFT Real Part');
grid on;
% DIT-FFT Imaginary Part
subplot(2, 2, 4);
stem(0:N-1, imag(dit_output), 'b', 'LineWidth', 1.5);
xlabel('Frequency Index');
ylabel('Amplitude');
title('DIT-FFT Imaginary Part');
grid on;

RESULT:
The program for Fast Fourier Transform using DIT-FFT and DIF-FFT. are performed by
using MATLAB script and the program results are verified by manual calculation.
VIVA QUESTIONS:

1. What is FFT?
FFT (Fast Fourier Transform) is an efficient algorithm to compute the Discrete Fourier Transform (DFT)
and its inverse. Instead of requiring O(N2) computations like DFT, FFT reduces it to O(NlogN)

2. What is the need for FFT over DFT?


DFT requires N2 multiplications and additions for N points, which is computationally expensive. FFT
reduces the complexity to NlogN , making it suitable for real-time and large data applications like signal
processing, image analysis, and communication systems.

3. What is the difference between DIT-FFT and DIF-FFT?


• DIT-FFT (Decimation in Time): Splits the input sequence into even and odd indexed samples and
performs butterflies stage by stage.
• DIF-FFT (Decimation in Frequency): Splits the output sequence into smaller parts, computing
butterflies directly on the time-domain sequence before applying twiddle factors.

4. What are butterflies in FFT?


A butterfly is the basic computation unit in FFT. It combines two complex numbers (inputs) into two
outputs using addition, subtraction, and twiddle factor multiplication. The structure of connections
resembles a butterfly’s wings, hence the name.

5. What are twiddle factors in FFT?


Twiddle factors are the complex exponential terms used in FFT:

They are responsible for introducing the frequency-dependent phase shifts in FFT.

6. What is the computational complexity of FFT?


• DFT: O(N2)
• FFT: O(NlogN)
Thus, FFT is much faster, especially for large NNN.

7. What is the input size restriction for FFT algorithms?


In radix-2 FFT (DIT/DIF), the input sequence length NNN must be a power of 2 (N=2m). For other
lengths, zero-padding is used to make the size a power of 2.

8. What is the main difference in implementation between DIF-FFT and DIT-FFT?


• DIT-FFT: Bit-reversal occurs at the input side (reordering input sequence).
• DIF-FFT: Bit-reversal occurs at the output side (reordering output sequence).

9. Which FFT algorithm is better: DIF or DIT?


Both DIF and DIT are mathematically equivalent and have the same computational complexity. The
choice depends on hardware/software implementation requirements. DIF is often preferred for in-place
computation, while DIT is easier to understand conceptually.

10. What are the applications of FFT?


• Spectrum analysis
• Image and audio compression (JPEG, MP3)
• Digital communications (OFDM, channel estimation)
AIM:
To write a MATLAB Script to design a low pass FIR filter using Window Method for the given
specifications.

COMPONENTS REQUIRED:
PC, MATLAB software

ALGORITHM/PROCEDURE:
1. Click on the MATLAB icon on the desktop (or go to Start – All
Programs and click on MATLAB) to get into the Command
Window.
2. Type ‘edit’ in the MATLAB prompt ‘>>’ that appears in the Command window.
3. Write the program in the ‘Edit’ window and save it in ‘M-file’.
4. Run the program.
5. Enter the input in the Command Window.
6. The result is displayed in the Command window and the graphical
output is displayed in the Figure Window.

SOURCE CODE :1
clc;
clear all;
close all;
N=input('Order of the filter:');
wc=input('Cut off frequency:');

h=fir1(N,wc/pi,rect
win(N+1));
freqz(h);
title('FIR Filter - Rectangular Window');

h=fir1(N,wc/pi,tria
ng(N+1)); figure(2)
freqz(h);
title('FIR Filter - Triangular Window');

h=fir1(N,wc/pi,haming(N+1));
OUTPUT: 1

Order of the filter:51


Cut off frequency:0.4
figure(3);
freqz(h);
title('FIR Filter - Hamming Window');

h=fir1(N,wc/pi,han
ning(N+1));
figure(4)
freqz(h);
title('FIR Filter - Hanning Window');

h=fir1(N,wc/pi,blac
kman(N+1));
figure(5)
freqz(h);
title('FIR Filter - Blackman Window');

SOURCE CODE :2
clc;
clear all;
close all;
N=input('Order of the filter:');
wc=input('Cut off frequency:');
b=fir1(N,wc/pi,rectwin(N+1));
[H,w]=freqz(b,1,512);
%frequency response
plot(w/pi,a
bs(H),'k');
hold on
b=fir1(N,wc/pi,triang(N+1));
[H,w]=freqz(b,1,512);
%frequency response
plot(w/pi,abs(H),'--k');
hold on
b=fir1(N,wc/pi,hamming(N+1))
; [H,w]=freqz(b,1,512);
%frequency response
plot(w/pi,abs(H),':k');
hold on
b=fir1(N,wc/pi,hanning(N+1));
[H,w]=freqz(b,1,512);
%frequency response

plot(w/pi,abs(H),'-.k');
hold on
b=fir1(N,wc/pi,blackman(N+1));
[H,w]=freqz(b,1,512); %frequency response
plot(w/pi,abs(H),'.b');
hold on

xlabel('Normalized
Frequency');
ylabel('Magnitude');
legend('Rectangular','Triangular(Barlett)','Hamming','Hanning','Blackman','Locatio
n','Best');
title('Gibbs Phenomenon');

a=findobj(gcf); % get the handles associated with the current figure

allaxes=findall(a,'Type','axes');
alllines=findall(a,'Type','line');
alltext=findall(a,'Type','text');

set(allaxes,'FontName','Times New
Roaman','FontWeight','Bold','LineWidth',1,... 'FontSize',12);
set(alllines,'Linewidth',1);
set(alltext,'FontName','Times New Roaman','FontWeight','Bold','FontSize',12);
OUTPUT: 2
Order of the filter:51
Cut off frequency:0.4
RESULT:
The given FIR low pass filter was designed using Window method and manually verified
filter co-efficient of the filters.
VIVA QUESTIONS:

1. What is an FIR filter?


FIR (Finite Impulse Response) filter is a digital filter whose impulse response settles to zero in a
finite duration. It is always stable and has linear phase properties.

2. What are window functions in FIR filter design?


Window functions are used to truncate the infinite impulse response of an ideal filter to a finite
length. Examples: Rectangular, Hamming, Hanning, Triangular, Blackman.

3. What is Gibbs Phenomenon?


When truncating an ideal filter using a finite-length window, oscillations occur near the cutoff
frequency in the frequency response. This is called Gibbs phenomenon.

4. Which window gives the best stopband attenuation?


Blackman window gives the best stopband attenuation but with a wider transition band.
Rectangular gives the narrowest transition but high ripples.

5. Why is Hamming window widely used in FIR filter design?


Because it provides a good trade-off between main lobe width (transition band) and side lobe
attenuation (stopband ripple).

6. What are the advantages of FIR filters over IIR filters?


• FIR filters are always stable.
• They can be designed to have exact linear phase.
• They are easier to implement on hardware.

7. What inputs are given in the MATLAB code for FIR filter design?
The order of the filter (N) and cutoff frequency (wc) are given as inputs.

8. What is the effect of increasing the filter order (N)?


Increasing order improves frequency selectivity (narrow transition band) but increases
computation and delay.

9. In the code, what does freqz(h) do?


It computes and plots the frequency response of the designed FIR filter.

10. Why is normalization with π used in cutoff frequency?


Because MATLAB uses normalized frequency (0 to π rad/sample) instead of absolute frequency
in Hz.
AIM:
To write a MATLAB Script to design a low pass FIR filter using Frequency Sampling Method
for the given specifications.

COMPONENTS REQUIRED:
PC, MATLAB software

SOURCE CODE:
%30th order LPF using Frequency Sampling method
clc;
clear all; close all;
Fs=1000; %sampling frequency Fn=Fs/2;
%Nyquist frequency f=[ 0 400 400 500]/Fn;
m=[1 1 0 0];
h=fir2(30,f,m); [H,w]=freqz(h,1,256);
plot(f*Fn,m,'-o') hold on
plot (Fn*w/pi, abs(H),'k');grid hold on
legend('Ideal', 'Designed')
xlabel('Frequency (Hz)')
ylabel('Magnitude') title('FIR filter')
%optional code
M=63; Wp=0.5*pi;
%the number of samples and the passband cutoff frequency
m=0:(M+1)/2; Wm=2*pi*m./(M+1);
%the sampling points and the stopband cutoff frequency
mtr=floor(Wp*(M+1)/(2*pi))+2;
%round to negative part,i.e.floor(3.5)=3;floor(-3.2)=-4
Ad=[Wm<=Wp];
Ad(mtr)=0.38;
Hd=Ad.*exp(-j*0.5*M*Wm);
%define frequency-domain sampling vector H(k)
Hd=[Hd conj(fliplr(Hd(2:(M+1)/2)))];
%fliplr is to realize the fliplr of matrix and conj
h=real(ifft(Hd));
% h(n)=IDFT[H(k)
w=linspace(0,pi,1000);
%get1000 row vectors between 0 andpi
H=freqz(h,[1],w);
%the amplitude -frequency characteristic diagram of the filter figure(1)
plot(w/pi,20*log10(abs(H)));
%parameters are respectively the normalized frequency and amplitude
xlabel('the normailzed frequency');
ylabel('gian/dB');
title('The gain response of lowpass filter');
axis([0 1 -50 0.5]); f1=100;f2=300;f3=700;
fs=2000;
%the frequencies of sines signal that needs filtered and the sample frequency
figure(2);
subplot(211)
t=0:1/fs:0.25;%define the time domain and steplength
s=sin(2*pi*f1*t)+sin(2*pi*f2*t)+sin(2*pi*f3*t);
%signal before filtering plot(t,s);%plot the diagram before filtering
xlabel('time/s'); ylabel('amplitude');
title('Time-domain diagram before filtering'); subplot(212)
Fs=fft(s,512); AFs=abs(Fs);
%transform to the frequency domain f=(0:255)*fs/512;%frequency sampling
plot(f,AFs(1:256));
%plot the frequency domain diagram before filtering xlabel('frequency/Hz');
ylabel('amplitude');
title('Frequency-domain diagram before filtering'); figure(3)
sf=filter(h,1,s);
%use function filter subplot(211)
plot(t,sf)
%plot the diagram after filtering
xlabel('time/s');
ylabel('amplitude');
title('Time-domain diagram after filtering');
axis([0.2 0.25 -2 2]);%set the range of image coordinates subplot(212)
Fsf=fft(sf,512); AFsf=abs(Fsf);%frequency-domain and the amplitude diagram
f=(0:255)*fs/512;%frequency sampling
plot(f,AFsf(1:256))%plot the frequency domain diagram before filtering
xlabel('frequency/Hz');
ylabel('amplitude');
title('Frequency-domain diagram after filtering');

RESULT:
For the given specifications low pass filter was designed using Frequency Sampling Method and
manually verified filter co-efficient of the filters.
VIVA QUESTIONS:
1. What is the fundamental principle of frequency sampling?

Defining filter response at discrete frequencies and using IDFT.

2. Why use ifft?

To convert frequency samples to the impulse response.

3. What is the filter's order (N)?

It's the number of frequency samples used.

4. Why must Hk be symmetric?

To get a real-valued impulse response.

5. What is the main drawback?

Significant ripple between the sampled frequencies.

6. Why is fftshift used?

To make the filter's impulse response causal.

7. How does a higher order affect the filter?

Steeper transition band, but more complexity and ripple.

8. What determines the cutoff frequency in the script?

The k_cutoff index in the Hk vector.

9. Why is an odd order often chosen?

To achieve linear phase response.

10. What is the output of the script's ifft function?

The filter's impulse response coefficients.


AIM:
To write a MATLAB Script to design Butterworth and Chebyshev low pass filters using Bilinear
Transformation, Impulse Invariant Transformation.

COMPONENTS REQUIRED:
PC, MATLAB software

BILINEAR TRANSFORMATION:
DESIGN STEPS:
i. From the given specifications, Find pre-warped analog frequencies using

ii. Using the analog frequencies, find H(s) of the analog filter
iii. Substitute

in the H(s) of Step:2

IMPULSE INVARIANT TRANSFORMATION:


DESIGN STEPS:
i. Find the analog frequency using
=w/ T
i. Find the transfer function of analog filter Ha(s)
ii. Express the analog filter transfer function as a sum of single pole filters
iii. Compute H(Z) of digital filter using the formula

ALGORITHM/PROCEDURE:
i. Calculate the attenuation in dB for the given design parameters
ii. Design the analog counterpart
iii. Using Impulse Invariant /Bilinear transformation design the digital filter
iv. Display the transfer function. Plot the magnitude response and phase response
/ Butterworth Lowpass Impulse invariant method

Command window:

OUTPUT:
SOURCE CODE:
/ Butterworth Lowpass Impulse invariant method
clc;
clear all;
close all;
warning off;
% Design of IIR Filters
%% Filter Specifications
% Input Wp,Ws,Sp,Ss,T
% T=1,bothe ripple gains should be b/w .1 to .3
disp(' Butterworth Lowpass filter using Impulse invariant method ');

T=input('Enter the Sampling Frequency in rad/sec: ');


Sp=input('Enter the Pass-band Ripple Gain: ');
Wp=input('Enter the Pass-band Edge Frequency in rad/sec: ');
Ss=input('Enter the Stop-band Ripple Gain: ');
Ws=input('Enter the Stop-band Edge Frequency in rad/sec: ');

% Calculation of
ohmp,ohms,Ap,As
Ap=abs(20*log10(1-
Sp));
As=abs(20*log10(Ss));

ohmp=Wp/T; ohms=Ws/T;
% Butterworth Filter
% Calculation of order and cutoff freq. for the above filter specs.
[n,Wc]=buttord(ohmp,ohms,Ap,As,'s');

% Low Pass Filtering


[b,a]=butter(n,Wc,'low','s');
[bz,az] = impinvar(b,a,T);
tf(bz,az,T);
O=linspace(-pi,pi,50);
% O is the freq. axis
H=freqz(bz,az,O);

% Magnitude Response
Hm=20*log10(abs(H));
subplot(2,1,1);
semilogx(O,Hm);
xlabel('Frequency');
ylabel('Magnitude');
title('Magnitude Response of IIR Filter using Impulse Invariant Method');
Butterworth Lowpass Bilinear Transformation Method

Command Window :

OUTPUT:
% Phase Response
Ha=angle(H);
subplot(2,1,2);
semilogx(O,Ha);
abel('Frequency');
ylabel('Phase');
title('Phase Response of IIR Filter using Impulse Invariant Method');

/ Butterworth Lowpass Bilinear Transformation Method


clc;
clear all;
close all;
warning off;
% Design of IIR Filters
%% Filter Specifications
% Input Wp,Ws,Sp,Ss,T
% T=1,both the ripple gains should have band width( .1 to .3)
disp(' Butterworth Lowpass filter using Bilnear transformation method ');

T=input('Enter the Sampling Frequency in rad/sec: ');


Sp=input('Enter the Pass-band Ripple Gain: ');
Wp=input('Enter the Pass-band Edge Frequency in rad/sec: ');
Ss=input('Enter the Stop-band Ripple Gain: ');
Ws=input('Enter the Stop-band Edge Frequency in rad/sec: ');

% Calculation of ohmp,ohms,Ap,As
Ap=abs(20*log10(1-Sp));
As=abs(20*log10(Ss));
ohmp=Wp/T;
ohms=Ws/T;
% Butterworth Filter
% Calculation of order and cutoff freq. for the above filter specs.
[n,Wc]=buttord(ohmp,ohms,Ap,As,'s');

% Low Pass Filtering [b,a]=butter(n,Wc,'low','s');


[bz,az] = bilinear(b,a,1/T);
tf(bz,az,T);
O=linspace(-pi,pi,50);
% O is the freq. axis
H=freqz(bz,az,O);

% Magnitude Response
Hm=20*log10(abs(H));
subplot(2,1,1);
semilogx(O,Hm);
Chebyshev Lowpass Impulse invariant method

Command Window:

OUTPUT:
xlabel('Frequency');
ylabel('Magnitude');
title('Magnitude Response of IIR Filter using Bilinear Transformation Method');

% Phase Response
Ha=angle(H);
subplot(2,1,2);
semilogx(O,Ha);
xlabel('Frequency');
ylabel('Phase');
title('Phase Response of IIR Filter using Bilinear Transformation Method');

/ Chebyshev Lowpass Impulse invariant method

clc;
clear all;
close all;
warning off;
% Design of IIR Filters
%% Filter Specifications
% Input Wp,Ws,Sp,Ss,T
% T=1,bothe ripple gains should be b/w .1 to .3
disp(' Chebyshev Lowpass filter using Impulse invariant method ');

T=input('Enter the Sampling Frequency in rad/sec: ');


Sp=input('Enter the Pass-band Ripple Gain: ');
Wp=input('Enter the Pass-band Edge Frequency in rad/sec: ');
Ss=input('Enter the Stop-band Ripple Gain: ');
Ws=input('Enter the Stop-band Edge Frequency in rad/sec: ');

% Calculation of ohmp,ohms,Ap,As
Ap=abs(20*log10(1-Sp)); As=abs(20*log10(Ss));
ohmp=Wp/T;
ohms=Ws/T;
% Chebyshev Filter
% Calculation of order and cutoff freq. for the above filter specs.
[n,Wc2]=cheb1ord(ohmp,ohms,Ap,As,'s')

% Low Pass Filtering


[b,a]=cheby1(n,Ap,Wc2,'low','s');
[bz,az] = impinvar(b,a,T); tf(bz,az,T);
O=linspace(-pi,pi,50);
% O is the freq. axis
H=freqz(bz,az,O);
/Chebyshev Lowpass Bilinear Transformation Method

Command Window:

OUTPUT:
% Magnitude Response
Hm=20*log10(abs(H));
subplot(2,1,1);
semilogx(O,Hm);
xlabel('Frequency');
ylabel('Magnitude');
title('Magnitude Response of IIR Filter using Impulse Invariant Method');
% Phase Response
Ha=angle(H);
xlabel('Frequency');
ylabel('Phase');
title('Phase Response of IIR Filter using Impulse Invariant Method');

/Chebyshev Lowpass Bilinear Transformation Method

clc;
clear all;
close all;
warning off;
% Design of IIR Filters
%% Filter Specifications
% Input Wp,Ws,Sp,Ss,T
% T=1,bothe ripple gains should be b/w .1 to .3
disp(' Chebyshev Lowpass filter using Bilnear transformation method ');

T=input('Enter the Sampling Frequency in rad/sec: ');


Sp=input('Enter the Pass-band Ripple Gain: ');
Wp=input('Enter the Pass-band Edge Frequency in rad/sec: ');
Ss=input('Enter the Stop-band Ripple Gain: ');
Ws=input('Enter the Stop-band Edge Frequency in rad/sec: ');

% Calculation of ohmp,ohms,Ap,As
Ap=abs(20*log10(1-Sp));
As=abs(20*log10(Ss)); ohmp=Wp/T;
ohms=Ws/T;
% Chebyshev Filter
% Calculation of order and cutoff freq. for the above filter specs.
[n,Wc2]=cheb1ord(ohmp,ohms,Ap,As,'s')

% Low Pass Filtering


[b,a]=cheby1(n,Ap,Wc2,'low','s');
[bz,az] = bilinear(b,a,1/T); tf(bz,az,T);
O=linspace(-pi,pi,50);
% O is the freq. axis
H=freqz(bz,az,O);

% Magnitude Response
Hm=20*log10(abs(H));
subplot(2,1,1);
semilogx(O,Hm);
xlabel('Frequency');
ylabel('Magnitude');
title('Magnitude Response of IIR Filter using Bilinear Transformation Method');
% Phase Response
Ha=angle(H);
subplot(2,1,2);
semilogx(O,Ha);
xlabel('Frequency');
ylabel('Phase');
title('Phase Response of IIR Filter using Bilinear Transformation Method');

RESULT:
Butterworth and Chebyshev Lowpass filters were designed using Bilinear and Impulse Invariant
transformations, and manually verified the order, cut off frequency and filter co-efficient of the
filters.
VIVA QUESTIONS:

1. What is the primary purpose of Bilinear Transformation?


To convert an analog filter design into a digital IIR filter.
2. What is "frequency warping" in Bilinear Transformation?
A non-linear mapping of the frequency axis, where analog frequencies are
compressed at higher values.
3. Why is "pre-warping" necessary with Bilinear Transformation?
To compensate for frequency warping and ensure the digital filter meets
specifications at critical frequencies.
4. What is the core principle of Impulse Invariant Transformation?
The digital filter's impulse response is a sampled version of the analog
filter's.
5. What is the main disadvantage of Impulse Invariant Transformation?
It introduces aliasing, which can distort the frequency response.
6. Which transformation method preserves filter stability?
Both the Bilinear and Impulse Invariant transformations.
7. Which filter type has a maximally flat passband?
Butterworth filters.
8. What distinguishes a Chebyshev filter's passband?
It has equiripple (ripples of equal amplitude) in the passband.
9. Which transformation is better for low-pass filters?
Bilinear Transformation, as it avoids aliasing.
10. Can both methods be used for all filter types?
No. Impulse Invariant is best for band-limited filters (e.g., bandpass),
while Bilinear is more versatile.
AIM:
To write a MATLAB Script to design multirate Signal Processing.

COMPONENTS REQUIRED:
PC, MATLAB software

A Simple Decimation System:

A Simple Interpolation System:


SOURCE CODE:
% To design a lowpass filter FIR filter having 128 coefficients and a cut of frequency of

clc;
clear all;
close all;
h = fir1(128-1,1/3); % Input cutoff as 2*fc, where fc = wc/(2pi) freqz(h,1,512,1)
print -tiff -depsc multi3.eps

%Downsample the spectrum signal by a factor of 2


n = 0:1024;
x = 1/4*sinc(1/4*(n-512)).^2; y = downsample(x,2);
f = -1:1/512:1;
X = freqz(x,1,2*pi*f);
Y = freqz(y,1,2*pi*f);
plot(f,abs(X))
subplot(211)
plot(f,abs(X))
subplot(212)
plot(f,abs(Y))
print -tiff -depsc multi4.eps
% use the same signal except with M=3. First without the prefilter, and then
include it to avoid aliasing.
n = 0:1024;
x = 1/4*sinc(1/4*(n-512)).^2;
xf = filter(h,1,x);
yf = downsample(xf,3);
ynf = downsample(x,3);
X = freqz(x,1,2*pi*f);
Xf = freqz(xf,1,2*pi*f);
Yf = freqz(yf,1,2*pi*f);
Ynf = freqz(ynf,1,2*pi*f);
subplot(411)
plot(f,abs(X))
subplot(412)
plot(f,abs(Ynf))
subplot(413)
plot(f,abs(Xf))
subplot(414)
plot(f,abs(Yf))
print -tiff -depsc multi5.eps
%Upsample the spectrum signal by a factor of 3

clear all, close all;


clc; n = 0:1024;
f = -1:1/512:1;
x = 1/4*sinc(1/4*(n-512)).^2;
y = upsample(x,3);
X = freqz(x,1,2*pi*f);
Y = freqz(y,1,2*pi*f);
h = fir1(128-1, 1/3);
yf = filter(h,1,y);
Yf = freqz(yf,1,2*pi*f);
subplot(311)
plot(f,abs(X))
subplot(312)
plot(f,abs(Y))
subplot(313) plot(f,abs(Yf))
print -tiff -depsc multi6.eps

RESULT:

The multirate LPF filters (Interpolator and Decimator) are performed by using MATLAB script
and the program results are verified by manual calculation.
VIVA QUESTIONS:
1. What is sampling in digital signal processing?
Sampling is the process of converting a continuous-time signal into a discrete-time signal by
taking values at regular intervals.

2. Define Nyquist rate and Nyquist theorem.


Nyquist rate = 2 × maximum frequency of the signal.
Nyquist theorem: To avoid aliasing, the sampling rate must be at least twice the highest signal frequency.

3. What is aliasing, and how can it be avoided?


Aliasing is the overlap of signal spectra due to undersampling. It is avoided by sampling at or
above the Nyquist rate or using a low-pass filter before sampling.

4. Explain the concept of bandwidth in signals.


Bandwidth is the range of frequencies present in a signal, typically from 0 to the highest
frequency component.

5. What is the role of a low-pass filter in sampling rate conversion?


It removes unwanted high-frequency components to prevent aliasing during downsampling and
eliminates spectral images during upsampling.

6. What is downsampling, and what happens to the signal when we downsample it?
Downsampling reduces the sampling rate by keeping every M-th sample. It compresses the
signal in the time domain but causes spectrum expansion and possible aliasing.

7. How do you calculate the new sampling frequency after downsampling?


New sampling frequency = Original sampling frequency ÷ Downsampling factor (M).

8. Why is a prefilter used before downsampling?


To limit the bandwidth below half the new sampling rate, avoiding aliasing.

9.What will happen if you downsample without using a prefilter?


High-frequency components fold back into the baseband, causing aliasing and distortion.

10. Explain the spectrum changes when downsampling is performed.


The spectrum gets compressed and repeats periodically due to the lower sampling rate.

You might also like