dsp lab pdf
dsp lab pdf
clc
clear all
close all
% a) LINEARITY PROPERTY
x1 = input( ' Enter the sequence x1[n] = ' );
x2 = input( ' Enter the sequence x2[n] = ' );
N1 = length(x1);
N2 = length(x2);
if ( N1 > N2 )
x2 = [ x2, zeros( 1, N1 - N2 ) ];
else
x1 = [ x1, zeros( 1, N2 - N1 ) ];
end
N = max( N1, N2 );
a1 = input('arbitrary constant value a1 = ');
a2 = input('arbitrary constant value a2 = ');
LHS = fft( a1*x1 + a2*x2 , N );
RHS = a1 * fft( x1, N ) + a2 * fft( x2, N );
disp( LHS )
disp( RHS )
1.Linearity properties:
Enter the sequence x1[n] = [1,0.54,-0.41,-0.98]
Enter the sequence x2[n] = [0,0.84,0.9,0.14]
arbitrary constant value a1 = 2
arbitrary constant value a2 = 3
5.9400 + 0.0000i 0.1200 - 5.1400i 1.8200 + 0.0000i 0.1200 + 5.1400i
X= 0 0 4 0
temp = 1 -1 1 -1
X1 = 0 0 4 0
X2 =
X= 2 0 2 0
Y=
2.0000 - 0.0000i 0.0000 + 0.0000i
X freq_shift = 2 0 2 0
X=2 0 2 0
Y=
2.0000 - 0.0000i 0.0000 + 0.0000i
Xfreq_shift = 2 0 2 0
4.parseval’s property
LHS=14
RHS=14
LHS=RHS
PROGRAM:
HAMMING WINDOW:
clc
clear all
close all
fc = input('Enter the cut off frequency in Hz:');
Fs = input('Enter the sampling frequency in Hz:');
N= input('Enter the order of the filter N=');
wc= ((2*pi*fc)/Fs);
window = hamming(N+1);
hn = fir1(N,wc/pi, window);
w=0:0.01:pi;
Hw= freqz(hn,1 ,w);
display('The LPF filter coefficients are');
display(hn);
subplot(2,2,1);
plot(w/pi,20*log(abs(Hw)));
grid;
xlabel('NormaIised frequency');
ylabel('Magnitude');
title( 'Magnitude response of low pass FIR filter with Hamming window');
subplot(2,2,2);
plot(w/pi,abs(Hw));
grid;
xlabel('NormaIised frequency');
ylabel('Phase');
title('Phase response of low pass FIR filter with Hamming window');
%FIR HPF
window =hamming(N+2);
hn = fir1(N,wc/pi, 'high',window);
w=0:0.01:pi;
Hw= freqz(hn,1 ,w);
display('The HPF filter coefficients are');
display(hn);
subplot(2,2,3);
plot(w/pi,20*log10(abs(Hw)));
grid;
xlabel('Normalised frequency');
ylabel('Magnitude');
title(']Magnitude response of high pass FIR filter with Hamming window');
subplot(2,2,4);
plot(w/pi,abs(Hw));
grid;
xlabel('NormaIised frequency');
ylabel('phase');
title('Phase response of high pass FIR filter with Hamming window');
-0.0013 0.0010
hn =
clc
clear all
close all
fc = input('Enter the cut off frequency in Hz:');
Fs = input('Enter the sampling frequency in Hz:');
N= input('Enter the order of the filter N=');
wc= ((2*pi*fc)/Fs);
window = hanning(N+1); % window = hanning(N+1) for Hanning window
hn = fir1(N,wc/pi, window);
w=0:0.01:pi;
Hw= freqz(hn,1 ,w);
display('The LPF filter coefficients are');
display(hn);
subplot(2,2,1);
plot(w/pi,20*log(abs(Hw)));
grid;
xlabel('NormaIised frequency');
ylabel('Magnitude');
title( 'Magnitude response of low pass FIR filter ');
subplot(2,2,2);
plot(w/pi,abs(Hw));
grid;
xlabel('NormaIised frequency');
ylabel('Phase');
title('Phase response of low pass FIR filter ');
%FIR HPF
window =hanning(N+2); %window = hanning(N+2) for Hanning window
hn = fir1(N,wc/pi, 'high',window);
w=0:0.01:pi;
Hw= freqz(hn,1 ,w);
display('The HPF filter coefficients are');
display(hn);
subplot(2,2,3);
plot(w/pi,20*log10(abs(Hw)));
grid;
xlabel('Normalised frequency');
ylabel('Magnitude');
title('Magnitude response of high pass FIR filter ');
subplot(2,2,4);
plot(w/pi,abs(Hw));
grid;
xlabel('NormaIised frequency');
ylabel('phase');
title('Phase response of high pass FIR filter ');
subplot(2,2,1);
plot(w/pi,20*log(abs(Hw)));
grid;
xlabel('NormaIised frequency');
ylabel('Magnitude');
title( 'Magnitude response of low pass FIR filter ');
subplot(2,2,2);
plot(w/pi,abs(Hw));
grid;
xlabel('NormaIised frequency');
ylabel('Phase');
title('Phase response of low pass FIR filter ');
%FIR HPF
window =blackman(N+2); % window = blackman(N+1) for blackman window
hn = fir1(N,wc/pi, 'high',window);
w=0:0.01:pi;
Hw= freqz(hn,1 ,w);
display('The HPF filter coefficients are');
display(hn);
subplot(2,2,3);
plot(w/pi,20*log10(abs(Hw)));
grid;
xlabel('Normalised frequency');
ylabel('Magnitude');
title('Magnitude response of high pass FIR filter');
subplot(2,2,4);
plot(w/pi,abs(Hw));
grid;
xlabel('NormaIised frequency');
ylabel('phase');
title('Phase response of high pass FIR filter ');
hn =
-0.0001 0
hn =
0.0006 -0.0000 0
GRAPH
BLACKMAN WINDOW:
PROGRAM:
RECTANGULAR WINDOW:
clc
clear all
close all
fc = input('Enter the cut off frequency in Hz:');
Fs = input('Enter the sampling frequency in Hz:');
N= input('Enter the order of the filter N=');
wc= ((2*pi*fc)/Fs);
window = boxcar(N+1); % window = boxcar(N+1) for rectangular window
hn = fir1(N,wc/pi, window);
w=0:0.01:pi;
Hw= freqz(hn,1 ,w);
display('The LPF filter coefficients are');
display(hn);
subplot(2,2,1);
plot(w/pi,20*log(abs(Hw)));
grid;
xlabel('NormaIised frequency');
ylabel('Magnitude');
title( 'Magnitude response of low pass FIR filter ');
subplot(2,2,2);
plot(w/pi,abs(Hw));
grid;
xlabel('NormaIised frequency');
ylabel('Phase');
title('Phase response of low pass FIR filter ');
%FIR HPF
window =boxcar(N+1); % window = boxcar(N+1) for rectangular window
hn = fir1(N,wc/pi, 'high',window);
w=0:0.01:pi;
Hw= freqz(hn,1 ,w);
display('The HPF filter coefficients are');
display(hn);
subplot(2,2,3);
plot(w/pi,20*log10(abs(Hw)));
grid;
xlabel('Normalised frequency');
ylabel('Magnitude');
title('Magnitude response of high pass FIR filter');
subplot(2,2,4);
plot(w/pi,abs(Hw));
grid;
xlabel('NormaIised frequency');
ylabel('phase');
title('Phase response of high pass FIR filter');
hn =
-0.0142 0.0131
hn =
HLs =
4.198
---------------------
s^2 + 2.898 s + 4.198
a=
The transfer function of the digital Butterworth filten using bilinear transformation is
HLz =
b=
0 0.6754 0
a=
The transfer function of the digital Butterworth filter using impulse invaince method is
EXPECTED GRAPH
PROGRAM
clc
clear all
close all
Ap= input('Enter the passband attenuation in dB =');
Wp= input('Enter the passband edge frequency in rad/sec =');
As= input('Enter the stopband attenuation in dB =');
Ws= input('Enter the stopband edge frequency in rad/sec =');
Fs= input('Enter the sampling frequency =');
Ts= 1/Fs;
% To calculate order & cut-off frequency
[n, Wc] = buttord(Wp, Ws, Ap, As, 's');
disp( 'The order of the Butterworth filter is N= ')
disp(n);
disp('The cut- off frequency of the Butterworth filter is Wc = ');
disp(Wc);
% To obtain analog transfer function of butterworth filter
[num, den] = butter(n, Wc, 'high', 's');
disp('The transfer function of the analog Butterworth filter is H(s)= ');
Hhs = tf(num,den)
%To obtain system function in digital domain using bilinear transformation
[b,a] = bilinear(num,den,Fs)
disp( 'The transfer function of the digital Butterworth filter using bilinear transformation is');
Hhz = tf(b,a, Ts)
%To obtain system function in digital domain using impulse invariant %transformation
%[b,a] = impinvar(num,den,Fs)
%disp(*The transfer function of the digital Butterworth filter using impulse invaince method
is ');
%HLz = tf(b,a,Ts)
% To obtain frequency response
[Ha, Wa] = freqs(num, den, 1024);
[Hd, wd] = freqz(b, a, 1024,10 );
figure(1)
plot(Wa, 20*log10(abs(Ha)))
title('Magnitude Frequency Response of analog Butter worth Filter')
xlabel('W...>')
ylabel('20*log10|H(w)|')
title('Magnitude Frequency Response of digital Butter worth Filter')
figure (2)
plot (wd,20*log10(abs(Hd)))
xlabel('w--- >')
ylabel('20*log10|H(w)|')
title ('magnitude frequency response of digital butter worth filter ')
AFTER THE EXECUTION:
Enter the passband attenuation in dB =3.01
Enter the passband edge frequency in rad/sec =2
Enter the stopband attenuation in dB =15
Enter the stopband edge frequency in rad/sec =4.828
Enter the sampling frequency =1
The order of the Butterworth filter is N= 2
Hhs =
s^2
---------------------
s^2 + 2.902 s + 4.212
b=
a=
The transfer function of the digital Butterworth filter using bilinear transformation is
Hhz =
In this formula:
- y[n] is the output sequence (result of the circular convolution).
- x[n] is the first input sequence.
- h[n] is the second input sequence.
- k is the summation variable, and the summation is taken over all possible values of k.
- N is the length of the sequences x[n] and h[n].
The key difference between linear convolution and circular convolution is the use of modulo
N in the formula. Circular convolution assumes that the sequences x[n] and h[n] are periodic
with a period of N, and it wraps around when reaching the end of the sequence.
Circular convolution is often used in applications involving periodic signals, such as in digital
signal processing for circular buffers or in the context of cyclic or periodic phenomena.
To perform circular convolution efficiently, the Discrete Fourier Transform (DFT) and the
Circular Convolution Theorem can be used. The Circular Convolution Theorem states that
circular convolution in the time domain is equivalent to element-wise multiplication in the
frequency domain after taking the DFT of the sequences, followed by an inverse DFT to obtain
the result in the time domain. This approach is computationally more efficient for long
sequences.
LINEAR CONVOLUTION
Linear convolution is a mathematical operation used in signal processing and mathematics to
combine two sequences to produce a third sequence. The formula for linear convolution
involves summing the products of corresponding elements of the two input sequences as they
slide past each other. Here's the formula:
Given two sequences x[n] and h[n], the linear convolution y[n] is calculated as:
Where:
y[n] is the resulting sequence (output).
x[n] and h[n] are the input sequences.
k is the summation index, typically ranging from negative infinity to positive infinity but
practically limited to the available data.
denotes the multiplication.
In practice, since the sequences are often finite, you'll need to consider only a finite range of
values for k.
Linear convolution is used in various applications like digital signal processing, image
processing, and more, to process and filter signals or data