The following code works very will except for the output is off by a factor of 10:
%// Part 3: Discrete-Time Signal Sampling and Recovery
%// Original and Sampling
W = -3:.1:3;
W_for_X = -30:30;
H = zeros(size(W));
H(23:37) = 4;
nA = -30:.1:30;
xnA = cos(.1*pi*nA)-(4*sin(.2*pi*nA));
n = -30:30;
xn = zeros(size(n));
remB = rem(n,4)==0;
xn(remB) = cos(.1*pi*n(remB))-(4*sin(.2*pi*n(remB)));
I'm pretty sure that the problem is not with the W
and W_for_X
part of the coding. However I'm not sure how to check. I've tried to re-scale both values but as they must scale linearly with each other (do to a correlation needed for the matrix multiplication) I don't think that the problem is here.
I have a feeling that the problem lies within the N = 4
and n = -30:30
. It would be nice if N
would stay at 4 because changing this number by a factor of ten didn't seem to solve the problem.
Since the H
and Xw
are multiplied together n
must scale with W
and W_for_X
.
It is apparent that the output of this code is off by a factor of ten given as follows:
The red output on the graph of the left should at least looks similar (which it does) to the graph on the right. The question is this what part of the code made the output ten times smaller and how can I fix it?
Side note: the value xn
is put into a trapz
function and then multiplied by H
. The resulting value is then put into one more trapz
function and then displayed. This part of the code is more or less a hold over from another code I have written and I have checked these parts and I'm pretty sure the problem isn't there. If you think it is feel free to say.
EDIT/CLARIFY - 1
The input is the blue plot on the left which is xnA
. Red dotted plot on the left is the sample xn
taken of the input. The red plot on the left is the output given by a variable y
which was not included in the original code.
To clarify the red plot on the left should resemble the blue plot on the right. Though it is a bit sharper it does have the same basic shape.
You have to look at the numbers on the X-axis
of the graph in order to see a difference. Though one looks the same, it happens at frequency of 1:10 (from left blue to right red) which is to say that it goes from -30:30
verses -3:3
another picture of the graph where the red output is laid upon the blue input is shown here:
The code that made this image is here:
figure(1);
subplot(1,2,1);plot(nA,xnA,n,xn,'r--o');
subplot(1,2,2);plot(nA,xnA,W,y,'r');
A Fourier transform is performed upon xn
moving it to the frequency domain then it is .*
by H
and the product of that is then inverse Fourier transformed back into the time domain and plotted. Is there something about the way I plotted this that would shrink the x-axis?
replace
W
by
W_for_X
in the line plot(nA,xnA,W,y,'r')
doing the plot.