Visualization Device for Deafness

After being approached by a deaf mother unable to hear her fetus’s heartbeat, I created a visual representation of the fetal heartbeat.  An audio recording of the fetal heartbeat is passed from a computer’s audio jack and into a circuit.  The circuit consisted of a bandpass filters to get rid of DC offset, as well as electrical and violet noise.  The signal was amplified and enveloped to detect fetal heartbeats.  To determine the appropriate filter, amplification & envelope parameters, digital signal processing was used.  Once parameters were identified, a circuit was built to perform analog signal processing.  Finally, heartbeats from the original audio sample were visually represented by LEDs.

Video Demonstration:  https://youtu.be/34DD48fEktM


Digital Filter Design

To start this project, I performed digital signal processing on the initial sound sample.  I used MATLAB software to perform an FFT of the original sound sample.  This showed the presence of violet noise (500+Hz) and DC offset (0Hz).  We also know that the power supply causes noise at multiples of 60Hz (i.e. 60Hz, 120Hz, 240hz, etc.).  Even with this information, it is hard to distinguish which is the signal of interest purely based on the FFT.  This is the case for most signals.  Therefore, I rigorously tested different bandpass filter ranges, using second-order Butterworth filters, to get and idea of which cutoff frequencies are needed to recover the desired signal.

Second-order filters have better attenuation due to their sharper frequency cutoff.  This can be seen in the bode plot, as shown below.  By testing high-order filters, I found that there is a limit to this.  A fifteenth-order filter can filter the entire signal, leaving you with nothing.  I found that fifth-order filters were the most effective, in the digital environment.


Figure 1 - Bode plot comparison of first-order vs second-order filters.


I initially expected that the important frequencies would be within the bass spectrum (60-250Hz).  However, after rigorous testing of different bandpass filter ranges, as well as envelope detector performance, I concluded that the best signal was extracted from the sub-bass spectrum (20-60Hz), reference Appendix.  The DC offset (0Hz) and 60Hz power-supply range was avoided by using a bandpass of frequency range 20-40Hz.


Additional testing showed that a fifth-order bandpass filter between 20 & 40Hz led to a cleaner signal, reference Figure 2.  The sound of the filtered signal was played back to ensure the heartbeat sound was not lost.  Once the range was determined, I began constructing analog filters.  

Figure 2 - Results of final digital filters.  This provides comparison of filtered vs unfiltered signals.


Analog Filter Design


When testing analog filters to get an idea of cutoffs, I found these to be slightly different from the digital ones.  Fifth-order filters were effective in the digital environment, however, I found that this removed too much of the signal in the analog environment.  Therefore, I reduced the number of filters.  I found that the order of these filters also affected their effectiveness.  The final filters are described in Figures 3 & 4.

Figure 3 - Analog filter circuit flow chart.  Sallen-key filters are second-order.


Figure 4 - Analog filter circuit schematic.


Signal Gain & Envelope Detector Design


To make the fetal heartbeat easier for the Arduino to detect, I added gain to the circuit.  Initially, Vmax~0.12V.  This was quite low, due to the large number of filters in my circuit.  Amplifying a signal with Vmax~0.12V is helpful since the Arduino’s maximum Vin=5V.  Therefore, I designed the circuit to add a Gain~41.67.  To do this, I used an inverting op-amp and its respective equation Gain=1+R2/R1.  To achieve the gain that I wanted, I used R2=39k Ohm and R1=1k Ohm so that Gain=40.  


For this application, we are really interested in the low frequency heartbeat signal embedded in the high frequency audio sample.  To differentiate these two signals, and make the fetal heartbeat easier to detect, an envelope detector was used.  The envelope detector is essentially a half-wave rectifier used to determine the amplitude of the fetal heartbeat signal (120-180bpm).  Using the equation 1fCarrierRC1fLow where fCarrier=sub-bass frequency=20 to 60Hz≈40Hz and fLow=180bpm found by listening to sound sample=3Hz.  Therefore, 0.025RC0.33.  After rigorous testing, I found the optimal RC value to be 0.082.  The final circuit for analog gain & enveloping is provided in Figures 5 & 6.

Figure 5 - Envelope & gain circuit flow chart.
Figure 6 - Envelope & gain circuit schematic.


Visual Representation


I used the Arduino to visually represent the fetal heartbeat sound.  The original audio sample is passed through the analog filter circuit, described above.  Next, the Arduino reads in the filtered signal, and flashes LEDs when voltage input is above a certain threshold.  This effectively provides a visual representation of the fetal heartbeat.  The Arduino code for executing this process can be found in the Appendix.  A video (with sound) of my final device can be found here:  https://youtu.be/34DD48fEktM.

