73 lines
2.0 KiB
Matlab
73 lines
2.0 KiB
Matlab
% Load Signal
|
|
pkg load signal
|
|
data = csvread('unknownsignal.csv');
|
|
signal=data';
|
|
Fs=300
|
|
N=length(signal)
|
|
% Apply the Hamming Filter
|
|
signal_Windowed = Hamming_Windower(signal);
|
|
|
|
% Spectral Analysis (FFT)
|
|
% Compute the FFT of the windowed signal
|
|
signal_Windowed_fft = fft(signal_Windowed, N);
|
|
|
|
% Normalize the FFT
|
|
signal_Windowed_fft_norm = signal_Windowed_fft / N;
|
|
|
|
% Compute the magnitude spectrum
|
|
magnitude_spectrum = abs(signal_Windowed_fft_norm);
|
|
|
|
% Generate the frequency vector
|
|
frequencies = linspace(0, Fs/2, N/2);
|
|
|
|
% Plot the magnitude spectrum in the frequency domain
|
|
figure;
|
|
plot(frequencies, magnitude_spectrum(1:N/2));
|
|
xlabel('Frequency (Hz)');
|
|
ylabel('Magnitude');
|
|
title('Magnitude Spectrum of the Windowed Signal');
|
|
grid on;
|
|
|
|
|
|
% Define the frequency range of interest
|
|
low_freq = 27;
|
|
high_freq = 66;
|
|
|
|
% Normalize the frequencies (Nyquist criterion)
|
|
low_freq_norm = low_freq / (Fs/2);
|
|
high_freq_norm = high_freq / (Fs/2);
|
|
|
|
% Design a Butterworth bandpass filter
|
|
filter_order = 4; % can be adjusted to modify rolloff
|
|
[b, a] = butter(filter_order, [low_freq_norm, high_freq_norm], 'bandpass');
|
|
|
|
% Apply the Butterworth filter to the windowed signal
|
|
filtered_signal = filter(b, a, signal_Windowed);
|
|
|
|
% Plot the filtered signal in the time domain
|
|
t = linspace(0, (N-1)/Fs, N); % Time vector
|
|
figure;
|
|
plot(t, filtered_signal);
|
|
xlabel('Time (s)');
|
|
ylabel('Amplitude');
|
|
title('Filtered Signal in Time Domain');
|
|
grid on;
|
|
|
|
% Compute the FFT of the filtered signal and normalize it
|
|
fft_filtered_signal = fft(filtered_signal, N);
|
|
fft_filtered_signal_normalized = fft_filtered_signal / N;
|
|
|
|
% Compute the magnitude spectrum
|
|
magnitude_spectrum_filtered = abs(fft_filtered_signal_normalized);
|
|
|
|
% Generate the frequency vector
|
|
frequencies = linspace(0, Fs/2, N/2);
|
|
|
|
% Plot the magnitude spectrum of the filtered signal in the frequency domain
|
|
figure;
|
|
plot(frequencies, magnitude_spectrum_filtered(1:N/2));
|
|
xlabel('Frequency (Hz)');
|
|
ylabel('Magnitude');
|
|
title('Magnitude Spectrum of the Filtered Signal');
|
|
grid on;
|