Dynamic spectrum (spectrogram) using Python

The signal processing course has reached a stage where the discrete Fourier transform has been introduced. Once all the theorems are proved, the applications begin. Here's a little python code to analyze time-frequency content of a signal. The signal is divided into snippets of time, which can be overlapping in time. Each snippet is discrete Fourier transformed using a windowed and zero padded FFT.

Here's an example output:
Dynamic spectrum of a chirped signal. 
Here's the code:

#!/usr/bin/env python
# 
# (c) 2017 Juha Vierinen
import numpy as n
import matplotlib.pyplot as plt
import scipy.signal as s

# create dynamic spectrum
def spectrogram(x,M=1024,N=128,delta_n=100):
    max_t=int(n.floor((len(x)-N)/delta_n))
    t=n.arange(max_t)
    X=n.zeros([max_t,M],dtype=n.complex64)
    w=s.hann(N)
    xin=n.zeros(N)
    for i in range(max_t):
        xin[0:N]=x[i*delta_n+n.arange(N)]
        X[i,:]=n.fft.fft(w*xin,M)
    return(X)

# sample rate (Hz)
fs=4096.0

# sample indexes (one second of signal)
nn=n.arange(4096)
# generate a chirp signal
x=n.sin(0.15e-14*nn**5.0)

# time step
delta_n=25
M=2048
# create dynamic spectrum.
# Use
# - 2048 point FFT
# - 128 samples for each spectra
# - 100 sample increments in time
S=spectrogram(x,M=M,N=128,delta_n=delta_n)
freqs=n.fft.fftfreq(2048,d=1.0/fs)
time=delta_n*n.arange(S.shape[0])/fs

# plot signal
plt.figure(figsize=(12,10))
plt.subplot(211)
plt.plot(nn/fs,x)
plt.title("Signal $x[n]$")
plt.xlabel("Time (s)")
plt.ylabel("Signal amplitude")
plt.subplot(212)

plt.title("Spectrogram")
plt.pcolormesh(time,freqs[0:(M/2)],n.transpose(10.0*n.log10(n.abs(S[:,0:(M/2)])**2.0)),vmin=0)
plt.xlim([0,n.max(time)])
plt.ylim([0,fs/2.0])
plt.xlabel("Time (s)")
plt.ylabel("Frequency (Hz)")
cb=plt.colorbar(orientation="horizontal")
cb.set_label("dB")
plt.tight_layout()
plt.savefig("dynspec.png")
plt.show()

