Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- % Define filter specifications
- Fp = 500; % Cutoff frequency in Hz
- Fst = 600; % Stopband frequency in Hz
- Fs = 2000; % Sample frequency in Hz
- Rp = 3; % Maximum passband ripple in dB
- A = 40; % Stopband attenuation in dB
- % Normalize frequencies
- Wp = 2 * Fp / Fs; % Cutoff frequency in radians/sample
- Wst = 2 * Fst / Fs; % Stopband frequency in radians/sample
- % Design the filter using fir1 function
- N = fir1(10, Wp, 'low', kaiser(11, 0.5));
- % Load an example audio file (replace 'input_audio.wav' with your input audio file)
- [input_signal, Fs] = audioread('input_audio.wav');
- % Apply the filter to the input signal
- output_signal = filter(N, 1, input_signal);
- % Plot input and output signals in the time domain
- figure;
- subplot(2,1,1);
- t = 0:1/Fs:(length(input_signal)-1)/Fs;
- plot(t, input_signal);
- xlabel('Time (s)');
- ylabel('Amplitude');
- title('Input Signal');
- subplot(2,1,2);
- plot(t, output_signal);
- xlabel('Time (s)');
- ylabel('Amplitude');
- title('Output Signal');
- % Compute and plot magnitude frequency responses
- figure;
- subplot(2,1,1);
- freqz(N, 1, 'half', 1024, Fs);
- title('Filter Frequency Response');
- xlabel('Frequency (Hz)');
- ylabel('Magnitude (dB)');
- subplot(2,1,2);
- [freq, input_spectrum] = periodogram(input_signal, [], [], Fs);
- [freq, output_spectrum] = periodogram(output_signal, [], [], Fs);
- plot(freq, 10*log10(input_spectrum), 'b', 'LineWidth', 1.5);
- hold on;
- plot(freq, 10*log10(output_spectrum), 'r', 'LineWidth', 1.5);
- hold off;
- xlabel('Frequency (Hz)');
- ylabel('Magnitude (dB)');
- legend('Input Spectrum', 'Output Spectrum');
- title('Input and Output Frequency Responses');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement