What Is Wrong With My Code? (Downsampling Of A Sinc Signal)

1 vue (au cours des 30 derniers jours)
cikalekli
cikalekli le 22 Mar 2022
Modifié(e) : Paul le 23 Mar 2022
Hi, I'm studying on my own about downsampling the signals on matlab.
Before exhibit my code which I wrote, I've curiosity questions below about my code.
I'm a self learner, so if anyone else could help me to understand. That would be glamorous.
1) How can I find the downsampling of my code?
2) How can I create a discrete time sinusoidal signal of a preferred frequency and decimate it?
Here is my code mentioned before which I wrote it:
N = 30;
n= 0:N;
x1 = sinc(n/6);
subplot(221);
stem(n,x1);
grid;
title('original signal');
xlabel('sample');
m = 2;
x2 = x1(1:m:length(x1));
m = 0:m:N;
subplot(222);
stem(m,x2);
grid;
title('decimated signal');
xlabel('sample');
f1=0:0.1:3; %frequency values
f2=0:0.4:6; %new frequency values
X1 = abs(fft(x1));
subplot(223);
stem(f1,X1);
title('input spectrum');
xlabel('frequency(Hz)');
X2 = abs(fft(x2));
subplot(224);
stem(f2,X2);
title('output spectrum');
xlabel('frequency(Hz)');
Here is my output:

Réponse acceptée

Paul
Paul le 22 Mar 2022
Modifié(e) : Paul le 23 Mar 2022
I'm not sure what you're trying to show, but I can see at least one issue in the code that needs to be considered. Maybe looking for something like this:
N = 30; % Length of the original sequence
n = 0:N-1; % note the N-1 so that n has 30 samples
x1 = sinc(n/6); % define the original sequence
Fs = 3; % it looks like this should be the sampling frequency
subplot(231);
stem(n,x1);
grid;
title('original signal');
xlabel('sample');
M = 2; % downsampling factor
x2 = x1(1:M:length(x1)); % the downsampled signal. Could also use x2 = downsample(x1,M)
Up to this point, there are no problems. However, the next line is problematic. In discrete time the independent variable has to cover all integers, but this definition of the values of m that correspond to the values of x2 are only even values of the independent variable, which is against the rules so to speak
m = 0:M:N;
After downsampling, the indices the correspond to x2 are really
m = 0:(numel(x2)-1);
and it is the indices of m as defned here that will be used in the DFT computation in fft(x2).
subplot(232);
stem(m,x2);
grid;
title('decimated signal');
xlabel('sample');
Now we can go to the frequency domain
X1 = abs(fft(x1));
f1 = (0:numel(X1)-1)/numel(X1)*Fs;
subplot(234);
stem(f1,X1);
title('input spectrum');
xlabel('frequency(Hz)');
X2 = abs(fft(x2));
f2 = (0:numel(X2)-1)/numel(X2)*Fs/M; % by downsampling, we increased the sampling period, which decreases the sampling frequency
subplot(235);
stem(f2,X2);
title('output spectrum');
xlabel('frequency(Hz)');
Now, we can upsample the down-sampled signal
x3 = upsample(x2,M);
subplot(233)
stem(n,x3);
grid
xlabel('sample')
title('upsampled output')
And its DFT
X3 = abs(fft(x3));
f3 = f1;
subplot(236)
stem(f3,X3);
xlabel('frequency(Hz)')
title('upsampled spectrum')

Plus de réponses (0)

Tags

Produits


Version

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by