Conclusion


The filters and envelope detector do a very good job at detecting heartbeats.  It seems as though almost every heartbeat is successfully detected, though some are stronger than others (reference Figure 7).  Part of this success stemmed from rigorously testing different envelope parameters (reference Appendix).  I started with the equation 1fCarrierRC1fLow.  Then, I tested different resistor values until all heartbeats were detected.  The variation in pulse strength (height of green spike) is due to limitations of the original sound sample.  Testing multiple envelope parameters allowed me to overcome these limitations.



Figure 7 - Comparison of filtered signal (yellow) vs enveloped signal (green).  Final envelope parameters:  C=10uF, R = 8.2k Ohm.

Appendix - Digital Filter Bandwidth Testing






























Appendix - Digital Filter Design
Fig. - Breaking down frequencies into noise & useful information.


Fig. - Comparison of envelope performance in different frequency ranges.  This helped to motivate the bandwidth of my bandpass filter.

Appendix - Envelope Detector Testing


C=10uF, R=360 Ohm
C= 10uF, R=620 Ohm


C= 10uF, R=1.2k Ohm
C= 10uF, R=3k Ohm


Appendix - Arduino Code
float val;
int ledOne = 7;
int ledTwo = 8;
int ledThree = 9;
int ledFour = 10;
int ledFive = 11;


void setup() {
 Serial.begin(9600);
 pinMode(ledOne, OUTPUT);
 pinMode(ledTwo, OUTPUT);
 pinMode(ledThree, OUTPUT);
 pinMode(ledFour, OUTPUT);
 pinMode(ledFive, OUTPUT);
}


void loop() {
 val = analogRead(A0);
 Serial.println(val);
 if (val > 1) {
   digitalWrite(ledOne, HIGH);
   digitalWrite(ledTwo,HIGH);
   digitalWrite(ledThree,HIGH);
   digitalWrite(ledFour,HIGH);
   digitalWrite(ledFive,HIGH);
   delay(30);
 }
   digitalWrite(ledOne, LOW);
   digitalWrite(ledTwo,LOW);
   digitalWrite(ledThree,LOW);
   digitalWrite(ledFour,LOW);
   digitalWrite(ledFive,LOW);
 delay(5);
}
















Appendix - MATLAB Code


%%%%%%%%%%%%%%%%%%%%%%%%%% Acquire Origninal Singal %%%%%%%%%%%%%%%%%%%%%%%%%%%%
s = daq.createSession('ni');
addAnalogInputChannel(s,'myDaq1', 0, 'Voltage');
s.Rate = 44100;
s.DurationInSeconds = 35;
[data,time]=s.startForeground;
%%%%%%%%%%%%%%%%%%%%%%%%%% Graph Origninal Singal %%%%%%%%%%%%%%%%%%%%%%%%%%%%
subplot(2,1,1);
plot(time,data)
title('Original Signal');
xlabel('Time (secs)');
ylabel('Voltage');
%%%%%%%%%%%%%%%%%%%%%%%%%% FFT %%%%%%%%%%%%%%%%%%%%%%%%%%%%
Fs = 44100; % Sample Rate
fs = 44100; % Sample Rate
T = 1/Fs; % Sampling period       
L = length(data); % Length of signal
t = (0:L-1)*T; % Time vector
Y = fft(data); % Compute the Fourier transform of the signal.
Compute the two-sided spectrum P2. Then compute the single-sided
spectrum P1 based on P2 and the even-valued signal length L.
P2 = abs(Y/L);
P1 = P2(1:L/2+1);
P1(2:end-1) = 2*P1(2:end-1);
Define the frequency domain f and plot the single-sided amplitude
spectrum P1. The amplitudes are not exactly at 0.7 and 1, as expected,
because of the added noise. On average, longer signals produce better
frequency approximations.
f = Fs*(0:(L/2))/L;
subplot(2,1,2);
plot(f,P1)
title('Single-Sided Amplitude Spectrum of X(t)');
xlabel('f (Hz)');
ylabel('|P1(f)|');
%%%%%%%%%%%%%%%%%% 2nd-Order Butterworth Filter Annealed 1-5 Times %%%%%%%%%%%%%%%%%%%%%%%
fc = 55; % Cutoff Frequency
fs = 44100; % Sample Rate
[b,a] = butter(2,fc/(fs/2)); % 2nd-Order Butter
yb = filter(b,a,data);
subplot(5,1,1)
plot(time,yb)
title('First 2nd-Order Butterworth Filter - fc=250');
xlabel('Time (secs)');
ylabel('Voltage');


