Advertisement
NullChips

Untitled

Mar 3rd, 2021
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. samplingRate = 48000;
  2. width = 550;
  3. cutoff = 1500;
  4. ripple = -80;
  5. A = -ripple;
  6.  
  7. transitionWidthNorm = 2 * pi * width / samplingRate;
  8. cutoffNorm = cutoff / samplingRate;
  9.  
  10.  
  11.  
  12. nTemp = (A - 7.95) / (2.285 * transitionWidthNorm);
  13. N = ceil(nTemp);
  14.  
  15. if(mod(N, 2) == 0)
  16. N = N + 1;
  17. end
  18.  
  19.  
  20. beta = 0.1102 * (A - 8.7);
  21.  
  22.  
  23.  
  24. %Working out window starts here.
  25. hN = (N - 1) / 2;
  26. n= -hN : hN;
  27.  
  28.  
  29. wd = kaiser(N, beta)';
  30. hd = 2 * cutoffNorm * sin(2 * pi * cutoffNorm * n)./(n * 2 * pi * cutoffNorm);
  31. hd(hN+1) = 2 * cutoffNorm;
  32.  
  33.  
  34. hdw = hd.*wd;
  35.  
  36. %Working out window ends here.
  37.  
  38. lowpassFile = fopen('LowPassCoef.asm', 'w');
  39. for c = 1 : N
  40. fprintf(lowpassFile, 'lpcoef_%d\tdc\t%1.8f\n', c, hdw(c));
  41. end
  42. fclose(lowpassFile);
  43.  
  44. %Start working out high pass filter here.
  45.  
  46. transitionWidthNorm = 2 * pi * width / samplingRate;
  47. cutoffNorm = cutoff / samplingRate;
  48.  
  49.  
  50.  
  51. nTemp = (A - 7.95) / (2.285 * transitionWidthNorm);
  52. N = ceil(nTemp);
  53.  
  54. if(mod(N, 2) == 0)
  55. N = N + 1;
  56. end
  57.  
  58.  
  59. beta = 0.1102 * (A - 8.7);
  60.  
  61.  
  62.  
  63. %Working out window starts here.
  64. hN = (N - 1) / 2;
  65. n= -hN : hN;
  66.  
  67.  
  68. wd = kaiser(N, beta)';
  69. hd = -2 * cutoffNorm * sin(2 * pi * cutoffNorm * n)./(n * 2 * pi * cutoffNorm);
  70. hd(hN+1) = 1 - (2 * cutoffNorm);
  71.  
  72.  
  73. hdw = hd.*wd;
  74.  
  75. %Working out window ends here.
  76.  
  77. %Plot graphs of high pass filter.
  78. figure(1)
  79. subplot(3, 1, 1), plot(n, hd);
  80. subplot(3, 1, 2), plot(n, wd);
  81. subplot(3, 1, 3), plot(n, hdw);
  82. [h1,w] = freqz(hd,1,4096,samplingRate);
  83. [h2,w] = freqz(hdw,1,4096,samplingRate);
  84. figure(2)
  85. subplot(2,1,1)
  86. plot(w,20*log10(abs(h1)),w,20*log10(abs(h2)))
  87. subplot(2,1,2)
  88. plot(w,unwrap(angle(h1)),w,unwrap(angle(h2)))
  89.  
  90. highPassFile = fopen('HighPassCoef.asm', 'w');
  91. for c = 1 : N
  92. fprintf(highPassFile, 'hpcoef_%d\tdc\t%1.8f\n', c, hdw(c));
  93. end
  94. fclose(highPassFile);
  95.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement