Abez
Newbie level 1
Understand the given code for sampling of analog signal in MATLB, the code must demonstrate following effects
Oversampling
Under sampling (Aliasing)
Run the codes given below and prepare a lab report max 2 pages based on your understanding of code and different sampling effects. Comment on the out and how it varies by changing different parameters in the given code
% Sample the sinusoid x = sin(2 pi f t), where f = 2 kHz, and plot the sampled
% signals over the continuous-time signal.
% Let x1 be the signal sampled at 10 kHz.
% Let x2 be the signal sampled at 3 kHz.
clc
clear all
close all
f = 2000;
T = 1/f;
tmin = 0;
tmax = 5*T; % for 5 cycles of given sinusoid
dt = 1/40000; fsim=1/dt;
dt1 = 1/10000; fs1=1/dt1; %over sampling
dt2 = 1/3000; fs2=1/dt2; %under sampling
t = tmin:dt:tmax;
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);
%*********************************************************************
clc
clear all
close all
Fs = 7000; % sampling frequency
% change sampling frequency to observe the effects of under sampling
% (Aliasing) and over sampling
f=1000;
% change signal frequency and analyze the output
Tmax = 10;
time = 0:1/Fs:Tmax;
omega = 2*pi*f; % signal frequency f Hz
signal = 10*sin(omega*time) + rand(1,Tmax*Fs+1);
Nfft = 2^8;
[Pxx,freq] = pwelch(signal,Nfft,[],[],Fs)%computing power spectral density
plot(freq,Pxx)
xlabel('frequency in hz');
ylabel('power P')
title('Signal PSD')
% frequency domain view
% Compute the frequency response
w1=-Fs/2:Fs/1024Fs/2)-1/1024
S = fftshift(fft(signal,1024));
figure
plot(w1,abs(S));grid
xlabel('Frequency in hz');
ylabel('Signal Amplitude A')
Kindly comment about it and explain this
Oversampling
Under sampling (Aliasing)
Run the codes given below and prepare a lab report max 2 pages based on your understanding of code and different sampling effects. Comment on the out and how it varies by changing different parameters in the given code
% Sample the sinusoid x = sin(2 pi f t), where f = 2 kHz, and plot the sampled
% signals over the continuous-time signal.
% Let x1 be the signal sampled at 10 kHz.
% Let x2 be the signal sampled at 3 kHz.
clc
clear all
close all
f = 2000;
T = 1/f;
tmin = 0;
tmax = 5*T; % for 5 cycles of given sinusoid
dt = 1/40000; fsim=1/dt;
dt1 = 1/10000; fs1=1/dt1; %over sampling
dt2 = 1/3000; fs2=1/dt2; %under sampling
t = tmin:dt:tmax;
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);
%*********************************************************************
clc
clear all
close all
Fs = 7000; % sampling frequency
% change sampling frequency to observe the effects of under sampling
% (Aliasing) and over sampling
f=1000;
% change signal frequency and analyze the output
Tmax = 10;
time = 0:1/Fs:Tmax;
omega = 2*pi*f; % signal frequency f Hz
signal = 10*sin(omega*time) + rand(1,Tmax*Fs+1);
Nfft = 2^8;
[Pxx,freq] = pwelch(signal,Nfft,[],[],Fs)%computing power spectral density
plot(freq,Pxx)
xlabel('frequency in hz');
ylabel('power P')
title('Signal PSD')
% frequency domain view
% Compute the frequency response
w1=-Fs/2:Fs/1024Fs/2)-1/1024
S = fftshift(fft(signal,1024));
figure
plot(w1,abs(S));grid
xlabel('Frequency in hz');
ylabel('Signal Amplitude A')
Kindly comment about it and explain this