# data[].attributes.body
x = [1 2 3 4]; % Sample input sequence

n = length(x); % Length of the sequence

subplot(2,1,1);

stem(x);

xlabel('Time');

ylabel('Amplitude');

title('Time Series');

y1 = fft(x, n); % Apply FFT

subplot(2,2,2);

stem(abs(y1)); % Plot FFT magnitude

xlabel('Frequency');

ylabel('Amplitude');

title('Fast Fourier Transform');

% DFT Calculation

Y_dft = fft(x); % Using FFT function for DFT

subplot(2,2,4);

stem(abs(Y_dft)); % Plot DFT magnitude

xlabel('Frequency');

ylabel('Amplitude');

title('Discrete Fourier Transform');

# data[].attributes.body
fs = 1000;

T = 1/fs;

t = 0:1/fs:1;

x = cos(2*pi*40*t) + randn(size(t));

[p, f] = periodogram(x, hamming(length(x)), length(x), fs, 'power');

subplot(2,1,1);

plot(f, 10*log10(p));

[pxx, f_pwelch] = pwelch(x, 500, 300, 500, fs);

subplot(2,1,2);

plot(f_pwelch, 10*log10(pxx));

xlabel('Frequency (Hz)');

ylabel('Magnitude (dB)');

# data[].attributes.body
clc;

clear;

% Filter design using Hamming, Blackman, and Hanning windows

% Input parameters

rp = 0.03; % Passband ripple

rs = 0.04; % Stopband ripple

fp = 1200; % Passband frequency

fs = 1700; % Stopband frequency

f = 9000; % Sampling frequency

wp = 2*(fp/f); % Normalized passband edge

ws = 2*(fs/f); % Normalized stopband edge

% Calculate filter order

num = -20*log10(sqrt(rp*rs)) - 13;

den = 14.6*(fs - fp)/f;

n = ceil(num/den);

n1 = n + 1;

if rem(n,2) ~= 0

n1 = n;

n = n - 1;

end

% Hamming Window Filters

figure('Name','Hamming Window');

y = hamming(n1);

b = fir1(n, wp, y); % LPF

[h, o] = freqz(b, 1, 256);

subplot(2,2,1);

plot(o/pi, 20*log10(abs(h)));

title('LPF - Hamming');

xlabel('Normal Frequency');

ylabel('Gain (dB)');

b = fir1(n, wp, 'high', y); % HPF

[h, o] = freqz(b, 1, 256);

subplot(2,2,2);

plot(o/pi, 20*log10(abs(h)));

title('HPF - Hamming');

xlabel('Normal Frequency');

ylabel('Gain (dB)');

wn = [wp ws];

b = fir1(n, wn, y); % BPF

[h, o] = freqz(b, 1, 256);

subplot(2,2,3);

plot(o/pi, 20*log10(abs(h)));

title('BPF - Hamming');

xlabel('Normal Frequency');

ylabel('Gain (dB)');

b = fir1(n, wn, 'stop', y); % BSF

[h, o] = freqz(b, 1, 256);

subplot(2,2,4);

plot(o/pi, 20*log10(abs(h)));

title('BSF - Hamming');

xlabel('Normal Frequency');

ylabel('Gain (dB)');

% Blackman Window Filters

figure('Name','Blackman Window');

y = blackman(n1);

b = fir1(n, wp, y);

[h, o] = freqz(b, 1, 256);

subplot(2,2,1);

plot(o/pi, 20*log10(abs(h)));

title('LPF - Blackman');

xlabel('Normal Frequency');

ylabel('Gain (dB)');

b = fir1(n, wp, 'high', y);

[h, o] = freqz(b, 1, 256);

subplot(2,2,2);

plot(o/pi, 20*log10(abs(h)));

title('HPF - Blackman');

xlabel('Normal Frequency');

ylabel('Gain (dB)');

b = fir1(n, wn, y);

[h, o] = freqz(b, 1, 256);

subplot(2,2,3);

plot(o/pi, 20*log10(abs(h)));

title('BPF - Blackman');

xlabel('Normal Frequency');

ylabel('Gain (dB)');

b = fir1(n, wn, 'stop', y);

[h, o] = freqz(b, 1, 256);

subplot(2,2,4);

plot(o/pi, 20*log10(abs(h)));

title('BSF - Blackman');

xlabel('Normal Frequency');

ylabel('Gain (dB)');

% Hanning Window Filters

figure('Name','Hanning Window');

y = hanning(n1);

b = fir1(n, wp, y);

[h, o] = freqz(b, 1, 256);

subplot(2,2,1);

plot(o/pi, 20*log10(abs(h)));

title('LPF - Hanning');

xlabel('Normal Frequency');

ylabel('Gain (dB)');

b = fir1(n, wp, 'high', y);

[h, o] = freqz(b, 1, 256);

subplot(2,2,2);

plot(o/pi, 20*log10(abs(h)));

title('HPF - Hanning');

xlabel('Normal Frequency');

ylabel('Gain (dB)');

b = fir1(n, wn, y);

[h, o] = freqz(b, 1, 256);

subplot(2,2,3);

plot(o/pi, 20*log10(abs(h)));

title('BPF - Hanning');

xlabel('Normal Frequency');

ylabel('Gain (dB)');

b = fir1(n, wn, 'stop', y);

[h, o] = freqz(b, 1, 256);

subplot(2,2,4);

plot(o/pi, 20*log10(abs(h)));

title('BSF - Hanning');

xlabel('Normal Frequency');

ylabel('Gain (dB)');

# data[].attributes.body
x = [0,0.5,1,0,0.5,1,0,0.5,1,0,0.5,1,0,0.5,1,0,0.5,1,0,0.5,1,0,0.5,1,0,0.5,1,0, ...

0.5,1,0,0.5,1,0,0.5,1,0,0.5,1,0,0.5,1,0,0.5,1,0,0.5,1,0,0.5,1,0,0.5,1,0,0.5,1, ...

0,0.5,1,0,0.5,1,0,0.5,1,0,0.5,1,0,0.5,1,0,0.5,1,0,0.5,1,0,0.5,1,0,0.5,1,0,0.5,1, ...

0,0.5,1,0,0.5,1,0,0.5,1,0,0.5,1,0,0.5,1];

e = randn(1, length(x));

y = conv(x, e, 'same');

h = ones(1, 26) / 26;

y1 = conv(y, h, 'same');

y2 = abs(fft(y1));

figure('Name', 'EEG Signal Processing');

subplot(3,2,1);

plot(x);

xlabel('Time'); ylabel('Amplitude');

title('EEG Signal');

subplot(3,2,2);

plot(e);

xlabel('Time'); ylabel('Amplitude');

title('Random Noise');

subplot(3,2,3);

plot(y);

xlabel('Time'); ylabel('Amplitude');

title('Noisy Signal');

subplot(3,2,4);

plot(y1);

xlabel('Time'); ylabel('Amplitude');

title('Filtered Output');

subplot(3,2,5);

stem(y2);

xlabel('Frequency'); ylabel('Amplitude');

title('FFT of Filtered Signal');

# data[].attributes.body
x=[0,0,0,0.5,0.7,0.8,0.7,0.5,0,0,-1,-1.5,1,2,4,6,4,2,1,-1,-2,-

4,0,0,0,0,0.2,0.4,0.8,0,0,0,0,0,0,0,0.5,0.7,0.8,0.7,0.5,0,0,-1,-

1.5,1,2,4,6,4,2,1,-1,-2,-

4,0,0,0,0,0.2,0.4,0.8,0,0,0,0,0,0,0,0.5,0.7,0.8,0.7,0.5,0,0,-1,-

1.5,1,2,4,6,4,2,1,-1,-2,-

4,0,0,0,0,0.2,0.4,0.8,0,0,0,0,0,0,0,0.5,0.7,0.8,0.7,0.5,0,0,-1,-

1.5,1,2,4,6,4,2,1,-1,-2,-

4,0,0,0,0,0.2,0.4,0.8,0,0,0,0,0,0,0,0.5,0.7,0.8,0.7,0.5,0,0,-1,-

1.5,1,2,4,6,4,2,1,-1,-2,-

4,0,0,0,0,0.2,0.4,0.8,0,0,0,0];

subplot(3,2,1);

plot(x);

xlabel('time');

ylabel('amplitude');

title('ecg');

e=randn(80,1);

subplot(3,2,2);

plot(e);

xlabel('time');

ylabel('amplitude');

title('random noise');

y=conv(x,e);

subplot(3,2,3);

plot(y);

title('nosiy signal');

h=[1 1 1 1 1 1]/6;

