KEMBAR78
SAMPLING | PDF | Sampling (Signal Processing) | Discrete Fourier Transform
0% found this document useful (0 votes)
20 views14 pages

SAMPLING

Samplong Theorem experiment

Uploaded by

virajbhosale781
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views14 pages

SAMPLING

Samplong Theorem experiment

Uploaded by

virajbhosale781
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 14

SAMPLING

Objective:
At the end of this experiment, we will know about:
(a) What is the sampling theorem, and how is sampling done?
(b) Why do we always perform sampling with a sampling frequency
above the Nyquist rate, and what happens when we sample below it?
(c) What is aliasing, and how do the original frequencies get folded
back into the spectrum when undersampling?
(d) Characteristics of DFT, as well as the effect of increasing the time
window on the DFT spectrum?
(e) The nature of the DFT spectrum of square waves and the
harmonics present in it.
(f) Effect of zero interpolation on a signal.
(g) How to use a lowpass filter and its effect on a signal.

Implementation:
(a) Sampling of a sinusoidal waveform:
i. Take an analog waveform,
x(t) = 10 cos(2π·10 3 t)+6 cos(2π·2×10 3 t)+2 cos(2π·4×10 3 t).
ii. Sample it at Fs = 12 kHz.
iii. Obtain DFT of x(t) with N = 64, 128, 256 points and plot the
respective magnitude spectrum.
(b) Sampling below the Nyquist rate and the effect of
aliasing:
i. Generate a sinusoidal signal of frequency 8 kHz.
ii. Sample it at Fs = 12 kHz.
iii. Pass it through a lowpass filter of cutoff frequency 6 kHz. iv. Find
the frequency of the reconstructed signal.
(c) Spectrum of a square wave:
i. Take a square wave with time period T = 1ms (F = 1 kHz).
ii. Sample it at Fs = 20 kHz.
iii. Obtain DFT of the sampled square wave with N = 256 points and
plot the results.
(d) Interpolation and Padding:
i. Take a lowpass signal of bandwidth 6 kHz.
ii. Sample it at Fs1 = 12 kHz.
iii. Insert one zero in between every two samples.
iv. Pass it through a lowpass filter of cutoff frequency 6 kHz. v. Plot
the output of the lowpass filter and compare it with the original
signal sampled at Fs = 24 kHz.

Code:
(a) Sampling of a sinusoidal waveform:

clc;
clear all;
close all;

T=(1e-7)/1.2;
fs=12000;
Ns=[64,128,256];
t=0:T:0.1;
delta=floor(1/(T*fs));

f1=1000;
f2=2000;
f3=4000;
x1=10*cos(2*pi*f1*t);
x2=6*cos(2*pi*f2*t);
x3=2*cos(2*pi*f3*t);
x=x1+x2+x3;

plot(t,x1,LineWidth=2)
title('Signal of f=1kHz')
xlabel('Time')
ylabel('Amplitude')
xlim([0,0.001])

figure
plot(t,x2,LineWidth=2)
title('Signal of f=2kHz')
xlabel('Time')
ylabel('Amplitude')
xlim([0,0.001])

figure
plot(t,x3,LineWidth=2)
title('Signal of f=4kHz')
xlabel('Time')
ylabel('Amplitude')
xlim([0,0.001])

figure
plot(t,x,LineWidth=2)
title('Signal of multiple frequency')
xlabel('Time')
ylabel('Amplitude')
xlim([0,0.001])

for j=1:3
N=Ns(j);
x_samples=zeros(1,N);
t_samples=zeros(1,N);

for i=1:N
t_samples(i)=t((i-1)*delta+1);
x_samples(i)=x((i-1)*delta+1);
end

X=fftshift(fft(x_samples,N));
n=(-N/2:N/2-1)*fs/N;

figure
plot(n,abs(X),LineWidth=2);
title('DFT at N=',num2str(N))
xlabel('Frequency')
ylabel('X|f|')

end

(b) Sampling at below Nyquist rate and effect of


aliasing:

T=(1e-7)/1.2;
fs=12000;
t=0:T:0.1;
delta=floor(1/(T*fs));

x=sin(2*pi*8000*t);
N=256;
Wn=(fs/2-1)/(fs/2);
[b,a]=butter(4,Wn,'low');
x1=filter(b,a,x);
figure
plot(t,x,LineWidth=2)
title('Signal')
xlabel('Time')
ylabel('Amplitude')
xlim([0,0.001])

for i=1:N
t_samples(i)=t((i-1)*delta+1);
x_samples(i)=x((i-1)*delta+1);
end