Comments

  1. This comment has been removed by a blog administrator.

    ReplyDelete
  2. This Nice blog is very informative. I’m looking and reading your points is so impressive. Regards,
    Blue prism Training in Chennai | Blue prism Training in Besant Nagar

    ReplyDelete
  3. Excellent and useful blog admin, I would like to read more about this topic.
    UIPath Training in Chennai | UIPath Training in Guindy

    ReplyDelete
  4. Nice article… I am sure I will share this information to my friends and relatives. Best Electrical Project Center in ChennaI | Best Electrical Project Center in Tambaram

    ReplyDelete
  5. Excellent information with unique content and it is very useful to know about the information based on blogs...Best MBA Project Center in Chennai |Best MBA Project Center in Perungudi

    ReplyDelete
  6. Nice article… I am sure I will share this information to my friends and relatives. Thanks for sharing the useful blog
    Ethical Hacking Training in Chennai | Ethical Hacking Training in Taramani

    ReplyDelete
  7. This is a good post. This post give truly quality information. I’m definitely going to look into it. Really very useful tips are provided here. thank you so much. Keep up the good works.
    Best Automation Anywhere Training Institute in Chennai | Best Automation Anywhere Training Institute in Velachery

    ReplyDelete
  8. Really nice article!!! I got more info to your innovate post. I like more addition info to your blog, keep posting....
    No.1 Ethical Hacking Training institute in Chennai | No.1 Ethical Hacking Training institute in Velachery

    ReplyDelete
  9. Thanks a lot very much for the high your blog post quality and results-oriented help. I won’t think twice to endorse to anybody who wants and needs support about this area.
    Blueprism Exam Center in Chennai | Blueprism Exam Center in Velachery

    ReplyDelete
  10. Great post! This is very useful for me and gain more information, Thanks for sharing with us.
    No.1 UIPath Training Institute in Chennai | No.1 UIPath Training Institute in Velachery

    ReplyDelete
  11. A good blog. Thanks for sharing the information. It is very useful for my future. keep sharing.
    Advanced Ethical Hacking course in Chennai | Certified Ethical Hacking Training in Velachery

    ReplyDelete
  12. It's very great post... Really you are... done a wonderful job Keep up the good work and continue sharing like this.
    No.1 RPA Training institute in Chennai | No.1 RPA Training institute in Velachery

    ReplyDelete
  13. This blog is really helpful and interesting and well appreciated! Thank you so much for sharing this great article
    No.1 Automation Anywhere Training Institute in Chennai | No.1 Automation Anywhere Training Institute in Velachery

    ReplyDelete
  14. Thanks for giving Good Example. Fantastic article, Viral. Very well written, clear and concise.
    No.1 UIPath Training Institute in Chennai | No.1 UIPath Training Institute in Velachery

    ReplyDelete
  15. Thank you for this brief explanation and ver nice information. well, got a good knowledge. Have a nice idea, this is more helpful to me. This can gives the better performance.
    No.1 RPA Training institute in Chennai | No.1 RPA Training institute in Velachery

    ReplyDelete
  16. Thank you for sharing wonderful information with us to get some idea about that content. check it once through.
    No.1 Blue Prism Training Institute in Chennai | No.1 Blue Prism Training Institute in Velachery

    ReplyDelete
  17. Thank you for your information. I have got some important suggestions from it. Keep on sharing. Best MBA project center in Chennai| Best MBA Project Center Tharamani

    ReplyDelete
  18. Best Electrical project center in Chennai| Best Electrical Project Center Perungudi This blog is really useful and it is very interesting thanks for sharing, it is really good and exclusive.

    ReplyDelete
  19. Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge.
    Blue Prism Training in Chennai | Blue Prism Training in Taramani | Blue Prism Training in Velachery

    ReplyDelete
  20. Excellent information with unique content and it is very useful to know about the information based on blogs...
    Selenium course in Taramani | Selenium Certification in Tambaram | Selenium Training in Chennai | Selenium Training Center in Velachery

    ReplyDelete
  21. This is really too useful and have more ideas from yours. keep sharing many techniques and thanks for sharing the information.
    Blue Prism Training in Chennai | Blue Prism Certification in Medavakkam | Blue Prism Training Center in Velachery

    ReplyDelete
  22. Your Blog is really awesome with useful and helpful content for us. Thanks for sharing. Keep updating more information.
    Selenium Training in Tambaram | Selenium Training Center in Chennai | Selenium Certification in Velachery | Selenium Exam Center in Medavakkam

    ReplyDelete
  23. Nice blog. I feel really happy to have seen your webpage and look forward to so many more entertaining times reading here. Thanks once more for all the details.
    Best Power System Project in Chennai | Best Power System Project in Guindy

    ReplyDelete
  24. Nice blog, really I feel happy to see this useful blog… Thanks for sharing this valuable information to our vision.I’m expecting much of these useful things. JAVA Certification Course in Chennai | JAVA Certification Course in Velachery

    ReplyDelete
  25. Its really informative blog.I found useful. Thanks for sharing

    awesome post. JAVA Training Course in Chennai | JAVA Training Course in Velachery

    ReplyDelete
  26. Pretty article! I found some useful information in your blog, it was awesome to read, thanks for sharing this great content to my vision, keep sharing.
    Selenium Training Institute in Chennai | Selenium Certification in Pallikaranai | Selenium Course in Velachery | Selenium Training Center in Medavakkam

    ReplyDelete
  27. It was wonderful article and I was really impressed by reading this blog.keep doing share this kind of articles.
    C / C++ Training Institute in Chennai | C / C++ Training Institute in Velachery

    ReplyDelete
  28. Really i enjoyed very much. And this may helpful for lot of peoples. So you are provided such a nice and great article within this.
    Android Training Center in Chennai | Android Training Centre in Velachary | Android Training Centre in Kancheepuram |

    ReplyDelete
  29. This is really too useful and have more ideas from yours. keep sharing many techniques and thanks for sharing the information.
    Best Graphic Designing Training Institute in Chennai | Best Graphic Designing Training Institute in Kanchipuram

    ReplyDelete
  30. This is really too useful and have more ideas from yours. Keep sharing many techniques and thanks for sharing the information.
    Android Training in Chennai | Android Training Center in Velachery | Android Training Institute in Pallikaranai

    ReplyDelete
  31. Good post..Thanks for sharing this wonderful post..Keep blogging.
    RPA Training in Chennai | RPA Training in Kanchipuram

    ReplyDelete
  32. Thank you so much for sharing this worthful content with us. The concept of here will be useful for know something in future programs. JAVA / J2EE Training courses in Chennai | JAVA / J2EE Training courses in Velachery

    ReplyDelete
  33. This is really too useful and have more ideas from yours. keep sharing many techniques and thanks for sharing the information.
    Blue Prism Training in Chennai | Blue Prism Training Center in Chennai | Blue Prism Certification in Chennai | Blue Prism Training Institute in Chennai

    ReplyDelete
  34. Nice blog,good message in this.Really I feel happy to see this useful blog… Sincere thanks for sharing this valuable information to our vision..... Android Training Institute in chennai | Android Training Institute in Velachery

    ReplyDelete
  35. This is really too useful and have more ideas from yours. Keep sharing many techniques. Eagerly waiting for your new blog and useful information. Keep doing more.
    Selenium Training Center in Chennai | Selenium Training Center in Velachery | Selenium Training Center in Taramani | Selenium Training Center in Madipakkam | Selenium Training Center in Pallikaranai

    ReplyDelete
  36. Excellent post. I have read your blog it's very interesting and informative. Keep sharing this kind of worthful ideas. Web Design Training in Chennai | Web Design Training in Velachery

    ReplyDelete
  37. Very good and informative article. Thanks for sharing such nice article, keep on updating such good articles.
    Android Training Institute in Chennai | Android Training Institute in Velachery | Android Training Center in Taramani

    ReplyDelete
  38. Good Informative post. I have read your blog it's very interesting and useful. Keep sharing this kind of worthful ideas. Android Training in Chennai | Android Training in Velachery

    ReplyDelete
  39. Pretty article! I found some useful information in your blog, it was awesome to read, thanks for sharing this great content to my vision, keep sharing.
    Android Training Institute in Chennai | Android Training Institute in Velachery | Android Training Institute in Kanchipuram

    ReplyDelete
  40. Thanks for sharing this valuable information to useful our vision.Keep sharing your post regularly.. Software Testing Training in Chennai | Software Testing Training in Velachery

    ReplyDelete
  41. Thanks for sharing this valuable information to useful our vision.Keep sharing your post regularly.. Software Testing Training in Chennai | Software Testing Training in Velachery

    ReplyDelete
  42. Your Blog is really wonderful..I have read your article,its very useful to us..keep updating related posts. C / C++ Training Courses in Chennai | C / C++ Training Courses in Velachery

    ReplyDelete
  43. Excellent information with unique content and it is very useful to know about the information based on blogs...
    Java Training Institute in Chennai | Java Training Center in Velachery | Java Training in Kanchipuram

    ReplyDelete
  44. Very good and informative article. Thanks for sharing such nice article, keep on updating such good articles.
    Selenium Training Center in Chennai | Selenium Training in Velachery | Selenium Exam Center in Chennai

    ReplyDelete
  45. Impressive blog with lovely information really very useful article for us thanks for sharing such a wonderful blog...
    Software Testing Courses in Chennai |Software Testing Courses in Velachery

    ReplyDelete
  46. I simply wanted to thank you so much again. I am not sure the things that I might have gone through without the type of hints revealed by you regarding that situation.Thank you so much one more times. Android Summer Training Courses in Chennai | Android Summmer Training Courses in Velachery

    ReplyDelete
  47. Good Blog....Thanks for sharing your informative and amazing blog with us, it’s very helpful for everyone.
    Summer Course Training in Chennai | Summer Course Training in Velachery | Summer Course Training in Kanchipuram

    ReplyDelete
  48. Thanks for posting this useful information, Good to know about new things here, Keep updating your blog...
    Vacation Courses Training in Chennai | Vacation Courses Training in Velachery

    ReplyDelete
  49. Really i enjoyed very much. And this may helpful for lot of peoples. So you are provided such a nice and great article within this.
    Best Summer Course Training Institute in Chennai | Best Summer Course Training Institute in Velachary | Best Summer Course Training Institute in Kanchipuram |

    ReplyDelete

  50. Thank you so much for posting this useful information content, Good to know about new things here, Keep share your blog...
    Vacation Classes in Chennai | Vacation Classes in Velachery

    ReplyDelete
  51. These provided information was really so nice, thanks for giving that post and the more skills to develop after refer that post.
    Summer Course in Chennai |Summer Course in Pallikaranai

    ReplyDelete
  52. Nice blog. Thank you for sharing. The information you shared is very effective for learners I have got some important suggestions from it
    Vacation Courses in Chennai | Vacation Courses in Keelkattalai

    ReplyDelete
  53. Thank you for sharing wonderful information with us to get some idea about that content.
    Vacation Courses in Chennai | Vacation Courses in Pallikaranai

    ReplyDelete
  54. Pretty article! I found some useful information in your blog, it was awesome to read, thanks for sharing this great content to my vision, keep sharing.
    Vacation Courses in Chennai | Vacation Courses in Meenampakkam

    ReplyDelete
  55. Thanks a lot! You made a new blog entry to answer my question; I really appreciate your time and effort.
    Summer courses in Chennai | Summer courses in Thiruvanmiyur

    ReplyDelete
  56. Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge.
    Vacation Courses in Chennai | Vacation Courses in Perungudi

    ReplyDelete
  57. It is very excellent blog and useful article thank you for sharing with us, keep posting.
    Summer courses in Chennai | Summer courses in Nanganallur

    ReplyDelete
  58. These provided information was really so nice, thanks for giving that post and the more skills to develop after referring that post. Your articles really impressed for me, because of all information so nice.
    Vacation Courses in Chennai | Vacation Courses in Thiruvanmiyur

    ReplyDelete
  59. Nice blog. Thank you for sharing. The information you shared is very effective for learners I have got some important suggestions from it
    Vacation Courses in Chennai | Vacation Courses in Nanganallur.

    ReplyDelete
  60. Awesome Blog with informative concept. Really I feel happy to see this useful blog.
    Selenium Course Training in Chennai | Selenium Course Training in Pallikaranai

    ReplyDelete
  61. Pretty article! I found some useful information in your blog, it was awesome to read, thanks for sharing this great content to my vision, keep sharing.
    AWS Training Center in Chennai | AWS Certification in Velachery | AWS Training in Nanganallur | AWS Training in Palavanthangal | AWS Training in Medavakkam

    ReplyDelete
  62. Thanks for posting this information it was really good and useful for me. Got many innovative ideas.AWS Training in Chennai | AWS Training in Taramani

    ReplyDelete
  63. Your blog is very informative with useful information, thanks a lot for sharing such a wonderful article, it’s very useful for me. Keep updating your creative knowledge....
    JAVA Course in Chennai | JAVA Course in Velachery | Java Course in Pallikaranai | Java Course in Taramani | Java Course in Madipakkam | Advanced Java Training in Keelkattalai

    ReplyDelete
  64. This is really too useful and have more ideas from yours. Keep sharing many techniques. Eagerly waiting for your new blog and useful information. Keep doing more.
    Python Training in Taramani | Python Training in Guindy | Python Certification Centers in Chennai | Python Training in Pallikaranai | Python Certification Training in Velachery

    ReplyDelete
  65. Pretty article! I found some useful information in your blog, it was awesome to read, thanks for sharing this great content to my vision, keep sharing.
    Best AWS Training in Chennai | Best AWS Training in Velachery

    ReplyDelete
  66. Nice and good article. It is very useful for me to learn and understand easily. Thanks for sharing your valuable information and time. Please keep updating...
    AWS Certification in Chennai | AWS Training in Tambaram | AWS Training in Meenambakkam | AWS Training in Porur | AWS Exam Center in Velachery

    ReplyDelete
  67. Really very nice blog information for this one and more technical skill is improved, I like that kind of post.
    Python Exam Center in Chennai | Python Exams in Velachery | Python Exam Center in Taramani | Python Certification in Chennai

    ReplyDelete
  68. Pretty article! I found some useful information in your blog, it was awesome to read, thanks for sharing this great content to my vision, keep sharing.
    AWS Training in Chennai | AWS Training in Velachery | AWS Certification in Chennai

    ReplyDelete
  69. Awesome post. Really you are shared very informative concept... Thank you for sharing. Keep on updating...
    Software Testing Training in Chennai | Software Testing Course in Velachery | Software Testing Training in Taramani

    ReplyDelete

  70. Thanks for posting this information it was really good and useful for me. Got many innovative ideas.
    Android Training Course in Chennai | Android Training Course in Adyar

    ReplyDelete
  71. Nice and good article. It is very useful for me to learn and understand easily. Thanks for sharing your valuable information and time. Please keep updating...
    Web Designing and Development Training in Chennai | Web Designing Course in Velachery | Web Development Course in Chennai

    ReplyDelete
  72. This is really too useful and have more ideas from yours. Keep sharing many techniques. Eagerly waiting for your new blog and useful information. Keep doing more.
    Cloud Computing Training in Chennai | Cloud Computing Training in Velachery | Cloud Computing Training in Taramani | Cloud Computing Training in Pallikaranai

    ReplyDelete
  73. Very interesting topic. Helps to gain knowledge about lot of information. Thanks for posting information in this blog.
    Selenium Training Institute in Chennai | Selenium Exam Center in Velachery | Selenium Training in Keelkattalai | Selenium Training in Taramani

    ReplyDelete
  74. Pretty article! I found some useful information in your blog, it was awesome to read, thanks for sharing this great content to my vision, keep sharing.
    Python Training Institute in Chennai | Python Training Center in Velachery | Python Exam Center in Taramani | Python Training in Guindy

    ReplyDelete
  75. Good and more informative blog...New concepts and easily understand.... Thanks for sharing the post....
    AWS Training in Chennai | AWS Training in Velachery | AWS Training in Pallikaranai | AWS Training in Adyar

    ReplyDelete
  76. Good and more informative blog...New concepts and easily understand.... Thanks for sharing the post....
    AWS Training in Chennai | AWS Training in Velachery | AWS Training in Pallikaranai | AWS Training in Adyar

    ReplyDelete
  77. All the points you described so beautiful. Every time i read your blog content and i so surprised that how you can write so well.
    Uipath Training Institute in Chennai | Uipath Training in Velachery | Uipath Certification in Chennai | Uipath Exam Center in Velachery

    ReplyDelete
  78. Nice and informative article. Thanks for sharing such nice article, keep on updating.

    CandC++ programming training academy in Kanchipuram


    ReplyDelete
  79. Pretty article! I found some useful information in your blog, it was awesome to read, thanks for sharing this great content to my vision, keep sharing.
    Tally Training in Chennai | Tally Training in Saidapet | Tally Training in Guindy | Tally Training in Velachery | Tally Training in Tambaram

    ReplyDelete
  80. I have read your blog. It’s very informative and useful blog. You have done really great job. Keep update your blog.

    Best Tally Courses Training Academy in Kanchipuram

    ReplyDelete
  81. It's very great post... Really you are... done a wonderful job Keep up the good work and continue sharing like this.
    Graphic Designing Training in Chennai | Graphic Designing Training in Guindy

    ReplyDelete
  82. Very good and informative article. Thanks for sharing such nice article, keep on updating such good articles.
    Uipath Exam Center in Chennai | Uipath Exam Center in Velachery | Uipath Exams in Madipakkam | Uipath Exam Center in Taramani

    ReplyDelete
  83. This is really too useful and have more ideas from yours. Keep sharing many techniques and thanks for sharing the information.
    Tally Course in Chennai | Tally Course in Velachery | Tally Course in Taramani | Tally Training in Pallikaranai

    ReplyDelete
  84. Your blog is very informative with useful information, thanks a lot for sharing such a wonderful article, it’s very useful for me. Keep updating your creative knowledge....
    Selenium Training Institute in Chennai | Selenium Training in Velachery | Selenium Course in Adyar | Selenium Training in Taramani

    ReplyDelete
  85. Nice Post! It is really interesting to read from the beginning and Keep up the good work and continue sharing like this.
    Web Designing Training in Chennai | Web Designing Course in Velachery | Web Designing Training Center in Taramani | Web Designing Course in Medavakkam

    ReplyDelete
  86. Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging…

    Best Web Designing Training Academy in Kanchipuram

    ReplyDelete

  87. Awesome post. Really you are shared very informative concept... Thank you for sharing. Keep on updating...

    Best Java Training Academy in Kanchipuram

    ReplyDelete
  88. This kind of information is very useful and required for the beginners like me. I wanna say thanks for the information that you are contributed here.
    Best Blue Prism Training Institute in Chennai | Blue prism Training in Velachery

    ReplyDelete
  89. Great Work. Your writing is one of a kind. The approach is very interesting to read and gives more clarity. Waiting for your future posts.
    BluePrism Training in Chennai | Blue prism Training in Pallikaranai

    ReplyDelete
  90. This blog very easily understandable. Thanks for sharing such an informative post with us. This is a nice post in an interesting line of content.
    Java Training Institute in Chennai | Java Training Center in Velachery | Java Course in Taramani | Java Training in Pallavaram

    ReplyDelete
  91. Thank you so much for sharing. Keep updating your blog. It will very useful to the many users.
    Best Web Designing Training Academy in Kanchipuram

    ReplyDelete
  92. Nice Post! It is really interesting to read from the beginning and Keep up the good work and continue sharing like this.
    Uipath Training Institute in Chennai | Uipath Training in Velachery | Uipath Training in Guindy | Uipath Certification in Taramani

    ReplyDelete
  93. I have read your blog its very attractive and impressive. I like it your blog.
    Best Software Testing Training Academy in Kanchipuram

    ReplyDelete

Post a Comment

Popular Posts