Sie sind auf Seite 1von 2

Lab-2: Digital signal processing

%Program for plotting unit impulse signal


figure(1)
n=-5:5;
x=[0 0 0 0 0 1 0 0 0 0 0];
stem(n,x,'m','linewidth',4)
xlabel('Time index')
ylabel('Amplitude')
title('Unit impulse signal waveform')
gridon
%
%%Program for plotting unit step signal
figure(2)
n=-5:5;
x=[0 0 0 0 0 1 1 1 1 1 1];
stem(n,x,'r','linewidth',4)
xlabel('Time index')
ylabel('Amplitude')
title('Unit step signal waveform')
gridon
%%
%Program for plotting ramp signal
figure(3)
n=-5:5;
x=[0 0 0 0 0 0 1 2 3 4 5];
stem(n,x,'r','linewidth',4)
xlabel('Time index')
ylabel('Amplitude')
title('Ramp signal waveform')
gridon
%%
%Program for Down sampling of discrete time signals
figure(4)
n=-5:5;
x=2*cos(pi*n);
M=4; % down sampling factor
y=downsample(x,M);
subplot(2,1,1)
stem(n,x,'linewidth',4)
xlabel('Time index')
ylabel('Amplitude')
title('Original signal')
gridon
subplot(2,1,2)
stem(1:length(y),y,'linewidth',4)
xlabel('Time index')
ylabel('Amplitude')
title('Down sampled signal')
gridon
%% Program for up sampling of discrete time signals
figure(5)
n=-5:5;
x=2*cos(pi*n);
L=4; % upsampling factor
y=upsample(x,L);
subplot(2,1,1)
stem(n,x,'linewidth',4)
xlabel('Time index')
ylabel('Amplitude')
title('Original signal')
gridon
subplot(2,1,2)
stem(1:length(y),y,'linewidth',4)
xlabel('Time index')
ylabel('Amplitude')
title('Up sampled signal')
gridon

Exercise
1) Plot the following discrete time signals in MATLAB.
|𝑛| 𝑢(−𝑛)
A) 𝑥(𝑛) = { }B)𝑥(𝑛) = 2 𝑐𝑜𝑠(10𝜋𝑛) 𝑢(𝑛)C)𝑥(𝑛) = 𝑠𝑖𝑛(𝜋𝑛) + 2𝑐𝑜𝑠(2𝜋𝑛)
0, 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒
2) If 𝑀 = 2 is the down sampling factor and 𝐿 = 2 is the up sampling factor, plot x[n] and
y[m] in the same plane using MATLAB and justify the results for the following two cases.

a)

b)

Das könnte Ihnen auch gefallen