Advertisement
Guest User

Untitled

a guest
Dec 10th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 2.32 KB | None | 0 0
  1.  
  2. close all;
  3. clear;
  4. clc;
  5.  
  6. fs=8000;
  7. M=50;
  8. fc = fs/4;
  9. Wc = 0.5;
  10.  
  11. h_lp = fir1(M, Wc, 'low');
  12. H_len_half = ceil(length(h_lp)/2);
  13.  
  14. if mod(H_len_half, 2) == 0
  15.   mask = [-1;1];
  16. else
  17.   mask = [1;-1];
  18. end
  19.  
  20. mask = repmat(mask, H_len_half);
  21. mask = mask(1:length(h_lp));
  22.  
  23. h_hp = h_lp .* mask;
  24.  
  25. a=1;
  26. b=h_hp;
  27.  
  28. figure();
  29. freqz(b,a);
  30. figure();
  31. impz(b,a);
  32.  
  33. b_hp = h_hp;
  34. b_lp = h_lp;
  35.  
  36. sig=loadbin("s0001.bin");
  37.  
  38. % HP filt
  39. y_hp=filter(b,a,sig);
  40. figure();
  41. subplot(211);
  42. spectrogram(y_hp,256,[],[],'yaxis');
  43. colormap jet;
  44. title("HP");
  45. % DP filt
  46. y_lp=filter(h_lp,a,sig);
  47. subplot(212);
  48. spectrogram(y_lp,256,[],[],'yaxis');
  49. colormap jet;
  50. title("LP");
  51.  
  52. y_rekonst_2=y_lp+y_hp; % secteni filtrovanych signalu pro dalsi ucely
  53.  
  54. y_dec_hp=y_hp(1:2:length(y_hp));
  55. y_dec_lp=y_lp(1:2:length(y_lp));
  56.  
  57. % HP decim. plot
  58. figure();
  59. subplot(211);
  60. spectrogram(y_dec_hp,128,[],[],'yaxis');
  61. colormap jet;
  62. title("HP decimated");
  63. % DP decim. plot
  64. subplot(212);
  65. spectrogram(y_dec_lp,128,[],[],'yaxis');
  66. colormap jet;
  67. title("LP decimated");
  68.  
  69. % naplneni nulami
  70. y_dec_hp_0s = zeros(1, 2*length(y_dec_hp));
  71. y_dec_lp_0s = zeros(1, 2*length(y_dec_lp));
  72. y_dec_hp_0s(1:2:end) = y_dec_hp;
  73. y_dec_lp_0s(1:2:end) = y_dec_lp;
  74.  
  75. % HP decim. plot
  76. figure();
  77. subplot(211);
  78. spectrogram(y_dec_hp_0s,256,[],[],'yaxis');
  79. colormap jet;
  80. title("interpol. HP");
  81. % DP decim. plot
  82. subplot(212);
  83. spectrogram(y_dec_lp_0s,256,[],[],'yaxis');
  84. colormap jet;
  85. title("LP");
  86.  
  87. % filtrace
  88. y_dec_hp_filt=filter(b_hp,a,y_dec_hp_0s);
  89. y_dec_lp_filt=filter(b_lp,a,y_dec_lp_0s);
  90. y_rekonst=2*(y_dec_hp_filt+y_dec_lp_filt);
  91.  
  92. figure();
  93. subplot(211);
  94. spectrogram(y_rekonst,256,[],[],'yaxis');
  95. colormap jet;
  96. title("Rekonstruovany");
  97. subplot(212);
  98. spectrogram(sig,256,[],[],'yaxis');
  99. colormap jet;
  100. title("puvodni");
  101.  
  102. figure();
  103. plot(sig);
  104. hold on;
  105. plot(y_rekonst);
  106. hold off;
  107.  
  108. % vypocet SNR
  109. figure();
  110. posuv=M;
  111. sig=sig(:);
  112. y_rekonst=y_rekonst(:);
  113. sig_a=sig(1:end-posuv);
  114. sig_b=y_rekonst(posuv+1:end-1);
  115. error=sig_b-sig_a;
  116. plot(error);
  117. pow_a = mean(sig_a.^2);
  118. pow_error = mean(error.^2);
  119.  
  120. snr=10*log10(pow_a/pow_error)
  121.  
  122. % vypocet signalu bez decimace a interpolace
  123. posuv = M/2;
  124. sig_a=sig(1:end-posuv);
  125. sig_b=y_rekonst_2(posuv+1:end);
  126. error=sig_b-sig_a;
  127. plot(error);
  128. pow_a = mean(sig_a.^2);
  129. pow_error = mean(error.^2);
  130. snr2=10*log10(pow_a/pow_error)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement