Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function applyFilter(inputFilePath, outputFilePath, filterCoefficients)
- % Read input wavefile
- [inputSignal, fs] = audioread(inputFilePath);
- % Apply filter
- outputSignal = filter(filterCoefficients, 1, inputSignal);
- % Write filtered signal to output wavefile
- audiowrite(outputFilePath, outputSignal, fs);
- % Compute frequency spectrum of input and output signals
- inputSpectrum = abs(fft(inputSignal));
- outputSpectrum = abs(fft(outputSignal));
- % Plot input signal frequency spectrum
- figure;
- subplot(2, 1, 1);
- plot(linspace(0, fs, length(inputSpectrum)), inputSpectrum);
- title('Input Signal Frequency Spectrum');
- xlabel('Frequency (Hz)');
- ylabel('Magnitude');
- % Plot output signal frequency spectrum
- subplot(2, 1, 2);
- plot(linspace(0, fs, length(outputSpectrum)), outputSpectrum);
- title('Output Signal Frequency Spectrum');
- xlabel('Frequency (Hz)');
- ylabel('Magnitude');
- % Save the plots as images (optional)
- saveas(gcf, 'input_output_spectrum_plots.png');
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement