0% found this document useful (0 votes)
203 views

MATLAB DSP Programs: Raja Rajasakeran Venkat Peddigari Pete Bernardin

This MATLAB document contains code for implementing various digital signal processing (DSP) techniques, including: 1. Designing and analyzing bandpass and notch filters. 2. Applying different window functions (Kaiser, Hamming, etc.) and analyzing their effects. 3. Computing the discrete Fourier transform (DFT) and fast Fourier transform (FFT) of signals. 4. Implementing comb filters and analyzing their frequency responses. 5. Using the Welch method to estimate the power spectral density of a noisy signal. 6. Modeling resonators and analyzing their transfer functions.

Uploaded by

risil
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
203 views

MATLAB DSP Programs: Raja Rajasakeran Venkat Peddigari Pete Bernardin

This MATLAB document contains code for implementing various digital signal processing (DSP) techniques, including: 1. Designing and analyzing bandpass and notch filters. 2. Applying different window functions (Kaiser, Hamming, etc.) and analyzing their effects. 3. Computing the discrete Fourier transform (DFT) and fast Fourier transform (FFT) of signals. 4. Implementing comb filters and analyzing their frequency responses. 5. Using the Welch method to estimate the power spectral density of a noisy signal. 6. Modeling resonators and analyzing their transfer functions.

Uploaded by

risil
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 11

MATLAB DSP Programs

Raja Rajasakeran
Venkat Peddigari
Pete Bernardin
Bandpass Filter

close all;
clear all;
r1 = 0.9;
r2 = 0.88;
r3=0.9;
theta1 = pi/5;
theta2 = 3*pi/10;
theta3=4*pi/10;
p1 = r1*cos(theta1) + i*r1*sin(theta1);
p2 = r1*cos(theta2) + i*r2*sin(theta2);
p3 = r3*cos(theta3) + i*r3*sin(theta3);
p2 = r2*cos(theta2) + i*r2*sin(theta2);
!aroots = [p1,conj(p1),p2,conj(p2), p3, conj(p3)];
aroots = [p2,conj(p2), p3, conj(p3)];
a = poly(aroots);
b = [1 zeros(1,18) -1];
b1 = [1];
[h,w] = freqz(b1,a);
freqzplot(h,w, 'mag');
     
H ( z )  1 / 0.9 1  e  j 2 z 1 1  e  j 2 z 1 0.9 1  e  j3 z 1 1  e  j3 z 1 
figure; 

 1 / 0.9 1  2 cos 2 z 1  z  2


 2  0.3

0.9 1  2 cos 3 z 1  z  2 

3  0.4 
freqzplot(h,w,'squared');
   
 1 / 0.9 1  2 cos(0.3 ) z 1  z  2 0.9 1  2 cos(0.4 ) z 1  z  2 
Kaiser Bessel Window
clear all;
close all;
N=61;
w31 = window(@kaiser,N,1);
w33 = window(@kaiser,N,3);
w35 = window(@kaiser,N,5);
w37 = window(@kaiser,N,7);
plot(1:N,[w31, w33, w35, w37]); axis([1 N 0 1]);
legend('beta=1','beta = 3', 'beta=5', 'beta=7');
figure;
a=[1];
[fw31,f] = freqz(w31,a);
[fw33,f] = freqz(w33,a);
[fw35,f] = freqz(w35,a);
[fw37,f] = freqz(w37,a);
freqzplot([fw31,fw33,fw35,fw37],f, 'mag');
legend('beta=1','beta = 3', 'beta=5', 'beta=7');
Time Domain Windows