[b,a] = butter(2,fc/(fs/2)); % 2nd-Order Butter
ybb = filter(b,a,yb);
subplot(5,1,2)
plot(time,ybb)
title('Second 2nd-Order Butterworth Filter - fc=250');
xlabel('Time (secs)');
ylabel('Voltage');


[b,a] = butter(2,fc/(fs/2)); % 2nd-Order Butter
ybbb = filter(b,a,ybb);
subplot(5,1,3)
plot(time,ybbb)
title('Third 2nd-Order Butterworth Filter - fc=250');
xlabel('Time (secs)');
ylabel('Voltage');


[b,a] = butter(2,fc/(fs/2)); % 2nd-Order Butter
ybbbb = filter(b,a,ybbb);
subplot(5,1,4)
plot(time,ybbbb)
title('Fourth 2nd-Order Butterworth Filter - fc=250');
xlabel('Time (secs)');
ylabel('Voltage');


[b,a] = butter(2,fc/(fs/2)); % 2nd-Order Butter
ybbbbb = filter(b,a,ybbbb);
subplot(5,1,5)
plot(time,ybbbbb)
title('Fifth 2nd-Order Butterworth Filter - fc=250');
xlabel('Time (secs)');
ylabel('Voltage');


%%%%%%%%%%%%%%%% 2nd-Order Butterworth Filter Annealed 1-5 Times %%%%%%%%%%%%%%%%%%%%%%%%%%
subplot(5,1,1)
plot(time,ybbbbb)
title('Fifth 2nd-Order Butterworth Filter - fc=250');
xlabel('Time (secs)');
ylabel('Voltage');


fc = 55; % Cutoff Frequency
fs = 44100; % Sample Rate
[b,a] = butter(2,fc/(fs/2)); % 6
yb = filter(b,a,ybbbbb);
[b,a] = butter(2,fc/(fs/2)); % 7
yb = filter(b,a,yb);
[b,a] = butter(2,fc/(fs/2)); % 8
yb = filter(b,a,yb);
[b,a] = butter(2,fc/(fs/2)); % 9
yb = filter(b,a,yb);
[b,a] = butter(2,fc/(fs/2)); % 10
yb = filter(b,a,yb);
subplot(5,1,2)
plot(time,yb)
title('Tenth 2nd-Order Butterworth Filter - fc=250');
xlabel('Time (secs)');
ylabel('Voltage');


[b,a] = butter(2,fc/(fs/2)); % 11
yb = filter(b,a,yb);
[b,a] = butter(2,fc/(fs/2)); % 12
yb = filter(b,a,yb);
[b,a] = butter(2,fc/(fs/2)); % 13
yb = filter(b,a,yb);
[b,a] = butter(2,fc/(fs/2)); % 14
yb = filter(b,a,yb);
[b,a] = butter(2,fc/(fs/2)); % 15
yb = filter(b,a,yb);
subplot(5,1,3)
plot(time,yb)
title('Fifteenth 2nd-Order Butterworth Filter - fc=250');
xlabel('Time (secs)');
ylabel('Voltage');


[b,a] = butter(2,fc/(fs/2)); % 16
yb = filter(b,a,yb);
[b,a] = butter(2,fc/(fs/2)); % 17
yb = filter(b,a,yb);
[b,a] = butter(2,fc/(fs/2)); % 18
yb = filter(b,a,yb);
[b,a] = butter(2,fc/(fs/2)); % 19
yb = filter(b,a,yb);
[b,a] = butter(2,fc/(fs/2)); % 20
yb = filter(b,a,yb);
subplot(5,1,4)
plot(time,yb)
title('Twentieth 2nd-Order Butterworth Filter - fc=250');
xlabel('Time (secs)');
ylabel('Voltage');


[b,a] = butter(2,fc/(fs/2)); % 21
yb = filter(b,a,yb);
[b,a] = butter(2,fc/(fs/2)); % 22
yb = filter(b,a,yb);
[b,a] = butter(2,fc/(fs/2)); % 23
yb = filter(b,a,yb);
[b,a] = butter(2,fc/(fs/2)); % 24
yb = filter(b,a,yb);
[b,a] = butter(2,fc/(fs/2)); % 25
yb = filter(b,a,yb);
subplot(5,1,5)
plot(time,yb)
title('Twenty-fifth 2nd-Order Butterworth Filter - fc=250');
xlabel('Time (secs)');
ylabel('Voltage');


%%%%%%%%%%%%%%%%% High-Pass Filter %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
subplot(4,1,4)
x = highpass(y2,65,fs);
plot(time,x)
title('Bandpass Filter - fc={65,250}; fs=44100');
%legend('Input Data','Low-Pass Filtered Data', 'Bandpass Filtered Data');
xlabel('Time (secs)');
ylabel('Voltage');


%%%%%%%%%%%%%%%%% Alternative Filter = {10,55} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
fc = 55; % Cutoff Frequency
fs = 44100; % Sample Rate
[b,a] = butter(2,fc/(fs/2)); % 2nd-Order Butter
y3 = filter(b,a,data);
[b,a] = butter(2,fc/(fs/2)); % 2nd-Order Butter
y4 = filter(b,a,y3);
x2 = highpass(y4,20,fs);
plot(time,x2)
title('Bandpass Filter - fc={65,250}; fs=44100');
%legend('Input Data','Low-Pass Filtered Data', 'Bandpass Filtered Data');
xlabel('Time (secs)');
ylabel('Voltage');


%%%%%%%%%%%%%%%%% Compare the Two Filters %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
figure()
subplot(3,1,1)
plot(time,data)
title('Original Signal');
xlabel('Time (secs)');
ylabel('Voltage');


subplot(3,1,2)
plot(time,x)
title('Bandpass Filter - fc={65,250}');%; fs=44100');
xlabel('Time (secs)');
ylabel('Voltage');


subplot(3,1,3)
plot(time,x2)
title('Bandpass Filter - fc={20,55}');%; fs=44100');
xlabel('Time (secs)');
ylabel('Voltage');


%%%%%%%%%%%%%%%%% Compare Multiple Bandpass Ranges %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
upperBound = 240;
lowerBound = 0;
fc = upperBound; % Cutoff Frequency
fs = 44100; % Sample Rate
[b,a] = butter(2,fc/(fs/2)); % 2nd-Order Butter
yb = filter(b,a,data);
[b,a] = butter(2,fc/(fs/2)); % 2nd-Order Butter
ybb = filter(b,a,yb);
b1 = highpass(ybb,upperBound,fs);


upperBound = 60;
lowerBound = 20;
fc = upperBound; % Cutoff Frequency
fs = 44100; % Sample Rate
[b,a] = butter(2,fc/(fs/2)); % 2nd-Order Butter
yb = filter(b,a,data);
[b,a] = butter(2,fc/(fs/2)); % 2nd-Order Butter
ybb = filter(b,a,yb);
b2 = highpass(ybb,upperBound,fs);


upperBound = 40;
lowerBound = 20;
fc = upperBound; % Cutoff Frequency
fs = 44100; % Sample Rate
[b,a] = butter(2,fc/(fs/2)); % 2nd-Order Butter
yb = filter(b,a,data);
[b,a] = butter(2,fc/(fs/2)); % 2nd-Order Butter
ybb = filter(b,a,yb);
b3 = highpass(ybb,upperBound,fs);


upperBound = 180;
lowerBound = 120;
fc = upperBound; % Cutoff Frequency
fs = 44100; % Sample Rate
[b,a] = butter(2,fc/(fs/2)); % 2nd-Order Butter
yb = filter(b,a,data);
[b,a] = butter(2,fc/(fs/2)); % 2nd-Order Butter
ybb = filter(b,a,yb);
b4 = highpass(ybb,upperBound,fs);


upperBound = 120;
lowerBound = 60;
fc = upperBound; % Cutoff Frequency
fs = 44100; % Sample Rate
[b,a] = butter(2,fc/(fs/2)); % 2nd-Order Butter
yb = filter(b,a,data);
[b,a] = butter(2,fc/(fs/2)); % 2nd-Order Butter
ybb = filter(b,a,yb);
b5 = highpass(ybb,upperBound,fs);


subplot(2,1,1)
plot(time,b1)
title('Bandpass Filter - fc={180,240}');
xlabel('Time (secs)');
ylabel('Voltage');


subplot(2,1,2)


subplot(2,1,1)
plot(time,b2)
title('Bandpass Filter - fc={20,60}');
xlabel('Time (secs)');
ylabel('Voltage');


