Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
40 views3 pages

Matlab Codes: Num (0 1) Denum (-1 1) Sys - 1 TF (Num, Denum) Bode (Sys - 1) Title

This document contains 4 MATLAB code examples: 1) Defines a transfer function and plots its frequency response. 2) Takes the FFT of a signal, plots the magnitude and phase spectra. 3) Plots an original signal, the same signal shifted by 2 units, and the shifted signal scaled to -2<x<2. 4) The codes demonstrate functions for transfer functions, FFTs, plotting signals, and signal shifting and scaling.

Uploaded by

saqib25492
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)
40 views3 pages

Matlab Codes: Num (0 1) Denum (-1 1) Sys - 1 TF (Num, Denum) Bode (Sys - 1) Title

This document contains 4 MATLAB code examples: 1) Defines a transfer function and plots its frequency response. 2) Takes the FFT of a signal, plots the magnitude and phase spectra. 3) Plots an original signal, the same signal shifted by 2 units, and the shifted signal scaled to -2<x<2. 4) The codes demonstrate functions for transfer functions, FFTs, plotting signals, and signal shifting and scaling.

Uploaded by

saqib25492
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/ 3

MATLAB CODES

Q#2 C
num=[0 1];
denum=[-1 1];

sys_1=tf(num,denum);
bode(sys_1)
title('Frequency response')

Output
Q#3

fs=500;
Ts=1/fs;
t=0:Ts:1;
f1=20;
f2=40;
x=2 + 4*cos((2*pi*f1*t) + 2.1 )+2*cos((2*pi*f2*t) + 1.05);
X=fftshift(fft(x));
X_mag=abs(X);
X_phase=angle(X);
subplot(2,1,1)
df=-fs/2:1:fs/2;
plot(t,X_mag)
title('Frequency Spectrum')
subplot(2,1,2)
plot(t,X_phase)

Output
Q#4
x1=-1:0.001:0;
y1=-(x1.^2) - x1 + 0.25;
x2=0:0.001:1;
y2=(x2.^2) - x2 + 0.25;

x=[x1 x2];
y=[y1 y2];
subplot(3,1,1)
plot(x,y)
title('Original Signal')
xlabel('Time period')
ylabel('Amplitude')

subplot(3,1,2)
plot((x-2),y);
title('Shifted Signal at x(t+2)')
xlabel('Time period')
ylabel('amplitude')

subplot(3,1,3)
plot((2*x-2),y)
title('Signal from -2<x<2 and shifted at x(t+2)')
xlabel('Time Period')
ylabel('Amplitude')

Output

You might also like