Advertisement
STANAANDREY

apd sapt 7 assig1

Nov 8th, 2023
872
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.62 KB | None | 0 0
  1. % Define filter specifications
  2. Fp = 500;   % Cutoff frequency in Hz
  3. Fst = 600;  % Stopband frequency in Hz
  4. Fs = 2000;  % Sample frequency in Hz
  5. Rp = 3;     % Maximum passband ripple in dB
  6. A = 40;     % Stopband attenuation in dB
  7.  
  8. % Normalize frequencies
  9. Wp = 2 * Fp / Fs;   % Cutoff frequency in radians/sample
  10. Wst = 2 * Fst / Fs;  % Stopband frequency in radians/sample
  11.  
  12. % Design the filter using fir1 function
  13. N = fir1(10, Wp, 'low', kaiser(11, 0.5));
  14.  
  15. % Load an example audio file (replace 'input_audio.wav' with your input audio file)
  16. [input_signal, Fs] = audioread('input_audio.wav');
  17.  
  18. % Apply the filter to the input signal
  19. output_signal = filter(N, 1, input_signal);
  20.  
  21. % Plot input and output signals in the time domain
  22. figure;
  23. subplot(2,1,1);
  24. t = 0:1/Fs:(length(input_signal)-1)/Fs;
  25. plot(t, input_signal);
  26. xlabel('Time (s)');
  27. ylabel('Amplitude');
  28. title('Input Signal');
  29.  
  30. subplot(2,1,2);
  31. plot(t, output_signal);
  32. xlabel('Time (s)');
  33. ylabel('Amplitude');
  34. title('Output Signal');
  35.  
  36. % Compute and plot magnitude frequency responses
  37. figure;
  38. subplot(2,1,1);
  39. freqz(N, 1, 'half', 1024, Fs);
  40. title('Filter Frequency Response');
  41. xlabel('Frequency (Hz)');
  42. ylabel('Magnitude (dB)');
  43.  
  44. subplot(2,1,2);
  45. [freq, input_spectrum] = periodogram(input_signal, [], [], Fs);
  46. [freq, output_spectrum] = periodogram(output_signal, [], [], Fs);
  47. plot(freq, 10*log10(input_spectrum), 'b', 'LineWidth', 1.5);
  48. hold on;
  49. plot(freq, 10*log10(output_spectrum), 'r', 'LineWidth', 1.5);
  50. hold off;
  51. xlabel('Frequency (Hz)');
  52. ylabel('Magnitude (dB)');
  53. legend('Input Spectrum', 'Output Spectrum');
  54. title('Input and Output Frequency Responses');
  55.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement