Solution#3-4 Raja Ali Dad DSP

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 10

Name: Raja Ali

Dad
Reg No : FA18-EPE-
174
Subject: DSP
Lab
Class: EPE-
5D
Assignment: 02
 Question 01:
 1. Firstly, take a continuous time sinusoidal with a cutoff frequency of 35 Hz. Analyze its
frequency spectrum using fft.
 2. Generate a square wave of frequency 70 Hz.
 3. Analyze its frequency spectrum using fft.
 4. Take its absolute derivative which would result in impulses thus generating impulse-train,
followed by step 5.
 5. Now multiply the impulse train with the sinusoidal & repeat step 5.
 6 The resultant is a discrete signal if zeros are terminated using a particular algorithm.
 7. Once again repeat step 5. 10. Now generate a square wave with frequency 200Hz and 35Hz
and repeat step 5 to 9 for both the frequencies.

 Coding
 Function
 function [w,Xjw]=fftt(x,fsim)
 X=fft(x,fsim)
 Xjw=fftshift(X)
 w=linspace(-fsim/2,fsim/2,fsim)
 end
 -----------------------------------------------------------
 clc;
 clear all;
 close all;
 fsim=400;
 t=[-0.1:1/fsim:0.1];
 fm=35;
 x=sin(2*pi*fm*t);
 subplot(211)
 plot(t,x)
 xlabel('time(T')
 ylabel('Amplitude(A)')
 [w Xjw]=CTFT(x,fsim);
 subplot(212)
 plot(w,abs(Xjw))
 xlabel('Frequency(w)')
 ylabel('Amplitude(A)')
 fn=70;
 impulse=abs(diff(square(2*pi*fn*t)))/2;
 figure
 subplot(211)
 plot(t(1:length(impulse)),impulse)
 xlabel('time(T')
 ylabel('Amplitude(A)')
 [w Xjw]=CTFT(impulse,fsim);
 subplot(212)
 plot(w,abs(Xjw))
 xlabel('Frequency(w)')
 ylabel('Amplitude(A)')
 z=x(1:length(impulse)).*impulse;

 index=1;

 for i=1:length(impulse)
 if impulse(i)==1
 s(index)=z(i);
 index=index+1;
 end

 end
 figure
 subplot(211)
 stem(s);
 hold on
 plot(x(1:length(s)),'r')
 subplot(212)
 [w Xjw]=CTFT(r,fsim);
 plot(w,Xjw)
 xlabel('Frequency(w)')
 ylabel('Amplitude(A)')

 ----------------------------------------------------------------------------------------------

 Output:

0.5
Amplitude(A)

-0.5