y1=conv(h,y);

subplot(3,2,4);

plot(y1);

xlabel('time');

ylabel('amplitude');

title('fitered output');

y2=fft(y1);

subplot(3,2,5);

stem(y2);

xlabel('time');

ylabel('amplitude');

title('y2');

# data[].attributes.body
fs=160;

T=1/fs;

L = 10; % Length of signal

t = 0:1/fs:L; % Time vector

x=sin(2*pi*40*t)+sin(2*pi*60*t);

subplot(3,1,1);

plot(t,x);

x1=length(x);

NFFT = 2^nextpow2(x1); % Next power of 2 from length of y

f = fs*linspace(0,1,NFFT);

Y = fft(x,NFFT);

subplot(3,1,2);

plot(f(1:1024),abs(Y(1:1024)));

title('Single-Sided Amplitude Spectrum of y(t)')

xlabel('Frequency (Hz)')

ylabel('|Y(f)|')

b=fir1(25,0.5,'low');

h=filter(b,1,x);

i=length(h);

NFFT1 = 2^nextpow2(i); % Next power of 2 from length of y

f1 = fs*linspace(0,1,NFFT1);

Y1 = fft(h,NFFT1);

subplot(3,1,3);

plot(f1(1:1024),abs(Y1(1:1024)));

# data[].attributes.body
f = [0 0.6 0.6 1];

m = [1 1 0 0];

b1 = fir2(30,f,m);

[h,w] = freqz(b1,2);

subplot(4,2,1)

plot(f,m,w/pi,abs(h))

title('lowpass filter magnitude response');

ylabel('mag in db');

xlabel('Norm frequency radian/samples');

subplot(4,2,2);

plot(f,m,w/pi,angle(h));

title('lowpass filter phase response');

ylabel('phase in degree');

xlabel('Norm frequency radian/samples');

# data[].attributes.body
f = [0 0.6 0.6 1];

m = [0 0 1 1];

b1 = fir2(30,f,m);

[h,w] = freqz(b1,1);

subplot(4,2,3)

plot(f,m,w/pi,abs(h))

title('Highpass filter magnitude response');

ylabel('mag in db');

xlabel('Norm frequency radian/samples');

subplot(4,2,4);

plot(f,m,w/pi,angle(h));

title('Highpass filter phase response');

ylabel('phase in degree');

xlabel('Norm frequency radian/samples');

# data[].attributes.body
f = [0 0.4 0.4 0.6 0.6 1];

m = [0 0 1 1 0 0];

b1 = fir2(30,f,m);

[h,w] = freqz(b1,1);

subplot(4,2,5)

plot(f,m,w/pi,abs(h))

title('Bandpass filter magnitude response');

xlabel('Norm frequency radian/samples');

ylabel('mag in db');

subplot(4,2,6);

plot(f,m,w/pi,angle(h));

title('Bandpass filter phase response');

ylabel('phase in degree');

xlabel('Norm frequency radian/samples');

f = [0 0.4 0.4 0.6 0.6 1];

m = [1 1 0 0 1 1];

b1 = fir2(30,f,m);

[h,w] = freqz(b1,1);

subplot(4,2,7)

plot(f,m,w/pi,abs(h));

title('Bandstop filter magnitude response');

xlabel('Norm frequency radian/samples');

ylabel('mag in db');

subplot(4,2,8);

plot(f,m,w/pi,angle(h));

title('Bandstop filter phase response');

ylabel('phase in degree');

xlabel('Norm frequency radian/samples');

# data[].attributes.body
% Design of Digital IIR Filters using Butterworth and Chebyshev methods

pkg load signal;

% Sampling frequency in Hz

fs = 1000;

% Filter order

n = 4;

% Cutoff frequency in Hz

fc = 200;

% Normalized cutoff frequency

Wn = fc / (fs / 2);

% Butterworth filter design

[b_butter, a_butter] = butter(n, Wn);

% Frequency response of Butterworth filter

freqz(b_butter, a_butter);

title('Butterworth Lowpass Filter Response');

% Pause before next plot

pause;

% Chebyshev Type I filter design

rp = 1; % Passband ripple in dB

[b_cheby, a_cheby] = cheby1(n, rp, Wn);

% Frequency response of Chebyshev filter

freqz(b_cheby, a_cheby);

title('Chebyshev Type I Lowpass Filter Response');