clear all;
close all;
N=61;
w = window(@blackmanharris,N);
w1 = window(@hamming,N);
w2 = window(@gausswin,N,2.5);
w3 = window(@kaiser,N,5);
w4 = window(@tukeywin,N,0.5);
plot(1:N,[w1,w3,w4]); axis([1 N 0 1]);
legend('Hamming','Kaiser', 'Tukey');
figure;
a=[1];
[fw,f] = freqz(w,a);
[fw1,f] = freqz(w1,a);
[fw2,f] = freqz(w2,a);
[fw3,f] = freqz(w3,a);
[fw4,f] = freqz(w4,a);
freqzplot([fw1,fw3,fw4],f, 'mag');
legend('Hamming','Kaiser', 'Tukey');
DFT of Square Waves, 3 Duties
100% Duty 50% Duty
close all;
clear all;
x = ones(1,16);
y = fft(x,16);
my = abs(y)/16;
ay = angle(y);
stem(my);
figure;
y1 = fft (x,32)/16;
my1 = abs(y1); 12.5% Duty
stem(my1);
y2= fft (x,128);
figure;
stem (abs(y2));
Notch Filters
clear all;
close all;
a = [1 -1.2726 0.81]; 1 2
b = [1 -1.414 1];
[H, W] = freqz(b,a);
figure;
freqzplot(H,W,'linear');
title ('Pole-zero Notch Filter - Mag');
figure;
freqzplot(H,W);
title ('Pole-zero Notch Filter - dB');
a1 = [1];
b1 = [1 -1.414 1];
[H1, W] = freqz(b1,a1); 3 4
figure;
freqzplot(H1,W,'linear');
title ('All zero Notch Filter - Mag');
figure;
freqzplot(H1,W);
title ('All zero Notch Filter - dB');
Resonators
title ('Pole-zero Resonator r=0.99, theta = pi/4 - Mag');
clear all;
figure;
close all;
freqzplot(H,W);
r = 0.99; title ('Pole-zero Resonator r=0.99, theta = pi/4- dB');
theta = pi/4; r = 0.9;
a = [1 -2*r*theta r^2]; theta = pi/4;
b = 1; a = [1 -2*r*theta r^2];
[H, W] = freqz(b,a); b = 1;
figure; [H, W] = freqz(b,a);
freqzplot(H,W,'linear'); figure;
title ('Resonator r=0.99, theta = pi/4 - Mag'); freqzplot(H,W,'linear');
figure; title ('Resonator r=0.9, theta = pi/4 - Mag');
freqzplot(H,W); figure;
title (' Resonator r=0.99, theta = pi/4- dB'); freqzplot(H,W);
title (' Resonator r=0.9, theta = pi/4- dB');
r = 0.95;
r = 1.0;
theta = pi/4;
theta = pi/4;
a = [1 -2*r*theta r^2];
a = [1 -2*r*theta r^2];
b = 1; b = 1;
[H, W] = freqz(b,a); [H, W] = freqz(b,a);
figure; figure;
freqzplot(H,W,'linear'); freqzplot(H,W,'linear');
title ('Resonator r=0.95, theta = pi/4 - Mag'); title ('Oscillator, theta = pi/4 - Mag');
figure; figure; 1
freqzplot(H,W); freqzplot(H,W);
title (' Resonator r=0.95, theta = pi/4- dB'); title ('Oscillator, theta = pi/4- dB');
r = 0.99;
theta = pi/4;
a = [1 -2*r*theta r^2];
b = [1 0 -1]
[H, W] = freqz(b,a);
figure;
freqzplot(H,W,'linear');
Resonators (continued)
2 3 4

5 6 7

8 9 10
Comb Filters
clear all;
close all;
a = [1 -1]; 1 2
b = [1 0 0 0 0 0 0 0 0 0 0 -1];
b = b/11;
[H, W] = freqz(b,a);
figure;
freqzplot(H,W,'linear');
title ('Comb Filter M=10 - Mag');
figure;
freqzplot(H,W);
title ('Comb Filter M=10 - dB');
bz = zeros (1,54);
a1 = [1 0 0 0 0 -1];
b1 = [1 [bz] -1];
[H, W] = freqz(b1,a1); 3 4
figure;
freqzplot(H,W,'linear');
title ('LM Comb Filter L = 5 M=10 - Mag');
figure;
freqzplot(H,W);
title ('LM Comb Filter L = 5 M=10 - dB');
Welch Periodogram PSD
close all;
clear all;
t = 0:.001:4.096;
x = sin(2*pi*50*t) + sin(2*pi*120*t);
1 2 ¼ Hz Res
stdev = 2;
y = x + stdev*randn(size(t));
figure;
plot(y(1:50))
title('Noisy time domain signal')
FS = 1000.; % Sampling Rate

% 1 section Time
NFFT = 4096;
Noverlap = 0
figure;
pwelch(y, 4096, Noverlap, NFFT, FS)

% 16 overlapping sections
NFFT = 512;
Noverlap = 256
figure;
2 Hz Res 4 Hz Res
pwelch(y, 512, Noverlap, NFFT, FS)

% 32 overlapping sections
NFFT = 256;
Noverlap = 128
figure;
pwelch(y, 256, Noverlap, NFFT, FS) 3 4
Discrete Fourier Transform (DFT)
N 1
Forward Transform: X (k )   x(n)e  j 2nk / N for k=0,1,2,…,N-1
n0

1 N 1 j 2nk / N
Inverse Transform: x(n)   X ( k )e for n=0,1,2,…,N-1
N k 0
-----------------------------------------------------------------------------------------------------------
N=8; % MATLAB “DISCRETE FOURIER TRANSFORM” PROGRAM
w0 = 2*pi/N;
K0 =3;
w=w0*K0*(0:N-1);
j2nKo/N
Data = complex(cos(w),sin(w)); % Data = e
for k =1:N
accum=complex(0,0);
for n=1:N
A = w0*(n-1)*(k-1);
-j2nk/N
Twiddle=complex(cos(A),-sin(A)); %Twiddle = e
accum = accum+Data(n)*Twiddle; % X(k)= e
j2nKo/N -j2nk/N
e
end % "n" is Time index
MAGXk=abs(accum) % Output the Magnitude of the DFT =N @ k=K0
end % "k" is the Frequency index

You might also like