Advertisement
STANAANDREY

apd sapt 7 assig3

Nov 8th, 2023
1,370
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.09 KB | None | 0 0
  1. function applyFilter(inputFilePath, outputFilePath, filterCoefficients)
  2.     % Read input wavefile
  3.     [inputSignal, fs] = audioread(inputFilePath);
  4.    
  5.     % Apply filter
  6.     outputSignal = filter(filterCoefficients, 1, inputSignal);
  7.    
  8.     % Write filtered signal to output wavefile
  9.     audiowrite(outputFilePath, outputSignal, fs);
  10.    
  11.     % Compute frequency spectrum of input and output signals
  12.     inputSpectrum = abs(fft(inputSignal));
  13.     outputSpectrum = abs(fft(outputSignal));
  14.    
  15.     % Plot input signal frequency spectrum
  16.     figure;
  17.     subplot(2, 1, 1);
  18.     plot(linspace(0, fs, length(inputSpectrum)), inputSpectrum);
  19.     title('Input Signal Frequency Spectrum');
  20.     xlabel('Frequency (Hz)');
  21.     ylabel('Magnitude');
  22.    
  23.     % Plot output signal frequency spectrum
  24.     subplot(2, 1, 2);
  25.     plot(linspace(0, fs, length(outputSpectrum)), outputSpectrum);
  26.     title('Output Signal Frequency Spectrum');
  27.     xlabel('Frequency (Hz)');
  28.     ylabel('Magnitude');
  29.    
  30.     % Save the plots as images (optional)
  31.     saveas(gcf, 'input_output_spectrum_plots.png');
  32. end
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement