Code-m file for Sampling

215 views (last 30 days)
Chetan Fadnis
Chetan Fadnis on 19 Sep 2021
Commented: VBBV on 28 Jan 2022
Write a MATLAB code to
1) Generate a band limited signal (at extremely high sampling rate to approximate it as a continuous signal)
2) Plot the signal in Time Domain.
3) Take the FFT of the signal and plot the magnitude and phase of the signal spectrum and show it is a bandlimited signal.
4) Generate an impulse train at an appropriate sampling rate using DFS and show that its FFT is again an impulse train.
5) Using the signal and impulse train generated in (1) and (4), produce sampled signal by multiplying the two and apply FFT.
6) Display the sampled signal and its spectrum.
7) Reconstruct the original signal from its sampled value using sinc (interpolation) filter and display the same.

Accepted Answer

VBBV
VBBV on 28 Jan 2022
clear all
close all
% Creating modulating signal
fm=2; % message signal frequency (Hz)
n=50; % factor of sampling frequency
K=1000;
Ts=1/(n*fm); % sampling time
t=0:Ts:100-Ts; % time range
N=size(t,2);
Fs=1/Ts; % sampling frequency
dFs=Fs/N;
f=-Fs/2:dFs:Fs/2-dFs;
m=2*cos(2*pi*fm*t); % message signal
subplot(5,1,1);
plot(t,m);
xlabel('Time(in s)');
title('Modulating signal');
% Frequency Domain
M=fftshift(fft(m)); % FFT of the message signal
subplot(5,1,2)
plot(f,abs(M)/N);
xlabel('Frequency(in hertz)');
title('Magnitude response');
%sound(X)
% Pulse train generation
T=0.2; %sampling interval
F=1/T; % sapling frequency
h=zeros(1,length(t)); % initialize all values to zero
for k=-K:1:K
h=h+(1/T)*cos(2*pi*k*F*t);
end
h_a=T*h/(2*K+1); % scaling
subplot(5,1,3);
plot(t,h_a);
xlabel('Time(s)');
title('Pulse train');
% sampling
m_samp=m.*h_a;
N_samp=length(m_samp);
subplot(5,1,4);
plot(t,m_samp);% add the plot function
xlabel('Time(in s)');
title('Sampled value');
% Magnitude response of sampled signal
M_samp=fftshift(fft(m_samp));
subplot(5,1,5)
plot(f,abs(M_samp)/N_samp);
xlabel('Frequency(in hertz)');
title('Magnitude response')
You forgot to use plot function. Check with this
m_samp=m.*h_a;
N_samp=length(m_samp);
subplot(5,1,4);
plot(t,m_samp);% add the plot
  1 Comment
VBBV
VBBV on 28 Jan 2022
M_samp=fftshift(fft(m_samp));
H = sinc(M_samp)./N_samp;
G = filter(H,1,t);
plot(f,G)
Add this to reconstruct the sampled signal

Sign in to comment.

More Answers (1)

Sulaymon Eshkabilov
Sulaymon Eshkabilov on 19 Sep 2021
Could pl., show what you have done so far?
  1 Comment
Chetan Fadnis
Chetan Fadnis on 19 Sep 2021
% Sampling and Reconstruction
clc
clear all
close all
% Creating modulating signal
fm=2; % message signal frequency (Hz)
n=50; % factor of sampling frequency
K=1000;
Ts=1/(n*fm); % sampling time
t=0:Ts:100-Ts; % time range
N=size(t,2);
Fs=1/Ts; % sampling frequency
dFs=Fs/N;
f=-Fs/2:dFs:Fs/2-dFs;
m=2*cos(2*pi*fm*t); % message signal
subplot(5,1,1);
plot(t,m);
xlabel('Time(in s)');
title('Modulating signal');
% Frequency Domain
M=fftshift(fft(m)); % FFT of the message signal
subplot(5,1,2)
plot(f,abs(M)/N);
xlabel('Frequency(in hertz)');
title('Magnitude response');
%sound(X)
% Pulse train generation
T=0.2; %sampling interval
F=1/T; % sapling frequency
h=zeros(1,length(t)); % initialize all values to zero
for k=-K:1:K
h=h+(1/T)*cos(2*pi*k*F*t);
end
h_a=T*h/(2*K+1); % scaling
subplot(5,1,3);
plot(t,h_a);
xlabel('Time(s)');
title('Pulse train');
% sampling
m_samp=m.*h_a;
N_samp=length(m_samp);
subplot(5,1,4);
xlabel('Time(in s)');
title('Sampled value');
% Magnitude response of sampled signal
M_samp=fftshift(fft(m_samp));
subplot(5,1,5)
plot(f,abs(M_samp)/N_samp);
xlabel('Frequency(in hertz)');
title('Magnitude response')
Finding difficulty in Reconstruction part

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!