plot the line y = sin(t2), where t is time between 1 and 30 s with a sample rate of 4000 hz. • using a 4th order butterworth bandpass zero-phase digital filter, filter y between 4 and 6 hz. . in matlab

main.m
% Define time vector
t = linspace(0, 30, 4000*30);

% Define signal y = sin(t^2)
y = sin(t.^2);

% Define filter parameters
Fs = 4000;                          % Sampling frequency
Fc1 = 4;                            % Lower cut-off frequency
Fc2 = 6;                            % Upper cut-off frequency
N = 4;                              % Filter order

% Create 4th order Butterworth bandpass filter
[b, a] = butter(N, [Fc1, Fc2]/(Fs/2), 'bandpass');

% Apply filter to signal
y_filt = filtfilt(b, a, y);

% Plot original and filtered signals
plot(t, y, 'b', t, y_filt, 'r')
ylabel('Amplitude')
xlabel('Time (s)')
legend('Original', 'Filtered')
649 chars
24 lines

This code defines a time vector and creates a signal y that is the sin(t^2). The sample rate is 4000 Hz. The code specifies filter parameters such as lower and upper cut-off frequencies, sampling frequency, and filter order, and creates a 4th order Butterworth bandpass filter. The code then applies the filter to the original signal y using filtfilt function and creates a filtered signal y_filt. Finally, the code plots the original signal y and filtered signal y_filt. The original signal is shown in blue and the filtered signal is shown in red. The plot function is used to plot the signals. The xlabel, ylabel, and legend functions are used to label the plot.

related categories

gistlibby LogSnag