Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function [V] = audioeq(inputPath, outputPath, Q)
- [Y, FS] = audioread(inputPath);
- Z = Y;
- freqC1 = 60; % Hz
- freqC2 = 230;
- freqC3 = 910;
- freqC4 = 4000;
- freqC5 = 14000;
- freqL1 = freqC1 * ( (-1) / (2 * Q) + sqrt(1 + (1 / 4 * Q ^ 2)));
- freqL2 = freqC2 * ( (-1) / (2 * Q) + sqrt(1 + (1 / 4 * Q ^ 2)));
- freqL3 = freqC3 * ( (-1) / (2 * Q) + sqrt(1 + (1 / 4 * Q ^ 2)));
- freqL4 = freqC4 * ( (-1) / (2 * Q) + sqrt(1 + (1 / 4 * Q ^ 2)));
- freqL5 = freqC5 * ( (-1) / (2 * Q) + sqrt(1 + (1 / 4 * Q ^ 2)));
- freqU1 = freqC1 * ( 1 / (2 * Q) + sqrt(1 + (1 / 4 * Q ^ 2)));
- freqU2 = freqC2 * ( 1 / (2 * Q) + sqrt(1 + (1 / 4 * Q ^ 2)));
- freqU3 = freqC3 * ( 1 / (2 * Q) + sqrt(1 + (1 / 4 * Q ^ 2)));
- freqU4 = freqC4 * ( 1 / (2 * Q) + sqrt(1 + (1 / 4 * Q ^ 2)));
- freqU5 = freqC5 * ( 1 / (2 * Q) + sqrt(1 + (1 / 4 * Q ^ 2)));
- normFL1 = freqL1 / (FS / 2);
- normFL2 = freqL2 / (FS / 2);
- normFL3 = freqL3 / (FS / 2);
- normFL4 = freqL4 / (FS / 2);
- normFL5 = freqL5 / (FS / 2);
- normFU1 = freqU1 / (FS / 2);
- normFU2 = freqU2 / (FS / 2);
- normFU3 = freqU3 / (FS / 2);
- normFU4 = freqU4 / (FS / 2);
- normFU5 = freqU5 / (FS / 2);
- bw1 = freqC1 / Q;
- bw2 = freqC2 / Q;
- bw3 = freqC3 / Q;
- bw4 = freqC4 / Q;
- bw5 = freqC5 / Q;
- nOrder = 40;
- [filt1Num, filt1Den] = fir1(nOrder, normFU1, 'low');
- [filt2Num, filt2Den] = fir1(nOrder, [normFL2 normFU2], 'bandpass');
- [filt3Num, filt3Den] = fir1(nOrder, [normFL3 normFU3], 'bandpass');
- [filt4Num, filt4Den] = fir1(nOrder, [normFL4 normFU4], 'bandpass');
- [filt5Num, filt5Den] = fir1(nOrder, normFL5, 'high');
- [H1, W1] = freqz(filt1Num, filt1Den);
- [H2, W2] = freqz(filt2Num, filt2Den);
- [H3, W3] = freqz(filt3Num, filt3Den);
- [H4, W4] = freqz(filt4Num, filt4Den);
- [H5, W5] = freqz(filt5Num, filt5Den);
- figure;
- plot(W1 / pi, abs(H1), W2 / pi, abs(H2), W3 / pi, abs(H3), W4 / pi, abs(H4), W5 / pi, abs(H5));
- xlabel('Normalized Frequency');
- ylabel('Magnitude');
- title('Frequency response of invidual filters');
- sumH = abs(H1) + abs(H2) + abs(H3) + abs(H4) + abs(H5);
- figure;
- plot(W1 / pi, 20 * log10(sumH));
- xlabel('Normalized Frequency');
- ylabel('20 log10(Mag)');
- title('Frequency response of sum of filters');
- audiowrite(outputPath, Z, FS);
- end
Add Comment
Please, Sign In to add comment