%%%%%%%%%%%%%%%% ENVELOPE DETECTOR %%%%%%%%%%%%%%%%%%%%%%%
subplot(2,1,2)
Y = Y * 10;
Y = abs(b2);
figure()
subplot(3,1,1);
plot(time,b1)
[up,lo] = envelope(b1,5000,'peak');
hold on
plot(time,up,time,lo,'linewidth',1.5);
legend('q','up','lo')
hold off
title('Bandpass Filter - fc={0,240}');
xlabel('Time (secs)');
ylabel('Voltage');
hold off


subplot(3,1,2);
plot(time,b2)
[up,lo] = envelope(b2,2000,'peak');
hold on
plot(time,up,time,lo,'linewidth',1.5);
legend('q','up','lo')
hold off
title('Bandpass Filter - fc={20,60}');
xlabel('Time (secs)');
ylabel('Voltage');
hold off


subplot(3,1,3);
plot(time,b3)
[up,lo] = envelope(b3,5000,'peak');
hold on
plot(time,up,time,lo,'linewidth',1.5);
legend('q','up','lo')
hold off
title('Bandpass Filter - fc={180,240}');
xlabel('Time (secs)');
ylabel('Voltage');
hold off


Y = b2;
[up,lo] = envelope(b1,10000,'peak');
plot(time,Y);
hold on
plot(t,up,t,lo,'linewidth',1.5);
legend('q','up','lo')
%hold off
title('Absolute Value - Bandpass Filter - fc={20,60}');
xlabel('Time (secs)');
ylabel('Voltage');
hold off


subplot(5,1,3)
plot(time,b3)
title('Bandpass Filter - fc={180,240}');
xlabel('Time (secs)');
ylabel('Voltage');


subplot(5,1,4)
plot(time,b4)
title('Bandpass Filter - fc={120,180}');
xlabel('Time (secs)');
ylabel('Voltage');


subplot(5,1,5)
plot(time,b5)
title('Bandpass Filter - fc={60,120}');
xlabel('Time (secs)');
ylabel('Voltage');


upperBound = 250;
lowerBound = 60;
fc = upperBound; % Cutoff Frequency
fs = 44100; % Sample Rate
[b,a] = butter(2,fc/(fs/2)); % 2nd-Order Butter
yb = filter(b,a,data);
[b,a] = butter(2,fc/(fs/2)); % 2nd-Order Butter
ybb = filter(b,a,yb);
b4 = highpass(ybb,upperBound,fs);


upperBound = 230;
lowerBound = 80;
fc = upperBound; % Cutoff Frequency
fs = 44100; % Sample Rate
[b,a] = butter(2,fc/(fs/2)); % 2nd-Order Butter
yb = filter(b,a,data);
[b,a] = butter(2,fc/(fs/2)); % 2nd-Order Butter
ybb = filter(b,a,yb);
b5 = highpass(ybb,upperBound,fs);


upperBound = 210;
lowerBound = 200;
fc = upperBound; % Cutoff Frequency
fs = 44100; % Sample Rate
[b,a] = butter(2,fc/(fs/2)); % 2nd-Order Butter
yb = filter(b,a,data);
[b,a] = butter(2,fc/(fs/2)); % 2nd-Order Butter
ybb = filter(b,a,yb);
b6 = highpass(ybb,upperBound,fs);


figure()
subplot(3,1,1)
plot(time,b4)
title('Bandpass Filter - fc={60,250}');
xlabel('Time (secs)');
ylabel('Voltage');


subplot(3,1,2)
plot(time,b5)
title('Bandpass Filter - fc={80,230}');
xlabel('Time (secs)');
ylabel('Voltage');


subplot(3,1,3)
plot(time,b6)
title('Bandpass Filter - fc={200,210}');
xlabel('Time (secs)');
ylabel('Voltage');


%%%%%%%%%%%%%%%%%%%%%%% Play Sound %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
sound(b1,44100)
clear sound % stop playback


%%%%%%%%%%%%%%%%%%%%%%Testing Different Cutoff Frequencies %%%%%%%%%%%%%%%%%%%%%%%%%
subplot(5,2,2);
fc = 600; % Cutoff Frequency
fs = 44100; % Sample Rate
[b,a] = butter(2,fc/(fs/2)); % 2nd-Order Butter
y = filter(b,a,data);
y = y * 10;
plot(time,data)
hold on
plot(time,y)
title('Input vs Filtered Signal - fc=600; fs=44100');
legend('Input Data','Filtered Data');
xlabel('Time (secs)');
ylabel('Voltage');
%%%%%%%%%%%
subplot(5,2,3);
fc = 400; % Cutoff Frequency
fs = 44100; % Sample Rate
[b,a] = butter(2,fc/(fs/2)); % 2nd-Order Butter
y = filter(b,a,data);
y = y*10;
plot(time,data)
hold on
plot(time,y)
title('Input vs Filtered Signal - fc=400; fs=44100');
legend('Input Data','Filtered Data');
xlabel('Time (secs)');
ylabel('Voltage');
%%%%%%%%%%%
subplot(5,2,4);
fc = 120; % Cutoff Frequency
fs = 44100; % Sample Rate
[b,a] = butter(2,fc/(fs/2)); % 2nd-Order Butter
y = filter(b,a,data);
y=y*10;
plot(time,data)
hold on
plot(time,y)
title('Input vs Filtered Signal - fc=120; fs=44100');
legend('Input Data','Filtered Data');
xlabel('Time (secs)');
ylabel('Voltage');
%%%%%%%%%%%
subplot(5,2,5);
fc = 100; % Cutoff Frequency
fs = 44100; % Sample Rate
[b,a] = butter(2,fc/(fs/2)); % 2nd-Order Butter
y = filter(b,a,data);
y = y * 10;
plot(time,data)
hold on
plot(time,y)
title('Input vs Filtered Signal - fc=100; fs=44100');
legend('Input Data','Filtered Data');
xlabel('Time (secs)');
ylabel('Voltage');
%%%%%%%%%%%
subplot(5,2,6);
fc = 80; % Cutoff Frequency
fs = 44100; % Sample Rate
[b,a] = butter(2,fc/(fs/2)); % 2nd-Order Butter
y = filter(b,a,data);
y = y * 10;
plot(time,data)
hold on
plot(time,y)
title('Input vs Filtered Signal - fc=80; fs=44100');
legend('Input Data','Filtered Data');
xlabel('Time (secs)');
ylabel('Voltage');
%%%%%%%%%%%
subplot(5,2,7);
fc = 60; % Cutoff Frequency
fs = 44100; % Sample Rate
[b,a] = butter(2,fc/(fs/2)); % 2nd-Order Butter
y = filter(b,a,data);
y = y * 20;
plot(time,data)
hold on
plot(time,y)
title('Input vs Filtered Signal - fc=60; fs=44100');
legend('Input Data','Filtered Data');
xlabel('Time (secs)');
ylabel('Voltage');
%%%%%%%%%%%
subplot(5,2,8);
fc = 40; % Cutoff Frequency
fs = 44100; % Sample Rate
[b,a] = butter(2,fc/(fs/2)); % 2nd-Order Butter
y = filter(b,a,data);
y = y * 30;
plot(time,data)
hold on
plot(time,y)
title('Input vs Filtered Signal - fc=40; fs=44100');
legend('Input Data','Filtered Data');
xlabel('Time (secs)');
ylabel('Voltage');
%%%%%%%%%%%
subplot(5,2,9);
fc = 20; % Cutoff Frequency
fs = 44100; % Sample Rate
[b,a] = butter(2,fc/(fs/2)); % 2nd-Order Butter
y = filter(b,a,data);
y = y * 100;
plot(time,data)
hold on
plot(time,y)
title('Input vs Filtered Signal - fc=20; fs=44100');
legend('Input Data','Filtered Data');
xlabel('Time (secs)');
ylabel('Voltage');
%%%%%%%%%%%
subplot(5,2,10);
fc = 10; % Cutoff Frequency
fs = 44100; % Sample Rate
[b,a] = butter(2,fc/(fs/2)); % 2nd-Order Butter
y = filter(b,a,data);
y = y * 100;
plot(time,data)
hold on
plot(time,y)
title('Input vs Filtered Signal - fc=10; fs=44100');
legend('Input Data','Filtered Data');
xlabel('Time (secs)');
ylabel('Voltage');


%%%%%%%%%%%%%%%%%%%%% Sound Playback %%%%%%%%%%%%%%%%%%%%%%%%%%%%
fc = 40; % Cutoff Frequency
fs = 44100; % Sample Rate
[b,a] = butter(2,fc/(fs/2)); % 2nd-Order Butter
y = filter(b,a,data);
y = y * 30;
sound(y,fs)


%%%%%%%%%%%%%%%%%% Bode Plot of Filter Transfer Function%%%%%%%%%%%%%%%%%%%%%%%%%%%%
freqz(b,a)
figure(3)
dataIn = randn(1000,1);
dataOut = filter(b,a,dataIn);
plot(dataIn,dataOut)






























0 comments:

Post a Comment

My Instagram