Code-m file for Sampling
241 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
采纳的回答
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
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
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 个)
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')
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spectral Measurements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!