Matlab 7 To 10
Matlab 7 To 10
PROGRAM:
fs = 1000; % Original continuous-time signal frequency (Hz)
t = 0:l/fs:l; % Time vector for one second
f_signal = 5; % Frequency of the original signal (Hz)
% Original Continuous-Time Signal
x = sin(2*pi*f_signal*t); % Generate a sine wave
% Plot the original signal figure;
subplot(3,l,l);
plot(t, x, 'b', 'LineWidth', 1.5);
title('Original Continuous-Time Signal');
xlabel('Time (s)'); ylabel('Amplitude');
grid on;
% Sampling with different sampling frequencies
sampling_freqs = [10, 20, 50]; % Array of sampling frequencies (Hz)
for i = l:length(sampling_freqs)
fs_sample = sampling_freqs(i); % Current sampling frequency
t_sampled = 0:l/fs_sample:l; % Time vector for sampled signal
x_sampled = sin(2*pi*f_signal*t_sampled); % Sample the signal
% Plot the sampled signal subplot(3,l,i+l);
stem(t_sampled, x_sampled, 'r', 'filled');
hold on;
plot(t, x, 'b:'); % Overlay the original signal title) ['Sampled Signal with Sampling Frequency
= ' num2str(fs_sample) ' Hz']);
xlabel('Time (s)'); ylabel('Amplitude');
EXPERIMENT :8
PROGRAM:
1)
L=input ('enter the upsampling factor');
N=input ('enter the length of the input signal');
fl=input ('enter the frequency of first sinusodal');
f2=input ('enter the frequency of second sinusodal');
n=0:N-l;
x=sin(2*pi*fl *n) +sin(2*pi*12*n);
y=interp (x, L);
subplot (2,1,1)
stem (n,x (1:N))
title('input sequence');
xlabel('time (n) ');
ylabel('amplitude');
subplot (2,1,2)
m=0:N*L-l;
stem (m, y (1:N*L))
title('output sequence’);
xlabel('time (n) ');
ylabel('amplitude');
2)
L=input ('Enter the upsampling factor');
N=input ('Enter the length of the input signal');
n=0:N-l;
x=cos (2*pi*30*n);
y=interp (x,L);
subplot (2,1,1);
stem (n,x(l:N));
title('Input signal');
xlabel('Time (n)');
ylabel('Amplitude');
subplot (2,1,2);
m=0:N*L-l
stem (m,y (1:N*L));
title('Output sequence');
xlabel('Time (n) ');
ylabel('Ampitude')
OUTPUT WAVEFORM:
Decimation :
Decimation is a signal processing technique that reduces the sampling rate of a signal. It’s
commonly used in digital signal processing (DSP) to lower the data rate or compress data
without losing essential information
PROGRAM:
D=input('enter the downsampling factor');
L=input ('enter the length of the input signal');
fl=input ('enter the frequency of first sinusodal');
f2-input ('enter the frequency of second sinusodal');
n=0:L-l;
x=sin(2*pi*fl*n) +sin(2*pi*f2*n);
y=decimate (x, D, 'fir');
subplot (2,1,1);
stem (n,x(l:L);
title('input sequence');
xlabel('time (n)');
ylabel('amplitude');
subplot (2,1,2)
m=0: (L/D)-l;
stem (m,y (1:L/D));
OUTPUT WAVEFORM:
EXPERIMENT : 9
CODE:
x=[l 2 3 4 5];
N=length (x);
xK=fft (x, N);
xrHfft (xK):
n=0:N-l;
subplot (2,2,1);
stem(x,’r’, ‘LineWidth’,1);
xlabel(‘n’);
ylabel(‘Amplitude');
title('lnput Sequence');
subplot (2,2,2);
stem (n, abs (xK), ‘b’,’ LineWidth ‘,2);
xlabel(‘n’);
ylabel('Magnitude’);
title("Magnitude Response");
subplot (2,2,3);
stem (n, angle (xK), 'black', 'LineWidth',3);
xlabel(‘n’);
ylabel('phase');
title('Phase Response");
subplot (2,2,4):
stem (n ,xn,'9’, ‘LineWidth’, 4)
xlabel('n');
ylabelf Amplitude');
title(‘IFFT’)
OUTPUT WAVEFORM:
EXPERIMENT : 10
Theory: The discrete Fourier transform, or DFT, is the primary tool of digital signal
processing. The foundation of the product is the fast Fourier transform (FFT), a method for
computing the DFT with reduced execution time.
DFT is given by formula:
* i k
->
A* = >
n=0
J
Xn e *
Procedure:
1) Double click in the MATLAB icon. MATLAB Desktop will be displayed.
2) Click 'file' menu, click 'new', click 'M-file'. Now the editor
window will be displayed.
3) Type the program and save it.
4) To run the program, click 'debug' menu and run sub menu or click the run button directly.
5) Enter sample inputs in command window, view the results and verify them.
CODE:
x=(l 2 3 4 5 6 7 8);
X=fft (x);
X_mag=abs (X);
X_phase angle (X);
N length (x);
F=(0:N-l)* (1/8);
subplot (2,1,1);
stem(f,X_mag,’r’,LineWidth’1);
xlabel ‘(Frequency (Hz)');
ylabel (‘Magnitude’);
title('Magnitude');
subplot (2,1,2);
stem (f,X_phase, 'b', 'Linewidth’,2);
xlabel('Frequency(Hz)’);
ylabel('Phase (rad)’);
title('phase Spectrum’)
OUTPUT: