logo

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
Signal Down-sampling and Up-sampling in MATLAB_1

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)
Signal Down-sampling and Up-sampling in MATLAB_2

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
Signal Down-sampling and Up-sampling in MATLAB_3

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];
Signal Down-sampling and Up-sampling in MATLAB_4

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');
Signal Down-sampling and Up-sampling in MATLAB_5

5EECS 152B
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

End of preview

Want to access all the pages? Upload your documents or become a member.