[go: up one dir, main page]

0% found this document useful (0 votes)
63 views27 pages

DSP Labs

The document describes experiments with upsampling and downsampling signals. In lab task 2, a composite 100 Hz and 200 Hz signal sampled at 1000 Hz is plotted over two cycles. This signal is then upsampled to an effective sampling rate of 4000 Hz by inserting zeros, increasing the number of samples. Exercises prove the upsampling by listing values of the original and upsampled signals over several samples. Upsampling by a factor of 4 is achieved through zero-stuffing. Downsampling a 8000 Hz signal to 2000 Hz by a factor of 4 is also demonstrated, where every 4th sample is kept while others are ignored. Resampling to change the sampling rate by a rational factor using interpolation and decimation is explored.

Uploaded by

Muhammad Uzair
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)
63 views27 pages

DSP Labs

The document describes experiments with upsampling and downsampling signals. In lab task 2, a composite 100 Hz and 200 Hz signal sampled at 1000 Hz is plotted over two cycles. This signal is then upsampled to an effective sampling rate of 4000 Hz by inserting zeros, increasing the number of samples. Exercises prove the upsampling by listing values of the original and upsampled signals over several samples. Upsampling by a factor of 4 is achieved through zero-stuffing. Downsampling a 8000 Hz signal to 2000 Hz by a factor of 4 is also demonstrated, where every 4th sample is kept while others are ignored. Resampling to change the sampling rate by a rational factor using interpolation and decimation is explored.

Uploaded by

Muhammad Uzair
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/ 27

Inlab Task:

According to the pole zero plot, the pole lies inside the unit circle. Hence the
system is stable.

clear all;
close all;
clc;
Num = poly([(0-(1i*(pi/2))),(0+(1i*(pi/2)))]);
Den = poly([-1,-1]);
Num1 = poly([1i,-1i]);
Den1 = poly([exp(-1),exp(-1)]);
sys1=tf(Num1,Den1,1)

figure;
subplot(3,1,1);
pzmap(sys1);
xlim([-2 2]);
ylim([-4 4]);

subplot(3,1,2);
[mag phase w]=bode(sys1);
mag=squeeze(mag);
plot(w,mag);
xlim([0 100])

subplot(3,1,3);
impulse(sys1);
H=dfilt.df1(Num,Den)
A=isfir(H)
figure;
pzmap(sys1)
grid on;
Exercise Task:
Change the location of poles from inside the unit circle to outside and
at the unit circle and observe and note the changes.

Location of poles at the unit circle

It is observed that when the pole is at the circumference of the unit circle, the
impulse response increases linearly with time. A spike is observed at w=0 rad/s
and at no other angular frequency. The system is marginally stable or oscillatory.

clear all;
close all;
clc;
Num = poly([(0-(1i*(pi/2))),(0+(1i*(pi/2)))]);
Den = poly([-1,-1]);
Num1 = poly([1i,-1i]);
Den1 = poly([1,1]);
sys1=tf(Num1,Den1,1)

figure;
subplot(3,1,1);
pzmap(sys1);
xlim([-2 2]);
ylim([-4 4]);

subplot(3,1,2);
[mag phase w]=bode(sys1);
mag=squeeze(mag);
plot(w,mag);
xlim([0 100])

subplot(3,1,3);
impulse(sys1);
H=dfilt.df1(Num,Den)
A=isfir(H)
figure;
pzmap(sys1)
grid on;
Location of poles outside the unit circle
When the poles lie outside the unit circle, the impulse response increases with
time. The system is therefore unstable.

clear all;
close all;
clc;
Num = poly([(0-(1i*(pi/2))),(0+(1i*(pi/2)))]);
Den = poly([-1,-1]);
Num1 = poly([1i,-1i]);
Den1 = poly([-2,2]);
sys1=tf(Num1,Den1,1)

figure;
subplot(3,1,1);
pzmap(sys1);
xlim([-2 2]);
ylim([-4 4]);

subplot(3,1,2);
[mag phase w]=bode(sys1);
mag=squeeze(mag);
plot(w,mag);
xlim([0 100])

subplot(3,1,3);
impulse(sys1);

H=dfilt.df1(Num,Den);
A=isfir(H)
figure;
pzmap(sys1)
grid on;
Inlab Task:

According to the pole zero plot, the pole lies inside the unit circle. Hence the
system is stable.

clear all;
close all;
clc;
Num = poly([(0-(1i*(pi/2))),(0+(1i*(pi/2)))]);
Den = poly([-1,-1]);
Num1 = poly([1i,-1i]);
Den1 = poly([exp(-1),exp(-1)]);
sys1=tf(Num1,Den1,1)