figure
plot(t,x1,LineWidth=2)
title('Signal')
xlabel('Time')
ylabel('Amplitude')
xlim([0,0.001])

n=(-N/2:N/2-1)*fs/N;

X=fftshift(fft(x_samples,N));
figure
plot(n,abs(X),LineWidth=2);
xlabel('Frequency')
ylabel('X|f|')

(c) Spectrum of a square wave:


clc;
clear all;
close all;
T=(1e-7)/1.2;
fs=24000;

t=0:T:0.1;
delta=floor(1/(T*fs));
N=256;
x=sign(sin(2*pi*1000*t));
plot(t,x,Linewidth=2)
title('Signal of multiple frequency')
xlabel('Time')
ylabel('Amplitude')
xlim([0,0.01])

x_samples=zeros(1,N);
t_samples=zeros(1,N);

for i=1:N
t_samples(i)=t((i-1)*delta+1);
x_samples(i)=x((i-1)*delta+1);
end
X=fftshift(fft(x_samples,N));
n=(-N/2:N/2-1)*fs/N;

figure
plot(n,abs(X),Linewidth=2);
title('DFT')
xlabel('Frequency')
ylabel('X|f|')

(d) Interpolation and Padding:

clc;

clear all;

close all;

%Signal Frequencies

f=6000;

fs1=12000;
t=0:1/fs1:0.001;

x=sin(2*pi*f*t);%signal
n=size(t,2);

x_ip=zeros(1,2*n-1);

for i=1:size(x_ip,2)
if rem(i,2)==1
x_ip(i)=x((i+1)/2);
end
end

fc=6000;
fs2=2*fs1;
Wn=fc*2/fs2;
[b,a]=butter(4,Wn,'low');
x_filtered=filter(b,a,x_ip);
t_neo=0:1/fs2:0.001;
x_neo= sin(2*pi*f*t_neo);%

plot(t,x_neo,LineWidth=2);%Plot of the signal


title("Original and Filtered Signals")
xlabel("Time")
ylabel("Amplitude")

hold on
plot(t_neo,x_filtered,LineWidth=2);
legend('Original Signal','Filtered Signal')

Results:
(a) Sampling of a sinusoidal waveform:
(b) Sampling at below Nyquist rate and effect of
aliasing:
From the spectrum we observe that the aliased frequency is 4kHz.
(c) Spectrum of a square wave:
(d) Interpolation and Padding:

Interpretation:
In the first part of this experiment, we sampled a sinusoidal signal
above the Nyquist rate and performed DFT at 3 different values of N.
The plots had 6 peaks at the frequencies present in the signal and
their negative. The height of the peaks is proportional to the
amplitude of the sinusoidal wave of the particular frequency. Also, as
we increase the value of N, the height of the peaks also increases
proportionally, while the value of the DFT at the other points
decreases. From this, we can theoretically infer that at N= ∞, the DFT
plot would be zero everywhere but the frequencies present in the
signal, where it will tend to ∞.
In this part of the experiment, we deliberately sample at a frequency
of 12kHz, which is below the Nyquist rate, i.e 16kHz, as the signal has
a maximum frequency of 8kHz to observe aliasing(i.e, undersampling).
Taking DFT of the undersampled signal at N=256, we observe that the
higher frequency components fold and appear as false frequencies in
the DFT plot, which are given as:
f alias = mF s ± f signal , where m is an integer.
Here, the original spectral components overlap with these aliases,
making it impossible to distinguish between true and aliased
frequencies. This confirms the practical importance of adhering to the
Nyquist criterion.
When we take the DFT of a square wave, we see that peaks appear
not just at the frequency of the square wave but also at its odd
multiples with decreasing amplitude. This is because the square wave
has half-wave symmetry, i.e.

( T2 )=−x(t)
x t+

which removes even harmonics. The square wave is also an odd


function, which means it contains only sine waves and is represented
as,
4 1 1
x (t )= [sin 2 πft + sin 2 π ( 3 f ) t+ sin 2 π ( 5 ft ) … … … … ]
π 3 5

From the equation, we can clearly see that the amplitude of the
frequency component decreases as the respective frequency
increases. Due to this, we usually neglect the DFT spectrum harmonics
above the 10 th harmonic as their amplitude is very small.
In the last part of the experiment, we took a signal sampled at 12kHz
and padded it with zeros in between each sample. This resulted in the
sample frequency increasing from 12kHz to 24kHz(upsampling). Then
we passed it through a low-pass filter, which removed the higher
frequency components and resulted in a signal that was almost
identical to the one directly sampled at 24kHz except for a finite delay
of 66.67µs and a scaling effect of around .32 caused by the filter.

You might also like