-1
-0.1 -0.08 -0.06 -0.04 -0.02 0 0.02 0.04 0.06 0.08 0.1
time(T

40

30
Amplitude(A)

20

10

0
-200 -150 -100 -50 0 50 100 150 200
Frequency(w)
1

0.5

-0.5

-1
0 5 10 15 20 25 30

15

10
Amplitude(A)

-5
-200 -150 -100 -50 0 50 100 150 200
Frequency(w)

1
Amplitude(A)

0.5

0
-0.1 -0.08 -0.06 -0.04 -0.02 0 0.02 0.04 0.06 0.08 0.1
time(T

30
Amplitude(A)

20

10

0
-200 -150 -100 -50 0 50 100 150 200
Frequency(w)

 Question#2:
 11. Generate a sinusoidal of two different frequencies (Continuous time).
 12. Take its samples after every 10 units, later keep on changing these frequency rates and
analyze the effect on reconstruction.
 13. Now multiply sinc with each sample and step by step add and multiply to reconstruct the
original signal.
 Coding
 Function
 function [w,Xjw]=fftt(x,fsim)
 X=fft(x,fsim)
 Xjw=fftshift(X)
 w=linspace(-fsim/2,fsim/2,fsim)
 end

 clc;
 clear all;
 close all;
 fsim=400;
 t=[-0.1:1/fsim:0.1];
 f1=30;
 f2=60;
 x=sin((2*pi*f1*t)+(2*pi*f2*t));
 subplot(211)
 plot(t,x)
 xlabel('time(T')
 ylabel('Amplitude(A)')
 [w Xjw]=CTFT(x,fsim);
 subplot(212)
 plot(w,abs(Xjw))
 xlabel('Frequency(w)')
 ylabel('Amplitude(A)')
 fn=70;
 impulse=abs(diff(square(2*pi*fn*t)))/2;
 figure
 subplot(211)
 plot(t(1:length(impulse)),impulse)
 xlabel('time(T')
 ylabel('Amplitude(A)')
 [w Xjw]=CTFT(impulse,fsim);
 subplot(212)
 plot(w,abs(Xjw))
 xlabel('Frequency(w)')
 ylabel('Amplitude(A)')
 z=x(1:length(impulse)).*impulse;

 index=1;

 for i=1:length(impulse)
 if impulse(i)==1
 s(index)=z(i);
 index=index+1;
 end

 end
 figure
 subplot(211)
 stem(s);
 hold on
 plot(x(1:length(s)),'r')
 subplot(212)
 [w Xjw]=CTFT(r,fsim);
 plot(w,Xjw)
 xlabel('Frequency(w)')
 ylabel('Amplitude(A)')
 fr=fn*2;
 Tr=1/fr;
 len=length(r)-1;
 n=(0:len*fr)/fr;
 x_new=zeros(1,len*fr+1);
 for i=0:len
 x_new(1,i*fr+1)=r(i+1);
 end
 sy=sinc(pi*n);
 figure
 subplot(311),stem(0:len,r),title 'x[n]'
 subplot(312),stem(n,x_new),xlabel 'n x T_r',ylabel 'x[nT_r]'
 subplot(313),plot(n,sy)
 ylabel 's(t)=sinc(2* \pi /Tr *t)',xlabel 't(msec)'

 x_rec=0;figure
 for i=0:length(r)-1


 x_rec=x_rec+r(i+1)*sinc(pi*(n-n(i*fr+1))/4);
 subplot(211),stem(n,x_new),hold on
 plot(n,r(i+1)*sinc(pi*(n-n(i*fr+1))/4),'r'),hold off

 subplot(212),plot(n/(fr),x_rec),title(['Tr=' num2str(fr/fn) 'Ts
& T actual is 20 msec' ]);
 xlabel 't(sec)',ylabel 'x_r(t)';grid on
 end

 --------------------------------------------------------------------------------------------------




 Outputs:

0.5
Amplitude(A)

-0.5

-1
-0.1 -0.08 -0.06 -0.04 -0.02 0 0.02 0.04 0.06 0.08 0.1
time(T

40

30
Amplitude(A)

20

10

0
-200 -150 -100 -50 0 50 100 150 200
Frequency(w)
1

Amplitude(A)
0.5

0
-0.1 -0.08 -0.06 -0.04 -0.02 0 0.02 0.04 0.06 0.08 0.1
time(T

30
Amplitude(A)

20

10

0
-200 -150 -100 -50 0 50 100 150 200
Frequency(w)

0.5

-0.5

-1
0 5 10 15 20 25 30

15

10
Amplitude(A)

-5
-200 -150 -100 -50 0 50 100 150 200
Frequency(w)
x[n]
1

-1
0 5 10 15 20 25 30

1
x[nT r ]

-1
0 5 10 15 20 25 30
n x Tr
/Tr *t)

0.5
s(t)=sinc(2*

0 5 10 15 20 25 30
t(msec)

0.5

-0.5

-1
0 5 10 15 20 25 30

Tr=2Ts & T actual is 20 msec

0.5
x r (t)

-0.5

-1

0 0.02 0.04 0.06 0.08 0.1 0.12 0.14 0.16 0.18 0.2
t(sec)

 Questions#1:- Explain if you observe under, over sampling.
 Answer:
Over sampling and under sampling are techniques used in data mining and
data analytics to modify unequal data classes to create balanced data sets. Over
sampling and under sampling are also known as resampling. These data analysis
techniques are often used to be more representative of real world data.
 Question#2:- Provide your analysis for the changed frequency of Impulse
train.
Answer:
An impulse train can be defined as a sum of shifted impulse: Here, is
the period of the impulse train, in seconds--i.e., the spacing between
successive impulses. The -periodic impulse train can also be defined as. Frequency-
domain analysis is a tool of utmost importance in signal processing
applications. Frequency-domain analysis is widely used in such areas as
communications, geology, remote sensing, and image processing.
 Question#3: Also use con2dis demo and provide detailed information on
aliasing process.
Answer:
Aliasing occurs when a signal is sampled at a less than twice the highest
frequency present in the signal. Signals at frequencies above half the sampling rate
must be filtered out to avoid the creation of signals at frequencies not present in the
original sound.
 ---------------------------------------------------------------------------------------------------------------------
-

You might also like