figure;
subplot(3,1,1);
pzmap(sys1);
xlim([-2 2]);
ylim([-4 4]);

subplot(3,1,2);
[mag phase w]=bode(sys1);
mag=squeeze(mag);
plot(w,mag);
xlim([0 100])

subplot(3,1,3);
impulse(sys1);
H=dfilt.df1(Num,Den)
A=isfir(H)
figure;
pzmap(sys1)
grid on;
Exercise Task:
Change the location of poles from inside the unit circle to outside and
at the unit circle and observe and note the changes.

Location of poles at the unit circle

It is observed that when the pole is at the circumference of the unit circle, the
impulse response increases linearly with time. A spike is observed at w=0 rad/s
and at no other angular frequency. The system is marginally stable or oscillatory.

clear all;
close all;
clc;
Num = poly([(0-(1i*(pi/2))),(0+(1i*(pi/2)))]);
Den = poly([-1,-1]);
Num1 = poly([1i,-1i]);
Den1 = poly([1,1]);
sys1=tf(Num1,Den1,1)

figure;
subplot(3,1,1);
pzmap(sys1);
xlim([-2 2]);
ylim([-4 4]);

subplot(3,1,2);
[mag phase w]=bode(sys1);
mag=squeeze(mag);
plot(w,mag);
xlim([0 100])

subplot(3,1,3);
impulse(sys1);
H=dfilt.df1(Num,Den)
A=isfir(H)
figure;
pzmap(sys1)
grid on;
Location of poles outside the unit circle
When the poles lie outside the unit circle, the impulse response increases with
time. The system is therefore unstable.

clear all;
close all;
clc;
Num = poly([(0-(1i*(pi/2))),(0+(1i*(pi/2)))]);
Den = poly([-1,-1]);
Num1 = poly([1i,-1i]);
Den1 = poly([-2,2]);
sys1=tf(Num1,Den1,1)

figure;
subplot(3,1,1);
pzmap(sys1);
xlim([-2 2]);
ylim([-4 4]);

subplot(3,1,2);
[mag phase w]=bode(sys1);
mag=squeeze(mag);
plot(w,mag);
xlim([0 100])

subplot(3,1,3);
impulse(sys1);

H=dfilt.df1(Num,Den);
A=isfir(H)
figure;
pzmap(sys1)
grid on;
LAB SESSION 06
The Discrete Fourier Transform as a Linear
Transformation
IN LAB TASK:
Compute 4 point DFT of x(n)= ( 1,2,3,0).
STEPS
1. Generate given sequence in Matlab .
2. Take N-=4 to calculate 4-point DFT.
3. Define 0: N-1 point vector for time and frequency samples.
4. Define W matrix and then use DFT analysis equation to compute DFT.

Code:
close all,
clear all;
clc;
x=[1 ,2 ,3 ,0];
N=4;
n=[0:1:N-1];
k=[0:1:N-1];
WN=exp(-j*2*pi/N);
nk=n'*k;
WNnk=WN.^nk;
Xk=x*WNnk

Output:
LAB TASK 1:
Prove DFT synthesis equation using DFT output generated from lab task.
Code:
clear all;
close all;
clc;

X=[6.0000 + 0.0000i -2.0000 - 2.0000i 2.0000 + 0.0000i -2.0000 +


2.0000i];
N=4;
n=[0:1:N-1];
k=[0:1:N-1];
WN=exp(j*2*pi/N);
nk=n'*k;
WNnk=WN.^nk;
x=1/N*(X*WNnk)

Output:

Comments:
DFT synthesis equation has been proved.
LAB SESSION 06
The Discrete Fourier Transform as a Linear
Transformation
IN LAB TASK:
Compute 4 point DFT of x(n)= ( 1,2,3,0).
STEPS
1. Generate given sequence in Matlab .
2. Take N-=4 to calculate 4-point DFT.
3. Define 0: N-1 point vector for time and frequency samples.
4. Define W matrix and then use DFT analysis equation to compute DFT.

Code:
close all,
clear all;
clc;
x=[1 ,2 ,3 ,0];
N=4;
n=[0:1:N-1];
k=[0:1:N-1];
WN=exp(-j*2*pi/N);
nk=n'*k;
WNnk=WN.^nk;
Xk=x*WNnk

Output:
LAB TASK 1:
Prove DFT synthesis equation using DFT output generated from lab task.
Code:
clear all;
close all;
clc;

X=[6.0000 + 0.0000i -2.0000 - 2.0000i 2.0000 + 0.0000i -2.0000 +


2.0000i];
N=4;
n=[0:1:N-1];
k=[0:1:N-1];
WN=exp(j*2*pi/N);
nk=n'*k;
WNnk=WN.^nk;
x=1/N*(X*WNnk)

Output:

Comments:
DFT synthesis equation has been proved.
IN LAB TASKS:

TASK#1:

In these plots
original signal
is given and
second one is
a up
sampled
signal. In this
plot
number of
samples have
been
increased by
using zero
stuffing
method. In
between two

consecutive points 5 zeros have been inserted to increase number of samples.

TASK#2:
This is a case when zero stuffing is done by using up sampling command in whereas
in previous task

A step was written to add zeros. Here signal is up sampled by a factor of 4 so from
plot it can be seen 3 zeros sampled are inserted between two samples.

TASK#3:
This plot shows two signals original one and up sampled. Here process used for up
sampling is interpolation. In interpolation two samples are taken and and
approximate average values are taken to insert between these two samples. To
interpolate interp command is used.

TASK#4/5:
This plot shows two signals original and down sampled one. In down sampling
number of samples representing a signal reduces that means sampling rate reduce.
In matlab down sample command is used to down sample a signal. Here 8000
sampling rate has been reduced to 2000 by a factor of 4.In down sampling at
particular instants samples are picked while others are ignored.

TASK#6:
This graph shows an original signal. With the help of resample command this signal
will be resampled. Resampling means combining interpolation and decimation to
change the sampling rate by a rational factor. Resampled signal is:
We resample when two different frequencies are given. To resample first signal is
interpolated and the downsamped. A ratio is obtained to get back the same sample.
Now obtained signal is approximately equal to original signal
Lab 05

Lab Task 2:
Generate a composite signal of 100 Hz and 200Hz sinusoid originally
sampled at Fs=1000 Hz.
 Plot it in discrete form for two complete cycles.
 Now up-sample the original signal such that the effective sampling rate
will become Fs'=4000 Hz.
 Observe and note the effects of up-sampling.

Exercises:
1.Write values of corresponding input and output sequences to prove lab
task 2.you may use
following table to note data. Also, prove the value of up sampling factor.
Sample Number Original Signal Up sampled Signal
0 0 0
1 1.5388 0
2 0.3633 0
3 -0.3633 0
4 0 1.5388
5 0.3633 0
6 -0.3633 0
7 -1.5388 0
8 -1.5388 1.5388
9 0 0
10 1.5388 0
11 1.5388 0
12 0.3633 0.3633
13 -0.3633 0
14 0 0
15 0.3633 0
16 -0.3633 -0.3633
17 -1.5388 0
18 -1.5388 0
19 0 0

The “upsample(x,L)” function increases the sampling rate of an input signal


“x” by a factor “L” called the up sampling factor. If up sampling is achieved
by zero-stuffing, then the newly generated signal would have “L-1” zeros
inserted between two consecutive samples of the input signal “x”.
In this case L=4 and as we can see from the values of original and up
sampled signals, 3 zeros have been inserted between two consecutive
samples of original signal to create the up sampled signal. The length of up
sampled signal is “L” times the length of original signal.
2. Record your voice at sampling rate of 44100Hz. Now down-sample and up
sample the
recorded speech signal by different factors and observe the quality of re-
sampled signals. And answer the given questions:

a Describe what you heard.


As the speech signal is down sampled its play back rate increases and
as the signal is up sampled its play back rate decreases.

b What changes in playback rate in the sound (yd,Fs) and sound (yu,Fs)
are necessary to make the audio sound just right?
If the signal is down sampled by a factor “M” then the play back rate
for “sound(yd,Fs)” should be “(1/M)x” to make the audio sound just
right. While in the case of up sampling by a factor of “L” the play back
rate in “sound(yu,Fs)” should be “Lx” to make the audio sound just
right.

c What changes in “audiowrite” are necessary to generate correct


multimedia files?
To generate correct audio files (which sound like the original recorded
voice), the “audiowrite(filename,y,Fs)” function could be modified.
In case of up sampling by a factor “L”, the sampling rate, at which the
audio is being written after being up sampled, should be “L” times the
original sampling rate i.e. “audiowrite(filename,y,L*Fs)”.
And In case of down sampling by a factor “M”, the sampling rate, at
which the audio is being written after being down sampled, should be
“1/M” times the original sampling rate i.e.
“audiowrite(filename,y,L*Fs/M)”.

d Mention both the maximum down sampling limit (factor) and up


sampling limit
(factor) in speech signal and also specify the reasons.

e Attach spectrum of all multimedia files of original, down sampled and


up sampled
versions e.g. speech.wav, dn2.wav, up2.wav, dn3.wav, up3.wav,
dn4.wav, up4.wav,
and so on by using the 'plot spectrum' in Audacity®. Use two column
format for the
plotting of figures. Use small sized figures (they should be readable).

At L=M=2,

At L=M=3,
At L=M=4,

You might also like