Professional Documents
Culture Documents
DSP Assignment 1 Ashwin
DSP Assignment 1 Ashwin
PROCESSING
Assignment -1 (Date: 01/08/2016)
corresponding MATLAB instructions are also given below. Here, one of the sample
frequencies 3kHz, is less than the Nyquist condition requirement. Hence, the first
plot shows an undersampled signal.
% Sample the sinusoid x = sin(2 pi f t), where f = 2 kHz.
% Let x1 be the signal sampled at 3 kHz.
% Let x2 be the signal sampled at 5 kHz.
f = 2000;
T = 1/f;
tmin = 0;
tmax = 5*T;
% Plot 5 cycles
dt1 = 1/3000;
dt2 = 1/5000;
t1 = tmin:dt1:tmax;
t2 = tmin:dt2:tmax;
x1 = sin(2*pi*f*t1);
x2 = sin(2*pi*f*t2);
subplot(211)
stem(t1,x1);
subplot(212)
stem(t2,x2);
4. The plot from MATLAB, and the adjoining code are as follows:
%
t1 = tmin:dt1:tmax;
t2 = tmin:dt2:tmax;
x = sin(2*pi*f*t);
x1 = sin(2*pi*f*t1);
x2 = sin(2*pi*f*t2);
subplot(211)
plot(t,x,'r');
hold on
stem(t1,x1);
subplot(212)
plot(t,x,'r');
hold on
stem(t2,x2);
In this question, we see that the sampled signals are peculiar they coincide exactly as one.
This,
is
because the signal frequencies 1/8Hz and -7/8Hz are both equidistant about 1Hz, the
sampling frequency. A couple of other examples would be signals having frequencies and 3/4 sampled at 1Hz, and signals with frequencies 5/3 and -1/3 sampled at 2Hz.
f1 = 1/8;
f2= -7/8;
T1 = 1/f1;
T2 =1/f2;
tmin = 0;
t1max = 4*T1;
t2max =-28*T2;
dt = 1;
ts1 = tmin:dt:t1max;
ts2 = tmin:dt:t2max;
x1s = 3*sin(2*pi*f1*ts1);
x2s = 3*sin(2*pi*f2*ts2);
t=0:0.00001:2*T1;
x1=3*sin(2*pi*f1*t);
x2=3*sin(2*pi*f2*t);
subplot(4,1,1);
stem(ts1,x1s),title('Both
Overlapped'),xlabel('t'),ylabel('A');hold on
stem(ts2,x2s,'k')
subplot(4,1,2);
stem(ts1,x1s),title('Sampling Freq
1/8'),xlabel('t'),ylabel('A');
subplot(4,1,3);
stem(ts2,x2s,'k'),title('Sampling Freq 7/8'),xlabel('t'),ylabel('A');
subplot(4,1,4);
plot(t,x1);hold on
plot(t,x2);hold on
stem(ts1,x1s);hold on
stem(ts2,x2s,'k'),title('All'),xlabel('t'),ylabel('A')
6.
f = 2000;
T = 1/f;
tmin = 0;
tmax = 5*T;
dt1 = 1/15000;
t1 = tmin:dt1:tmax;
x1 = 3*sin(2*pi*f*t1);
t=0:0.00001:0.0025;
x=3*sin(2*pi*f*t);
dv=(3/4);
partition = [-3:dv:3];
codebook = [-3-(dv/2):dv:(3+(dv/2))];
[index,quantized] = quantiz(x1,partition,codebook);
stem(t1,quantized),title('Digitalized Signal'),xlabel('time-->'),ylabel('amplitude--->'),grid on;hold on
plot(t,x)
error=immse(x1,quantized)