Code-m file for Sampling

조회 수: 222 (최근 30일)
Chetan Fadnis
Chetan Fadnis 2021년 9월 19일
댓글: VBBV 2022년 1월 28일
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.

채택된 답변

VBBV
VBBV 2022년 1월 28일
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
VBBV
VBBV 2022년 1월 28일
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

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2021년 9월 19일
Could pl., show what you have done so far?
  댓글 수: 1
Chetan Fadnis
Chetan Fadnis 2021년 9월 19일
% 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

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 AI for Signals에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by