0% found this document useful (0 votes)
13 views

Signal Generator

The document describes generating and filtering a signal. It generates a multi-frequency signal, filters it using an IIR digital filter with a cutoff frequency of 500 Hz, and performs an FFT to analyze the filtered signal's frequencies. It repeats this process with adjustments to the filter coefficients each time to test different filters.

Uploaded by

Maria Tokan
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)
13 views

Signal Generator

The document describes generating and filtering a signal. It generates a multi-frequency signal, filters it using an IIR digital filter with a cutoff frequency of 500 Hz, and performs an FFT to analyze the filtered signal's frequencies. It repeats this process with adjustments to the filter coefficients each time to test different filters.

Uploaded by

Maria Tokan
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/ 6

%---------------- Signal Generator ------------------------------------

Fsampling = 4000; % Sampling frequency

T = 1/Fsampling; % Sampling period

L = 1500; % Length of signal

t = (0:L-1)*T; % Time vector

x = 12*sin(2*pi*20*t)+8*sin(2*pi*100*t)+4*sin(2*pi*1000*t); % First row wave

figure;

plot(t,x);

title ('Original Signal');

%-----------------IIR Digital Filter (Fcutoff HPF 500 Hz)-------------

% Numerator

b0= 0.0028724756513808097; b1=-0.022979805211046478 ;

b2= 0.080429318238662673 ;

b3=-0.16085863647732535 ;

b4= 0.20107329559665671 ; b5=-0.16085863647732535 ; b6= 0.080429318238662673 ;

b7=-0.022979805211046478 ; b8= 0.0028724756513808097 ;

% Denumerator

a1=1.3501361364487803 ; a2=1.7975905688855653 ;

a3=1.2177510636641604 ; a4=0.69341884928031972 ;

a5=0.24161277228930172 ; a6=0.062150179283697871 ;

a7=0.0089336956190665673 ; a8=0.00062783732521360053;

x7=0;x6=0;x5=0;x4=0;x3=0;x2=0;x1=0;x0=0;

y7=0;y6=0;y5=0;y4=0;y3=0;y2=0;y1=0;y=0;

for i=1:L

y8=y7;

y7=y6;

y6=y5;

y5=y4;

y4=y3;

y3=y2;
y2=y1;

y1=y;

x8=x7;

x7=x6;

x6=x5;

x5=x4;

x4=x3;

x3=x2;

x2=x1;

x1=x0;

x0=x(i);

y=b0*x0 + b1*x1 + b2*x2 + b3*x3 + b4*x4 + b5*x5 + b6*x6 + b7*x7 + b8*x8...

-a1*y1 - a2*y2 - a3*y3 - a4*y4 - a5*y5 - a6*y6 - a7*y7 - a8*y8;

yfilter(i)=y;

end

y = yfilter';

figure;

plot(t,y);

title ('Filtered Signal');

%-----------------Fast Fourier Transform (FFT) -------------------------

n = 2^nextpow2(L);

Yfft = fft(y,n);

P2 = abs(Yfft/L);

P1 = P2(1:n/2+1);

P1(1:end-1) = 2*P1(1:end-1);

figure;

plot(0:(Fsampling/n):(Fsampling/2-Fsampling/n),P1(1:n/2));

title ('Frequency of the signal');


%---------------- Signal Generator ------------------------------------

Fsampling = 4000; % Sampling frequency

T = 1/Fsampling; % Sampling period

L = 1500; % Length of signal

t = (0:L-1)*T; % Time vector

x = 12*sin(2*pi*20*t)+8*sin(2*pi*100*t)+4*sin(2*pi*1000*t); % First row wave

figure;

plot(t,x);

title ('Original Signal');

%-----------------IIR Digital Filter (Fcutoff HPF 500 Hz)-------------

% Numerator

b0= 0.030771479272431172; b1=-0.15652080036646746 ;

b2= 0.35572158002260579 ;

b3= -0.45970055199521503 ;

b4= 0.35572158002260579 ; b5=-0.15652080036646746 ; b6= 0.030771479272431172 ;

% Denumerator

a1=0.30884033103534397 ; a2= 0.85222412042395601 ;

a3=0.13106150365169317 ; a4= 0.13806933200256852 ;

a5= 0.0070633392736270759 ; a6= 0.0023999928523632964 ;

x6=0;x5=0;x4=0;x3=0;x2=0;x1=0;x0=0;

y6=0;y5=0;y4=0;y3=0;y2=0;y1=0;y=0;

for i=1:L

y6=y5;

y5=y4;

y4=y3;

y3=y2;

y2=y1;
y1=y;

x6=x5;

x5=x4;

x4=x3;

x3=x2;

x2=x1;

x1=x0;

x0=x(i);

y=b0*x0 + b1*x1 + b2*x2 + b3*x3 + b4*x4 + b5*x5 + b6*x6 ...

-a1*y1 - a2*y2 - a3*y3 - a4*y4 - a5*y5 - a6*y6 - a7*y7 ;

yfilter(i)=y;

end

y = yfilter';

figure;

plot(t,y);

title ('Filtered Signal');

%-----------------Fast Fourier Transform (FFT) -------------------------

n = 2^nextpow2(L);

Yfft = fft(y,n);

P2 = abs(Yfft/L);

P1 = P2(1:n/2+1);

P1(1:end-1) = 2*P1(1:end-1);

figure;

plot(0:(Fsampling/n):(Fsampling/2-Fsampling/n),P1(1:n/2));

title ('Frequency of the signal');


%---------------- Signal Generator ------------------------------------

Fsampling = 4000; % Sampling frequency

T = 1/Fsampling; % Sampling period

L = 1500; % Length of signal

t = (0:L-1)*T; % Time vector

x = 12*sin(2*pi*20*t)+8*sin(2*pi*100*t)+4*sin(2*pi*1000*t); % First row wave

figure;

plot(t,x);

title ('Original Signal');

%-----------------IIR Digital Filter (Fcutoff HPF 500 Hz)-------------

% Numerator

b0= 0.0074909098845689359; b1=-0.024939666312861833 ;

b2= 0.041954064312904264 ;

b3= -0.041954064312904264 ;

b4= 0.024939666312861833 ; b5= -0.0074909098845689359;

% Denumerator

a1= 2.677448793088633 ; a2=3.8083303551156718 ;

a3=3.1767832172611352 ; a4=1.5547078663147071 ;

a5= 0.36003693005994097 ;

x5=0;x4=0;x3=0;x2=0;x1=0;x0=0;

y5=0;y4=0;y3=0;y2=0;y1=0;y=0;

for i=1:L

y5=y4;

y4=y3;

y3=y2;

y2=y1;

y1=y;

%
x5=x4;

x4=x3;

x3=x2;

x2=x1;

x1=x0;

x0=x(i);

y=b0*x0 + b1*x1 + b2*x2 + b3*x3 + b4*x4 + b5*x5 + b6*x6 ...

-a1*y1 - a2*y2 - a3*y3 - a4*y4 - a5*y5 ;

yfilter(i)=y;

end

y = yfilter';

figure;

plot(t,y);

title ('Filtered Signal');

%-----------------Fast Fourier Transform (FFT) -------------------------

n = 2^nextpow2(L);

Yfft = fft(y,n);

P2 = abs(Yfft/L);

P1 = P2(1:n/2+1);

P1(1:end-1) = 2*P1(1:end-1);

figure;

plot(0:(Fsampling/n):(Fsampling/2-Fsampling/n),P1(1:n/2));

title ('Frequency of the signal');

You might also like