regzarr

lab9

Apr 6th, 2021 (edited)
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 2.17 KB | None | 0 0
  1. function [V] = audioeq(inputPath, outputPath, Q)
  2.  
  3. [Y, FS] = audioread(inputPath);
  4.  
  5. Z = Y;
  6.  
  7. freqC1 = 60; % Hz
  8. freqC2 = 230;
  9. freqC3 = 910;
  10. freqC4 = 4000;
  11. freqC5 = 14000;
  12.  
  13. freqL1 = freqC1 * ( (-1) / (2 * Q) + sqrt(1 + (1 / 4 * Q ^ 2)));
  14. freqL2 = freqC2 * ( (-1) / (2 * Q) + sqrt(1 + (1 / 4 * Q ^ 2)));
  15. freqL3 = freqC3 * ( (-1) / (2 * Q) + sqrt(1 + (1 / 4 * Q ^ 2)));
  16. freqL4 = freqC4 * ( (-1) / (2 * Q) + sqrt(1 + (1 / 4 * Q ^ 2)));
  17. freqL5 = freqC5 * ( (-1) / (2 * Q) + sqrt(1 + (1 / 4 * Q ^ 2)));
  18.  
  19. freqU1 = freqC1 * ( 1 / (2 * Q) + sqrt(1 + (1 / 4 * Q ^ 2)));
  20. freqU2 = freqC2 * ( 1 / (2 * Q) + sqrt(1 + (1 / 4 * Q ^ 2)));
  21. freqU3 = freqC3 * ( 1 / (2 * Q) + sqrt(1 + (1 / 4 * Q ^ 2)));
  22. freqU4 = freqC4 * ( 1 / (2 * Q) + sqrt(1 + (1 / 4 * Q ^ 2)));
  23. freqU5 = freqC5 * ( 1 / (2 * Q) + sqrt(1 + (1 / 4 * Q ^ 2)));
  24.  
  25. normFL1 = freqL1 / (FS / 2);
  26. normFL2 = freqL2 / (FS / 2);
  27. normFL3 = freqL3 / (FS / 2);
  28. normFL4 = freqL4 / (FS / 2);
  29. normFL5 = freqL5 / (FS / 2);
  30.  
  31. normFU1 = freqU1 / (FS / 2);
  32. normFU2 = freqU2 / (FS / 2);
  33. normFU3 = freqU3 / (FS / 2);
  34. normFU4 = freqU4 / (FS / 2);
  35. normFU5 = freqU5 / (FS / 2);
  36.  
  37. bw1 = freqC1 / Q;
  38. bw2 = freqC2 / Q;
  39. bw3 = freqC3 / Q;
  40. bw4 = freqC4 / Q;
  41. bw5 = freqC5 / Q;
  42.  
  43. nOrder = 40;
  44.  
  45. [filt1Num, filt1Den] = fir1(nOrder, normFU1, 'low');
  46. [filt2Num, filt2Den] = fir1(nOrder, [normFL2 normFU2], 'bandpass');
  47. [filt3Num, filt3Den] = fir1(nOrder, [normFL3 normFU3], 'bandpass');
  48. [filt4Num, filt4Den] = fir1(nOrder, [normFL4 normFU4], 'bandpass');
  49. [filt5Num, filt5Den] = fir1(nOrder, normFL5, 'high');
  50.  
  51. [H1, W1] = freqz(filt1Num, filt1Den);
  52. [H2, W2] = freqz(filt2Num, filt2Den);
  53. [H3, W3] = freqz(filt3Num, filt3Den);
  54. [H4, W4] = freqz(filt4Num, filt4Den);
  55. [H5, W5] = freqz(filt5Num, filt5Den);
  56.  
  57. figure;
  58. plot(W1 / pi, abs(H1), W2 / pi, abs(H2), W3 / pi, abs(H3), W4 / pi, abs(H4), W5 / pi, abs(H5));
  59. xlabel('Normalized Frequency');
  60. ylabel('Magnitude');
  61. title('Frequency response of invidual filters');
  62.  
  63. sumH = abs(H1) + abs(H2) + abs(H3) + abs(H4) + abs(H5);
  64. figure;
  65. plot(W1 / pi, 20 * log10(sumH));
  66. xlabel('Normalized Frequency');
  67. ylabel('20 log10(Mag)');
  68. title('Frequency response of sum of filters');
  69.  
  70. audiowrite(outputPath, Z, FS);
  71.  
  72. end
Add Comment
Please, Sign In to add comment