Тёмный
No video :(

(How to) Create A Digital Filter in Python - Signal Processing #20 

Tutorials with Gary
Подписаться 3,9 тыс.
Просмотров 49 тыс.
50% 1

An example of a python implementation of a digital filter which we designed in a previous video.
Code: drive.google.com/file/d/0B6hN...

Опубликовано:

 

12 авг 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 51   
@refrefwgwgwegew
@refrefwgwgwegew 2 года назад
Such amazing explanation. You got a sub over here:). I am trying to replicate a freq. response filter from a scientific paper it seems to use 3 filters. Each filter filters out different frequency intervals. To give an example: It filters out the 0 frequency-until 0.1, the graph peeks than at 0.25, but after that it has some more filtering that is applied. How do I go about filtering out multiple frequencies. I really hope you can provide me with some insight! Best regards, new sub:)
@manchcadwallader6166
@manchcadwallader6166 5 лет назад
Hi Luke! I have plenty of signal processing experience and use it on the job, but I'm lacking in coding experience. What if it was a continuous signal, or rather a string of samples?
@TutorialsWithGary
@TutorialsWithGary 5 лет назад
Hey, this approach will only work for a discrete filter sorry, but you could just sample your continuous signal and pass it through a filter such as the one we went through in this video. Not sure what you mean by a string of samples, are there multiple samples in a string object separated by some sort of delimiter? Thanks
@adityakapadi2104
@adityakapadi2104 5 лет назад
hi luke, i have a raw data of time vs Amplitude and if i want to apply filter & reduce the noise. how i m gonna do it ?? can you suggest some possible ways ? i have a frequency of 7.835 MHz.
@TutorialsWithGary
@TutorialsWithGary 4 года назад
Hey sorry for the very delayed reply here! Filtering raw amplitude data over time is exactly what we have done here, using the steps I have gone through in my previous videos you should be able to define a filter for the frequencies you care about and implement it in the exact same way as we have here
@kiddyboy1540
@kiddyboy1540 4 года назад
Hi Luke.. Just a doubt.. The plot that you have shown.. Actually the output we get from the filter is a frequency wave right? Technically, the output that you show isn't just the magnitude right? That is Magnitude+phase, that your plot's y-axis indicates.. am I right?
@TutorialsWithGary
@TutorialsWithGary 4 года назад
Hey, in this case here the output is the raw output transformed signal. It won’t look as simple as the output signal you are using because here we are only using two distinct frequencies. Real world information is a lot messier :)
@kiddyboy1540
@kiddyboy1540 4 года назад
Luke, a follow-up as well.. Supposing I need a continuous signal, you use the convolution process right? And also, you won't create empty arrays but rather just create continuous signals right? Can you just type down the sample code here for some random input continuous signal and a continuous filter(I assume you define the impulse function for the filter here and use that for the convolution with the signal ). If there are any mistakes in my line of thought or they need clarification or you want to add something on top, can you be as detailed as possible? I'm kinda slow and can understand better if explained in a simplified but detailed manner. Thanks in advance!!
@TutorialsWithGary
@TutorialsWithGary 4 года назад
This process will work just as well for a continuous signal but you would have to implement a more complex system around it my example here. And sorry I make a point to not give out code as a response to questions because people can use it to cheat on university work.
@kiddyboy1540
@kiddyboy1540 4 года назад
@@TutorialsWithGary Alright I get it. Thanks!!
@juanfelipemontana3635
@juanfelipemontana3635 6 лет назад
Hellow, luke. thanks for tutorial. so i have a question in new talking about sounds and signals and i watch the video and i get that if i modify de 48 khz the bandpass filter change what i dont understand is that what value should i need for examplee to filter 3->4 khz signals. should i use 16khz and not 48 ? how do i know that ?
@TutorialsWithGary
@TutorialsWithGary 6 лет назад
Hey Juan! So this what your describing actually has a name - The Nyquist frequency, which is essentially saying, at what frequency so i have to sample my audio stream to ensure that I dont miss any information about my input signal, this is typically denoted as: "the minimum rate at which a signal can be sampled without introducing errors, which is twice the highest frequency present in the signal" Thus if you were looking to signals up to 4kHz, an 8kHz sampling rate should be good enough. This doen't mean that having a sampling frequency any higher will negatively impact the result - if anything it will make the output look cleaner. So anything above 8kHz (even the same 48 that we used in this example) would work fine :) Link: en.wikipedia.org/wiki/Nyquist_frequency
@juanfelipemontana3635
@juanfelipemontana3635 6 лет назад
ty for answer luke, i will look into Nyquist thorem, one last thing i modified de program to reproduce the sound depending of the input frecuency, of course. do you know how could i reproduce the sound after the signal is filtered ? or how can i get the frecuency of the signal after this pass through the filter
@TutorialsWithGary
@TutorialsWithGary 6 лет назад
You sure can, the output data is the sound wave that it generated as an outcome of the filter. If you want to listen to it, you can export it as a *.wav file pretty easily in python, you can follow this to work out how: docs.python.org/2/library/wave.html If you have any problems and can't do it, let me know and I should be able to write something that does for you.
@juanfelipemontana3635
@juanfelipemontana3635 6 лет назад
Thanks a lot, bro i use wave library and i can reproduce the sound of the filtred signal. thanks, man
@TutorialsWithGary
@TutorialsWithGary 6 лет назад
No problems, glad to help!
@akiriisio8558
@akiriisio8558 7 лет назад
Hello. I recently started a small project where I would do a program which analyzes an audio stream (from microphone). My plan is to make my own speech recognition in my own native language (finnish). I have very little background in signal processing so I'm having a hard time to get started. Do you have any tips where to look? The plan was not to use the existing libraries for speech recognition.
@TutorialsWithGary
@TutorialsWithGary 7 лет назад
Hi Aki, A few things before i try to help, Do you have any programming experience prior to this? And what background in signal processing do you have? If its more theoretical rather than applied this could put you in a good space to develop skills further with online tools rather than having to take a course.
@akiriisio8558
@akiriisio8558 7 лет назад
Wow, fastest response ever. I've used Python in my own projects for 7 years now mostly related to RaspberryPi3. Some small projects like analyzing WhatsApp chats, movement recognition and so on.. And for one year now I've used Python in data engineering for basic ETL. Mostly working with API's and databases. Some web scraping as well. So I think I've moved on to the next level now from the basics. My background in signal processing is very limited. Only two courses way back in college (theory) and one applied course. I am familiar with Fourier transforms and the basic math behind this. I also believe my music background helps a lot since I'm processing wave forms all the time while making music.
@TutorialsWithGary
@TutorialsWithGary 7 лет назад
Good timing :) Okay programming wise you sound pretty confident which is a good start. If you've had some signal processing experience through college I'd probably be asking what aspects of the project that you'll be needing help with. I'd personally look into research papers, could lead to some really good ideas. There's one particular paper which has had a lot of interest, which uses hidden Markov models. It's an IEEE paper (been spoiled, as a student it can be accessed for free) but might be worth the investment. ieeexplore.ieee.org/abstract/document/18626/
@akiriisio8558
@akiriisio8558 7 лет назад
Thank you very much. Reading the abstract, I think this is exactly what I need. I'd also like to thank you for this signal processing series (which I haven't completed *yet*). I'm sure it will help me during my project.
@TutorialsWithGary
@TutorialsWithGary 7 лет назад
No problems, Good luck with the project and thanks for watching :)
@AzeezAbass
@AzeezAbass 5 лет назад
How would you go about plotting the bode plot for your filter function? i.e.: have some random filter function and you don't know how it works but you still want to plot it.
@TutorialsWithGary
@TutorialsWithGary 5 лет назад
Hey Azeez, plotting bode plots from transfer functions really isnt too difficult :) There's an awesomne explaination / example that you can find here: lpsa.swarthmore.edu/Bode/BodeExamples.html
@AzeezAbass
@AzeezAbass 5 лет назад
@@TutorialsWithGary Thank you for the source, it explains it well in a mathematical sense. But I was wondering if it could be done in Python for some unknown python function that takes in an array and spits out the filtered data, the only other way I can think of of giving it a bunch of different frequency sine waves and finding the response for each one. I've moved on to using scipy for my project, but I'm still wondering if this is possible.
@TutorialsWithGary
@TutorialsWithGary 5 лет назад
SciPy is actually pretty awesome. You could find a library to solve for the poles, then construct a graph but I can't think of any simple way sorry other than using something like SciPy :)
@Stanleywei0509
@Stanleywei0509 6 лет назад
Hi, Luke. I have some questions as follows: 1. Is this a band-pass filter, right? 2. How to know the formula for y? Thank you for your teaching.
@TutorialsWithGary
@TutorialsWithGary 6 лет назад
+CHIA-CHEN Wei hey hey, Yes this is a band pass filter :) We calculated the coefficients for this filter in a couple of previous videos (the process which is quite enjoyable but I'm biased) which you can find here: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-WJ7WeKgdcQw.html
@Stanleywei0509
@Stanleywei0509 6 лет назад
Thank you for replying me quickly.
@Stanleywei0509
@Stanleywei0509 6 лет назад
I watch video that you suggest, I don't know how to get the H function and how to get formula y from H?
@TutorialsWithGary
@TutorialsWithGary 6 лет назад
Watch the following 2 or so videos and we go through all the steps :)
@Stanleywei0509
@Stanleywei0509 6 лет назад
Ok, thank you for your suggestion.
@dotink9209
@dotink9209 6 лет назад
How about band reject filter?
@TutorialsWithGary
@TutorialsWithGary 6 лет назад
Yes! In fact it's called a band stop filter. An in the same way that we can convert a low pass into a high pass or band pass, we can also convert it into a band stop, you can find an explanation here: www.rfcafe.com/references/electrical/filters.htm
@TutorialsWithGary
@TutorialsWithGary 6 лет назад
Pre-warning the site has some terrible advertising, direct link: www.rfcafe.com/references/electrical/images/filter4.gif
@dotink9209
@dotink9209 6 лет назад
Luke Berry Thank you very much! 😀
@johnsaeid95
@johnsaeid95 7 лет назад
where did u get the coefficients of the filter , i can't use signal.butter in python
@TutorialsWithGary
@TutorialsWithGary 7 лет назад
+Hanna Nabil hi, The first video explaining how we got the coefficients is: firstly we calculated the frequency response in this video ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-WJ7WeKgdcQw.html Then we calculated the filter coefficients given the frequency response in this one: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-uZGqFZD3S10.html If you are using the scipy library for your Butterworth filter, and you have imported it as scipy, you will need to use scipy.signal.butter, details can be found here docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.signal.butter.html
@johnsaeid95
@johnsaeid95 7 лет назад
Thanks For reply Man i really appreciate it so um trying to implement a digital filter for a signal from .wav file it's sampling rate = 38000 so i used this command b, a = signal.butter(5,5000/nyq, btype='low', analog=False, output='ba') where nyq = 0.5 * 38000 so i implement a low pass filter that cuts all above 5000 hz just like what u did in that video but when adding a frequency of 6000 it does not filter it ,, actually it begin to filter from 15000 hz Do you know why ?? Thanks in advance :D
@TutorialsWithGary
@TutorialsWithGary 7 лет назад
Edit: Not this.
@johnsaeid95
@johnsaeid95 7 лет назад
when i tried first divide the nyq by np.pi and apply it made a strange output and does not filter what above 5000 when multiply by np.pi reduce the magnitude of all the frequencies below 5000 and above >>> actually i put the whole code on stackoverflow stackoverflow.com/questions/43947999/digital-filter-coefficients-using-butter ** Another thing Can i have your E-mail :D
@ritanovitasari9653
@ritanovitasari9653 7 месяцев назад
heloo can u help me ValueError Traceback (most recent call last) Cell In[12], line 15 12 return y 14 ###Read in desired frequency from command line ---> 15 frequency = int(sys.argv[1]) 17 ### Create empty arrays 18 input = [0]*48000 ValueError: invalid literal for int() with base 10: '-f'
@TutorialsWithGary
@TutorialsWithGary 7 месяцев назад
Hey, what value are you passing in for your frequency? It looks like python can’t parse it to an integer
Далее
Denoising Data with FFT [Python]
10:03
Просмотров 171 тыс.
Can You Forge Tungsten?
16:14
Просмотров 536 тыс.