Advertisement
Guest User

banana

a guest
Nov 27th, 2014
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.21 KB | None | 0 0
  1. %%Problem 2
  2.  
  3. % b)We wish to find the error in reconstruction. To do that we firstly need
  4. % to find the second norm of f(t). By applying Parseval's theorem we can
  5. % compute this as the area under the FT of f(t) squared.
  6. normF = 2 * integral(@(x) (8000 - 4*x).^2, 0, 2000);
  7. %Know we need to find the norm of the difference in a similar matter
  8. part1 = 2 * integral (@(x) ( (8000-4*x)-(1600) ).^2, 1600, 1800);
  9. part2 = 2 * integral (@(x) (8000-4*x).^2, 1800, 2000);
  10. normDiff = part1 + part2;
  11. %now we can express the error as shown below
  12. relativeError = normDiff/normF;
  13.  
  14. % c) We limit f(t) within frequnecy components between -1800 and 1800
  15. % (apply low-pass). We recalcualte the error for this new signal in a
  16. % similar way as before.
  17. normDiffC = temp2;
  18. relativeErrorC = normDiffC / normF;
  19.  
  20. %d)To avoid the effects of aliasing it would be better to filter the signal
  21. %f(t) with a lowpass (with cut-off frequncy ws=1800). The effects of this
  22. %in the reconstructed signal are shown above, and as we noticed, are better
  23. %then suffering the aliasing effect.
  24. %% Problem 3
  25.  
  26. f = @(t) (cos(30*pi.*t)+ sin(40*pi.*t) - 2*cos(20*pi.*t));
  27. %According to the Nyquist criteria we need 8 samples per period to properly
  28. %sample this signal, but since there is a sin component in it, we need to
  29. %chose any rate higehr then this for proper sampling (say 16 samples per
  30. %period) T=0.2s, we chose N=16.
  31.  
  32. t=0:0.0125:15*0.0125;
  33. x=f(t);
  34. f=0.2/16*fft(x); %We multiply by T/N
  35. w=0:10*pi:150*pi;
  36. subplot(1,2,1);
  37. stem(w,real(f));
  38. hold
  39. stem(w,imag(f),'r');
  40. title ('Imaginary and Real part of FT Y');
  41. xlabel ('w, rad/s');
  42. ylabel('Y, Volts');
  43. subplot(1,2,2);
  44. stem(w,abs(f));
  45. title ('Abs part FT Y');
  46. xlabel ('w, rad/s');
  47. ylabel('Y, Volts');
  48. %We can see from the graphs that we have properly reconstructed the FT of
  49. %the signal from its DFT
  50. %% Problem 4
  51. %Our signla is trumcated between -5 and 5 (outside is zero). We assume this
  52. %signal repeats periodically outside this bounds.
  53. N=71 %We chose this N to achieve a point-wise errer less than 0.05.
  54. t1=0:10/N:5;
  55. t2=t1(2:length(t1));
  56. t2=fliplr(t2);
  57. t=[t1,t2];
  58. x=exp(-abs(t));
  59. y=10./N*fft(x,N);
  60. k=0:round(N/2)-1;
  61. f1=2./(1+(k*pi./5).^2);
  62. f2=f1(2:length(f1));
  63. f2=fliplr(f2);
  64. f=[f1,f2];
  65. err=norm(y-f)./N^0.5;
  66. %% Problem 5
  67. N=41 %We use this sampling rate
  68. t1=0:10/N:5;
  69. t2=t1(2:length(t1));
  70. t2=fliplr(t2);
  71. t=[t1,t2];
  72. x=sinc(t);
  73. y=10./N*fft(x,N);
  74. k=0:round(N/2)-1;
  75. f1=rectangularPulse((-pi+0.01),(pi+0.01),(k*pi/5));
  76. %We have to define a wider pulse, becasue of the matlab implementation
  77. %This will not effect the result however
  78. f2=f1(2:length(f1));
  79. f2=fliplr(f2);
  80. f=[f1,f2];
  81. err=norm(y-f)./N^0.5;
  82. %We can' reconstruct the signla's FT from its DFT no matter how many
  83. %samples we take, because the signal is not periodic in time domain
  84. %% Problem 6
  85. N=200001;%We need to take roughly this many samples, to have an erro less then 0.01
  86. t1=0:(3*pi)/N:3*pi/2;
  87. t2=t1(2:length(t1));
  88. t2=fliplr(t2);
  89. t=[t1,t2];
  90. x=cos(t);
  91. helper = @(w) sin(3*pi.*w./2)./w;
  92. F = @(k) helper(2.*k./3 -1) + helper(2.*k./3 +1);
  93. y=10./N*fft(x,N);
  94. k=0:round(N/2)-1;
  95. f1=F(k);
  96. f2=f1(2:length(f1));
  97. f2=fliplr(f2);
  98. f=[f1,f2];
  99. err=norm(y-f)./N^0.5;
  100. %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