Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function filter_signal(input_file, output_file)
- % Constants
- F1 = 2000; % Frequency of the first component in Hz
- F2 = 3200; % Frequency of the second component in Hz
- Fs = 15000; % Sampling frequency in Hz
- % Read the input audio file
- [x, Fs_original] = audioread(input_file);
- % Generate the input signal x(t)
- t = 0:1/Fs:(length(x)-1)/Fs;
- input_signal = cos(2*pi*F1*t) + cos(2*pi*F2*t);
- % Plot the input signal in the time domain
- figure;
- subplot(3, 1, 1);
- plot(t, input_signal);
- xlabel('Time (s)');
- ylabel('Amplitude');
- title('Input Signal in Time Domain');
- % Compute and plot the magnitude of the signal's frequency response
- subplot(3, 1, 2);
- f = linspace(0, Fs/2, length(input_signal)/2);
- input_signal_fft = abs(fft(input_signal));
- plot(f, input_signal_fft(1:length(f)));
- xlabel('Frequency (Hz)');
- ylabel('Magnitude');
- title('Frequency Response of Input Signal');
- % Design FIR filter to reject the first signal spectrum component
- cut_off_freq = F1 / (Fs / 2);
- filter_order = 50;
- b = fir1(filter_order, cut_off_freq, 'high');
- % Apply the FIR filter on the input signal
- filtered_signal = filter(b, 1, input_signal);
- % Plot the output signal in the time domain
- subplot(3, 1, 3);
- plot(t, filtered_signal);
- xlabel('Time (s)');
- ylabel('Amplitude');
- title('Output Signal in Time Domain');
- % Compute and plot the magnitude of the filtered signal's frequency response
- figure;
- filtered_signal_fft = abs(fft(filtered_signal));
- plot(f, filtered_signal_fft(1:length(f)));
- xlabel('Frequency (Hz)');
- ylabel('Magnitude');
- title('Frequency Response of Filtered Signal');
- % Write the filtered signal to an output audio file
- audiowrite(output_file, filtered_signal, Fs_original);
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement