-
Notifications
You must be signed in to change notification settings - Fork 0
/
lab_10.asv
88 lines (65 loc) · 1.92 KB
/
lab_10.asv
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
close all;
clc;
clearvars;
%%
syms t k
% Original Signal
f0 = 10;
original_signal = sin(2*pi*f0*t);
% Impulse Train for Sampling
Fs = 20;
N = 201;
k_values = linspace(0,1,N);
sampled_signal = zeros(size(k_values));
impulse_train_plot = zeros(size(k_values));
% sample the original using Impulse Train
for i = 1:length(k_values)
% Create an impulse train using the heaviside function
impulse_train = heaviside(t-k_values(i)/Fs);
impulse_train_plot(i) = double(subs(impulse_train,t,k_values(i)));
% Evaluate the product of original_signal and impulse_train
sampled_signal_sym = subs(original_signal * impulse_train,t,k_values(i));
% Convert the symbolic expression to double
sampled_signal(i) = double(sampled_signal_sym);
end
dft_of_sample = abs(fftshift(fft(sampled_signal))) / N;
fft_time = linspace(-f0,f0,N);
% Plot the results
figure;
subplot(4, 1, 1);
fplot(original_signal, [0, 1]);
title('Original Signal');
subplot(4,1,2);
stem(k_values,impulse_train_plot);
title("Impulse_ Train");
subplot(4,1,3);
stem(k_values,sampled_signal);
title("Sampled Signal");
subplot(4,1,4);
plot(fft_time,dft_of_sample);
title("dft of sample");
%%
up=2;
down=2;
upsampled_signal = upsample(sampled_signal,up);
downsampled_signal = downsample(sampled_signal,down);
up_lenght = length(upsampled_signal);
down_lenght = length(downsampled_signal);
dft_of_upsample = abs(fftshift(fft(upsampled_signal))) / N;
dft_of_downsample = abs(fftshift(fft(downsampled_signal))) / N;
up_time = linspace(0,450,length(upsampled_signal));
down_time = linspace(0,100,length(downsampled_signal));
forier_time = -100:20:1*
figure;
subplot(2,2,1);
stem(down_time,downsampled_signal);
title("downsampled signal");
subplot(2,2,2);
stem(up_time,upsampled_signal);
title("upsampled signal");
subplot(2,2,3);
plot(forier_time,dft_of_downsample);
title("DFT of downsample")
subplot(2,2,4);
plot(forier_time,dft_of_upsample);
title("DFT of upsample");