Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %%Problem 2
- % b)We wish to find the error in reconstruction. To do that we firstly need
- % to find the second norm of f(t). By applying Parseval's theorem we can
- % compute this as the area under the FT of f(t) squared.
- normF = 2 * integral(@(x) (8000 - 4*x).^2, 0, 2000);
- %Know we need to find the norm of the difference in a similar matter
- part1 = 2 * integral (@(x) ( (8000-4*x)-(1600) ).^2, 1600, 1800);
- part2 = 2 * integral (@(x) (8000-4*x).^2, 1800, 2000);
- normDiff = part1 + part2;
- %now we can express the error as shown below
- relativeError = normDiff/normF;
- % c) We limit f(t) within frequnecy components between -1800 and 1800
- % (apply low-pass). We recalcualte the error for this new signal in a
- % similar way as before.
- normDiffC = temp2;
- relativeErrorC = normDiffC / normF;
- %d)To avoid the effects of aliasing it would be better to filter the signal
- %f(t) with a lowpass (with cut-off frequncy ws=1800). The effects of this
- %in the reconstructed signal are shown above, and as we noticed, are better
- %then suffering the aliasing effect.
- %% Problem 3
- f = @(t) (cos(30*pi.*t)+ sin(40*pi.*t) - 2*cos(20*pi.*t));
- %According to the Nyquist criteria we need 8 samples per period to properly
- %sample this signal, but since there is a sin component in it, we need to
- %chose any rate higehr then this for proper sampling (say 16 samples per
- %period) T=0.2s, we chose N=16.
- t=0:0.0125:15*0.0125;
- x=f(t);
- f=0.2/16*fft(x); %We multiply by T/N
- w=0:10*pi:150*pi;
- subplot(1,2,1);
- stem(w,real(f));
- hold
- stem(w,imag(f),'r');
- title ('Imaginary and Real part of FT Y');
- xlabel ('w, rad/s');
- ylabel('Y, Volts');
- subplot(1,2,2);
- stem(w,abs(f));
- title ('Abs part FT Y');
- xlabel ('w, rad/s');
- ylabel('Y, Volts');
- %We can see from the graphs that we have properly reconstructed the FT of
- %the signal from its DFT
- %% Problem 4
- %Our signla is trumcated between -5 and 5 (outside is zero). We assume this
- %signal repeats periodically outside this bounds.
- N=71 %We chose this N to achieve a point-wise errer less than 0.05.
- t1=0:10/N:5;
- t2=t1(2:length(t1));
- t2=fliplr(t2);
- t=[t1,t2];
- x=exp(-abs(t));
- y=10./N*fft(x,N);
- k=0:round(N/2)-1;
- f1=2./(1+(k*pi./5).^2);
- f2=f1(2:length(f1));
- f2=fliplr(f2);
- f=[f1,f2];
- err=norm(y-f)./N^0.5;
- %% Problem 5
- N=41 %We use this sampling rate
- t1=0:10/N:5;
- t2=t1(2:length(t1));
- t2=fliplr(t2);
- t=[t1,t2];
- x=sinc(t);
- y=10./N*fft(x,N);
- k=0:round(N/2)-1;
- f1=rectangularPulse((-pi+0.01),(pi+0.01),(k*pi/5));
- %We have to define a wider pulse, becasue of the matlab implementation
- %This will not effect the result however
- f2=f1(2:length(f1));
- f2=fliplr(f2);
- f=[f1,f2];
- err=norm(y-f)./N^0.5;
- %We can' reconstruct the signla's FT from its DFT no matter how many
- %samples we take, because the signal is not periodic in time domain
- %% Problem 6
- N=200001;%We need to take roughly this many samples, to have an erro less then 0.01
- t1=0:(3*pi)/N:3*pi/2;
- t2=t1(2:length(t1));
- t2=fliplr(t2);
- t=[t1,t2];
- x=cos(t);
- helper = @(w) sin(3*pi.*w./2)./w;
- F = @(k) helper(2.*k./3 -1) + helper(2.*k./3 +1);
- y=10./N*fft(x,N);
- k=0:round(N/2)-1;
- f1=F(k);
- f2=f1(2:length(f1));
- f2=fliplr(f2);
- f=[f1,f2];
- err=norm(y-f)./N^0.5;
- %You can replace N=7 in this code to simualte a samplin with rate T=pi/2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement