Code-m file for Sampling

219 次查看(过去 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
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