0% found this document useful (0 votes)
12 views7 pages

DTSP Programs

Easy matlab programs dsp

Uploaded by

sasiram2707
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views7 pages

DTSP Programs

Easy matlab programs dsp

Uploaded by

sasiram2707
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Lpf butterworth

N = 4;

wc = 1;

[b, a] = butter(N, wc, 'low', 's');

[h, w] = freqs(b, a);

subplot(2,1,1);

plot(w, abs(h));

title('Magnitude Response of HPF');

subplot(2,1,2);

plot(w, angle(h));

title('Phase Response of HPF');

-------------------------------------------------------------

hpf butterworth

N = 4; % Filter order

wc = 1; % Cutoff frequency

[b, a] = butter(N, wc, 'high', 's');

[h, w] = freqs(b, a);

subplot(2,1,1);

plot(w, abs(h));

title('Magnitude Response of HPF');

subplot(2,1,2);

plot(w, angle(h));

title('Phase Response of HPF');

bpf

N = 4; % Filter order

wc1 = 0.5; % Lower cutoff frequency

wc2 = 1.5; % Upper cutoff frequency

[b, a] = butter(N, [wc1, wc2], 'bandpass', 's');

[h, w] = freqs(b, a);

subplot(2,1,1);
plot(w, abs(h));

title('Magnitude Response of BPF');

subplot(2,1,2);

plot(w, angle(h));

title('Phase Response of BPF');

band stop

N = 4; % Filter order

wc1 = 0.5; % Lower cutoff frequency

wc2 = 1.5; % Upper cutoff frequency

[b, a] = butter(N, [wc1, wc2], 'stop', 's');

[h, w] = freqs(b, a);

subplot(2,1,1);

plot(w, abs(h));

title('Magnitude Response of BPF');

subplot(2,1,2);

plot(w, angle(h));

title('Phase Response of BPF');

lpf chebyshev

N = 4; % Filter order

wc = 1; % Cutoff frequency

Rp = 3; % Passband ripple in dB

[b, a] = cheby1(N, Rp, wc, 'low', 's');

[h, w] = freqs(b, a);

subplot(2,1,1);

plot(w, abs(h));

title('Magnitude Response of Chebyshev HPF');

subplot(2,1,2);

plot(w, angle(h));

title('Phase Response of Chebyshev HPF');


hpf chebyshev

N = 4; % Filter order

wc = 1; % Cutoff frequency

Rp = 3; % Passband ripple in dB

[b, a] = cheby1(N, Rp, wc, 'high', 's');

[h, w] = freqs(b, a);

subplot(2,1,1);

plot(w, abs(h));

title('Magnitude Response of Chebyshev HPF');

subplot(2,1,2);

plot(w, angle(h));

title('Phase Response of Chebyshev HPF');

Chebyshev Band-Pass Filter (BPF)

N = 4; % Filter order

wc1 = 0.5; % Lower cutoff frequency

wc2 = 1.5; % Upper cutoff frequency

Rp = 3; % Passband ripple in dB

[b, a] = cheby1(N, Rp, [wc1, wc2], 'bandpass', 's');

[h, w] = freqs(b, a);

subplot(2,1,1);

plot(w, abs(h));

title('Magnitude Response of Chebyshev BPF');

subplot(2,1,2);

plot(w, angle(h));

title('Phase Response of Chebyshev BPF');


Chebyshev Band-Stop Filter (BSF)

N = 4; % Filter order

wc1 = 0.5; % Lower cutoff frequency

wc2 = 1.5; % Upper cutoff frequency

Rp = 3; % Passband ripple in dB

[b, a] = cheby1(N, Rp, [wc1, wc2], 'stop', 's');

[h, w] = freqs(b, a);

subplot(2,1,1);

plot(w, abs(h));

title('Magnitude Response of Chebyshev BSF');

subplot(2,1,2);

plot(w, angle(h));

title('Phase Response of Chebyshev BSF');

auto correlation

x = [1 2 3 4 5 6 7 8 9];
Rxx = xcorr(x);

% Plot the input sequence


subplot(2,1,1);
stem(x);
title('Input Sequence');
xlabel('Time Index');
ylabel('Amplitude');

% Plot the autocorrelated signal


subplot(2,1,2);
stem(Rxx);
title('Autocorrelated Signal');
xlabel('Lag');
ylabel('Autocorrelation');
linear conv

x = [1 2 3 4 5];
h = [1 2 1];

% Compute linear convolution


y = conv(x, h);

% Display the result


disp('Input Sequence x:');
disp(x);
disp('Impulse Response h:');
disp(h);
disp('Linear Convolution y:');
disp(y);

% Plot the input sequence, impulse response, and output sequence


subplot(3,1,1);
stem(x);
title('Input Sequence x');
xlabel('Time Index');
ylabel('Amplitude');

subplot(3,1,2);
stem(h);
title('Impulse Response h');
xlabel('Time Index');
ylabel('Amplitude');

subplot(3,1,3);
stem(y);
title('Linear Convolution y');
xlabel('Time Index');
ylabel('Amplitude');

circular conv

y =cconv(x,h)

circular conv using fft

x = [1 2 3 4 5];
h = [1 2 1];

% Compute circular convolution using FFT


X = fft(x, length(x) + length(h) - 1);
H = fft(h, length(x) + length(h) - 1);
Y = X .* H;
y = ifft(Y);

% Plot the input sequences and output sequence


subplot(3,1,1);
stem(x);
title('Input Sequence x');
xlabel('Time Index');
ylabel('Amplitude');

subplot(3,1,2);
stem(h);
title('Impulse Response h');
xlabel('Time Index');
ylabel('Amplitude');

subplot(3,1,3);
stem(y);
title('Circular Convolution y');
xlabel('Time Index');
ylabel('Amplitude');
To write a program to find the Discrete Fourier Transform and IDFT of the
given sequence
using MATLAB and plot the magnitude and phase response.

% Given sequence
x = [1 2 3 4 5];

% Compute DFT
X = fft(x);

% Compute IDFT
x_idft = ifft(X);

% Plot the original sequence and IDFT sequence


subplot(2,1,1);
stem(x);
title('Original Sequence');
xlabel('Time Index');
ylabel('Amplitude');

subplot(2,1,2);
stem(x_idft);
title('IDFT Sequence');
xlabel('Time Index');
ylabel('Amplitude');

% Plot the magnitude response


figure;
magnitude_X = abs(X);
stem(magnitude_X);
title('Magnitude Response');
xlabel('Frequency Index');
ylabel('Magnitude');

% Plot the phase response


figure;
phase_X = angle(X);
stem(phase_X);
title('Phase Response');
xlabel('Frequency Index');
ylabel('Phase (radians)');

fft

% Given sequence
x = [1 2 3 4 5];

% Compute FFT
X = fft(x);

% Compute IFFT
x_ifft = ifft(X);

% Plot the original sequence and IFFT sequence


subplot(2,1,1);
stem(x);
title('Original Sequence');
xlabel('Time Index');
ylabel('Amplitude');
subplot(2,1,2);
stem(x_ifft);
title('IFFT Sequence');
xlabel('Time Index');
ylabel('Amplitude');

% Plot the magnitude response


figure;
magnitude_X = abs(X);
stem(magnitude_X);
title('Magnitude Response');
xlabel('Frequency Index');
ylabel('Magnitude');

% Plot the phase response


figure;
phase_X = angle(X);
stem(phase_X);
title('Phase Response');
xlabel('Frequency Index');
ylabel('Phase (radians)');

You might also like