Signal Down-sampling and Up-sampling in MATLAB
Added on 2023-04-21
30 Pages3489 Words56 Views
|
|
|
Running head: EECS 152B
EECS 152B
Name of the Student
Name of the University
Author Note
EECS 152B
Name of the Student
Name of the University
Author Note
![Signal Down-sampling and Up-sampling in MATLAB_1](/_next/image/?url=https%3A%2F%2Fdesklib.com%2Fmedia%2Fimages%2Fvw%2F4fcd5c8b324a4d69a7cf6040da971493.jpg&w=3840&q=10)
1EECS 152B
Question 1:
The MATLAB code for generating samples of a sin wave having frequency 1000 Hz which is
sampled by rate 20 kHz is given below. Then the sound command is used to listen the signal
as sound wave.
MATLAB code:
fs = 20e3; % sampling rate sample/sec
delt = 1/fs; % time increment sec/sample
t = 0:delt:1;
f = 1e3; % frequency of signal
s = sin(2*pi*f*t); % signal amplitude is 1
plot(t,s,'m')
xlabel('time in seconds');
ylabel('Signal aplitude');
title('Amplitude of signal vs time')
grid on
zoom(32)
ylim([-1.5,1.5])
sound(s,fs)
Question 1:
The MATLAB code for generating samples of a sin wave having frequency 1000 Hz which is
sampled by rate 20 kHz is given below. Then the sound command is used to listen the signal
as sound wave.
MATLAB code:
fs = 20e3; % sampling rate sample/sec
delt = 1/fs; % time increment sec/sample
t = 0:delt:1;
f = 1e3; % frequency of signal
s = sin(2*pi*f*t); % signal amplitude is 1
plot(t,s,'m')
xlabel('time in seconds');
ylabel('Signal aplitude');
title('Amplitude of signal vs time')
grid on
zoom(32)
ylim([-1.5,1.5])
sound(s,fs)
![Signal Down-sampling and Up-sampling in MATLAB_2](/_next/image/?url=https%3A%2F%2Fdesklib.com%2Fmedia%2Fimages%2Fjv%2F70f82e612d0049909fd44ce24ff14ca6.jpg&w=3840&q=10)
2EECS 152B
Plot:
0.485 0.49 0.495 0.5 0.505 0.51 0.515
time in seconds
-1.5
-1
-0.5
0
0.5
1
1.5
Signal aplitude
Amplitude of signal vs time
The sine wave with 20 kHz frequency is shown above and the sound of the wave is played
which has very low bass or high treble.
Question 2:
Now, the input signal is upsampled to 80 kHz. Then the Up-sampled output is interpolated
two form the 80 kHz sampling rate output.
MATLAB code:
fs = 20e3; % sampling rate sample/sec
fup = 80e3; % upsampling rate
sfactor=fup/fs; % sampling factor
Plot:
0.485 0.49 0.495 0.5 0.505 0.51 0.515
time in seconds
-1.5
-1
-0.5
0
0.5
1
1.5
Signal aplitude
Amplitude of signal vs time
The sine wave with 20 kHz frequency is shown above and the sound of the wave is played
which has very low bass or high treble.
Question 2:
Now, the input signal is upsampled to 80 kHz. Then the Up-sampled output is interpolated
two form the 80 kHz sampling rate output.
MATLAB code:
fs = 20e3; % sampling rate sample/sec
fup = 80e3; % upsampling rate
sfactor=fup/fs; % sampling factor
![Signal Down-sampling and Up-sampling in MATLAB_3](/_next/image/?url=https%3A%2F%2Fdesklib.com%2Fmedia%2Fimages%2Fvr%2F965e2966fd3341fdad3fe948d7eb649e.jpg&w=3840&q=10)
3EECS 152B
delt = 1/fs; % time increment sec/sample
t = 0:delt:1;
f = 1e3; % frequency of signal
s = sin(2*pi*f*t); % signal amplitude is 1
figure(1)
subplot(2,1,1)
stem(t,s)
xlabel('Time in sec');
ylabel('Amplitude');
title('Signal output before Up-sampling');
zoom(64)
ylim([-1.5,1.5])
%%% zero insertion
lx = length(s);
y = 0;
y(1) = s(1);
for i=2:lx
c = [zeros(1,sfactor-1),s(i)];
y = [y,c];
delt = 1/fs; % time increment sec/sample
t = 0:delt:1;
f = 1e3; % frequency of signal
s = sin(2*pi*f*t); % signal amplitude is 1
figure(1)
subplot(2,1,1)
stem(t,s)
xlabel('Time in sec');
ylabel('Amplitude');
title('Signal output before Up-sampling');
zoom(64)
ylim([-1.5,1.5])
%%% zero insertion
lx = length(s);
y = 0;
y(1) = s(1);
for i=2:lx
c = [zeros(1,sfactor-1),s(i)];
y = [y,c];
![Signal Down-sampling and Up-sampling in MATLAB_4](/_next/image/?url=https%3A%2F%2Fdesklib.com%2Fmedia%2Fimages%2Fbb%2F32152b15d6ef40dca35d55bf36080b8d.jpg&w=3840&q=10)
4EECS 152B
end
%%% Output display of zeros inserted signal
nm=linspace(0,1,length(y));
figure(1)
subplot(2,1,2)
stem(nm,y); %Upsampled version of signal
xlabel('Time in sec');
ylabel('Amplitude');
title('Zeros inserted Output of Signal');
zoom(64)
ylim([-1.5,1.5])
sound(y,fup)
xi=s;
yi = interp(xi,sfactor);
nn=linspace(0,1,length(yi));
figure(2)
stem(nn,yi); %interpolation output
xlabel('Time in sec');
ylabel('Amplitude');
end
%%% Output display of zeros inserted signal
nm=linspace(0,1,length(y));
figure(1)
subplot(2,1,2)
stem(nm,y); %Upsampled version of signal
xlabel('Time in sec');
ylabel('Amplitude');
title('Zeros inserted Output of Signal');
zoom(64)
ylim([-1.5,1.5])
sound(y,fup)
xi=s;
yi = interp(xi,sfactor);
nn=linspace(0,1,length(yi));
figure(2)
stem(nn,yi); %interpolation output
xlabel('Time in sec');
ylabel('Amplitude');
![Signal Down-sampling and Up-sampling in MATLAB_5](/_next/image/?url=https%3A%2F%2Fdesklib.com%2Fmedia%2Fimages%2Fxe%2F34c193ebfb2648669997339b3c858e2c.jpg&w=3840&q=10)
5EECS 152B
title('Up-sampled output after interpolation');
zoom(64)
ylim([-1.5,1.5])
sound(yi,fup)
Plots:
title('Up-sampled output after interpolation');
zoom(64)
ylim([-1.5,1.5])
sound(yi,fup)
Plots:
![Signal Down-sampling and Up-sampling in MATLAB_6](/_next/image/?url=https%3A%2F%2Fdesklib.com%2Fmedia%2Fimages%2Fbd%2F3ccd1ab64b1548318a161994a9ffff3b.jpg&w=3840&q=10)
End of preview
Want to access all the pages? Upload your documents or become a member.