Code-m file for Sampling

조회 수: 220 (최근 30일)
Chetan Fadnis
Chetan Fadnis 2021년 9월 19일
답변: Adel 2024년 9월 23일
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
  댓글 수: 2
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
Sushilkumar
Sushilkumar 2024년 5월 6일
% Sampling Theorem
clc;
clear all;
t = -100:0.01:100;
T=30;
fm = 1/T;
x = cos(2*pi*fm*t);
subplot(2,2,1);
plot(t,x);
grid on;
xlabel('Time in seconds');
xlabel('x(t)');
title('Continuous time signal');
fs1 = 1.6*fm;
n1 = -5:1:5;
xn1 = cos(2*pi*n1*fm/fs1);
subplot(2,2,2);
stem(n1,xn1);
hold on;
plot(n1, xn1);
grid on;
xlabel('Time in seconds');
xlabel('x(t)');
title('Discrete time signal with fs1<2fm');
fs2 = 2*fm;
n2 = -5:1:5;
xn2 = cos(2*pi*n2*fm/fs2);
subplot(2,2,3);
stem(n2,xn2);
hold on;
plot(n2, xn2);
grid on;
xlabel('Time in seconds');
xlabel('x(t)');
title('Discrete time signal with fs2 = 2fm');
fs3 = 8*fm;
n3 = -20:1:20;
xn3 = cos (2*pi*n3*fm/fs3);
subplot(2,2,4);
stem(n3,xn3);
hold on;
plot(n3, xn3);
grid on;
xlabel('Time in seconds');
xlabel('x(t)');
title('Discrete time signal with fs1 > 2fm');
sampling

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

추가 답변 (2개)

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

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


Adel
Adel 2024년 9월 23일
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')

카테고리

Help CenterFile Exchange에서 Spectral Measurements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by